-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbzMerger
executable file
·84 lines (64 loc) · 1.37 KB
/
cbzMerger
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# For CBZs downloaded with HakuNeko
# Ensure original folder of CBZs are in page-order when sorted alphabetically A-Z
# Rename covers to !000_cover.png/jpg
ORIGWORKDIR=$(pwd)
if [[ ! -z $1 ]]; then
PRINWORKDIR="$1"
else
PRINWORKDIR="./"
fi
function Merge()
{
cd "$PRINWORKDIR"
filearray=(`find ./ -maxdepth 1 -name "*.cbz"`)
if [[ ${#filearray[@]} -gt 0 ]]; then
echo "Files found.";
else
echo "Files not found. Exiting";
exit;
fi
mkdir cbz_working
if [[ -f "!000_cover.png" ]]; then
echo "Found cover (png)"
cp "!000_cover.png" cbz_working/
elif [[ -f "!000_cover.jpg" ]]; then
echo "Found cover (jpg)"
cp "!000_cover.jpg" cbz_working/
fi
for f in *.cbz
do
DIR="./cbz_working/$f"
unzip "$f" -d "$DIR"
cd "$DIR"
HEAD=$(basename "$f" .cbz)
if [[ $HEAD == *":"* ]]; then
HEAD=$(echo "$HEAD" | tr ":" "\n" | head -n 1)
fi
for g in *
do
mv "$g" "$HEAD"_"$g"
done
mv * ../
cd ../../
rmdir "$DIR"
done
cd cbz_working
zip -mr "combined.zip" *
mv "combined.zip" "combined.cbz"
mv combined.cbz "$ORIGWORKDIR/"
cd ..
rmdir cbz_working
}
echo ""
echo "Operating from \"$ORIGWORKDIR\"."
while true; do
read -p "Combining .cbz files in \"$PRINWORKDIR\". Proceed (y/n)? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
Merge