v0.6 added log file for batch runs.
This commit is contained in:
parent
c8690afa3b
commit
2a7fa965cb
219
cbr2cbz.sh
219
cbr2cbz.sh
|
@ -1,8 +1,10 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
version="0.6"
|
||||||
|
|
||||||
function Help {
|
function Help {
|
||||||
echo "cbr2cbz Conversion Tool"
|
echo "cbr2cbz Conversion Tool"
|
||||||
echo "Version 0.5"
|
echo "Version $version"
|
||||||
echo "https://git.zaks.web.za/thisiszeev/cbr2cbz"
|
echo "https://git.zaks.web.za/thisiszeev/cbr2cbz"
|
||||||
echo
|
echo
|
||||||
echo 'Usage: cbr2cbz single "filename.cbr"'
|
echo 'Usage: cbr2cbz single "filename.cbr"'
|
||||||
|
@ -26,32 +28,97 @@ function Convert {
|
||||||
echo
|
echo
|
||||||
if [[ $exitcoder == "0" ]]
|
if [[ $exitcoder == "0" ]]
|
||||||
then
|
then
|
||||||
zip -jm "$cbz" /tmp/cbr2cbz/*
|
zip -jm "$cbz" /tmp/cbr2cbz/*
|
||||||
echo
|
echo
|
||||||
exitcodez=$?
|
exitcodez=$?
|
||||||
if [[ $exitcodez == "0" ]]
|
if [[ $exitcodez == "0" ]]
|
||||||
then
|
then
|
||||||
rm "$cbr"
|
rm "$cbr"
|
||||||
echo "Successfully Converted $cbr to $cbz..."
|
echo "Successfully Converted $cbr to $cbz..."
|
||||||
sleep 2s
|
temp=( $( du $cbz ) )
|
||||||
echo
|
tmp=$(( $convsize + ${temp[0]} ))
|
||||||
else
|
convsize=$tmp
|
||||||
echo "Error Writing $cbz - Skipping..."
|
sleep 2s
|
||||||
sleep 2s
|
echo
|
||||||
echo
|
else
|
||||||
rm "$cbz"
|
echo "Error Writing $cbz - Skipping..."
|
||||||
fi
|
if [[ $isbatch = true ]]
|
||||||
|
then
|
||||||
|
((failedfiles++))
|
||||||
|
echo " $cbr"
|
||||||
|
fi
|
||||||
|
sleep 2s
|
||||||
|
echo
|
||||||
|
rm "$cbz"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "Error Reading $cbr - Skipping..."
|
echo "Error Reading $cbr - Skipping..."
|
||||||
sleep 2s
|
if [[ $isbatch = true ]]
|
||||||
echo
|
then
|
||||||
|
((failedfiles++))
|
||||||
|
echo " $cbr"
|
||||||
|
fi
|
||||||
|
sleep 2s
|
||||||
|
echo
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function BatchRun {
|
function BatchRun {
|
||||||
rm -R "/tmp/cbr2cbz"
|
isbatch=true
|
||||||
|
rm -Rf "/tmp/cbr2cbz"
|
||||||
mkdir -p "/tmp/cbr2cbz"
|
mkdir -p "/tmp/cbr2cbz"
|
||||||
find . -type f -name "*.cbr" > /tmp/cbr2cbz.list
|
find . -type f -name "*.cbr" > /tmp/cbr2cbz.list
|
||||||
|
totalfiles=$(( find . -type f -name "*" | wc -l ))
|
||||||
|
startsize=$(( du | tail -1 ))
|
||||||
|
cbrfiles=$(( find . -type f -name "*.cbr" | wc -l ))
|
||||||
|
if [[ $cbrfiles == 0 ]]
|
||||||
|
then
|
||||||
|
echo "No files to convert!"
|
||||||
|
echo
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
temp=( $( du -c *.cbr | tail -1 ) )
|
||||||
|
cbrsize=${temp[0]}
|
||||||
|
temp=$(( $cbrsize / 1024 / 1024 ))
|
||||||
|
if [[ $temp > 0 ]]
|
||||||
|
then
|
||||||
|
cbrsizeh="$temp GB"
|
||||||
|
else
|
||||||
|
temp=$(( $cbrsize / 1024 ))
|
||||||
|
if [[ $temp > 0 ]]
|
||||||
|
then
|
||||||
|
cbrsizeh="$temp MB"
|
||||||
|
else
|
||||||
|
cbrsizeh="$temp KB"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
cbzfiles=$(( find . -type f -name "*.cbz" | wc -l ))
|
||||||
|
temp=( $( du -c *.cbz | tail -1 ) )
|
||||||
|
cbzsize=${temp[0]}
|
||||||
|
temp=$(( $cbzsize / 1024 / 1024 ))
|
||||||
|
if [[ $temp > 0 ]]
|
||||||
|
then
|
||||||
|
cbzsizeh="$temp GB"
|
||||||
|
else
|
||||||
|
temp=$(( $cbzsize / 1024 ))
|
||||||
|
if [[ $temp > 0 ]]
|
||||||
|
then
|
||||||
|
cbzsizeh="$temp MB"
|
||||||
|
else
|
||||||
|
cbzsizeh="$temp KB"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "CBR2CBZ Batch Log" > cbr2cbz.log
|
||||||
|
echo "Version $version" >> cbr2cbz.log
|
||||||
|
echo "You can check for script updates at https://git.zaks.web.za/thisiszeev/cbr2cbz"
|
||||||
|
echo "Batch Start Date & Time: $(( date ))" >> cbr2cbz.log
|
||||||
|
echo >> cbr2cbz.log
|
||||||
|
echo "Considering $totalfiles ($startsize)" >> cbr2cbz.log
|
||||||
|
echo " of which..." >> cbr2cbz.log
|
||||||
|
echo "CBZ files: $cbzfiles ($cbzsizeh)" >> cbr2cbz.log
|
||||||
|
echo "CBR files: $cbrfiles ($cbrsizeh)" >> cbr2cbz.log
|
||||||
|
echo
|
||||||
|
echo "Failed files:" >> cbr2cbz.log
|
||||||
files=$( cat /tmp/cbr2cbz.list | wc -l )
|
files=$( cat /tmp/cbr2cbz.list | wc -l )
|
||||||
while read -r filename
|
while read -r filename
|
||||||
do
|
do
|
||||||
|
@ -61,11 +128,109 @@ function BatchRun {
|
||||||
clear
|
clear
|
||||||
Convert
|
Convert
|
||||||
done < /tmp/cbr2cbz.list
|
done < /tmp/cbr2cbz.list
|
||||||
rm /tmp/cbr2cbz.list
|
temp=$(( $convsize / 1024 / 1024 ))
|
||||||
rm -R "/tmp/cbr2cbz"
|
if [[ $temp > 0 ]]
|
||||||
|
then
|
||||||
|
convsizeh="$temp GB"
|
||||||
|
else
|
||||||
|
temp=$(( $convsize / 1024 ))
|
||||||
|
if [[ $temp > 0 ]]
|
||||||
|
then
|
||||||
|
convsizeh="$temp MB"
|
||||||
|
else
|
||||||
|
convsizeh="$temp KB"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
rm -f /tmp/cbr2cbz.list
|
||||||
|
rm -Rf "/tmp/cbr2cbz"
|
||||||
|
PrintStats
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function SingleRun {
|
||||||
|
isbatch=false
|
||||||
|
rm -Rf "/tmp/cbr2cbz"
|
||||||
|
cbr=$2
|
||||||
|
size=$(( ${#cbr} - 1 ))
|
||||||
|
cbz="${cbr:0:$size}z"
|
||||||
|
mkdir -p "/tmp/cbr2cbz"
|
||||||
|
files=1
|
||||||
|
Convert
|
||||||
|
rm -Rf "/tmp/cbr2cbz"
|
||||||
|
PrintStats
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
function PrintStats {
|
||||||
|
RunTime
|
||||||
|
if [[ $isbatch == true ]]
|
||||||
|
then
|
||||||
|
echo
|
||||||
|
echo "Total CBR files: $cbrfiles ($cbrsizeh)"
|
||||||
|
echo "Succefully converted: $(( $cbrfiles - $failedfiles )) ($convsizeh)"
|
||||||
|
echo "Failed: $failedfiles"
|
||||||
|
echo
|
||||||
|
echo "A log file has been written to cbr2cbz.log which contains all the failed files."
|
||||||
|
if [[ $failedfiles == 0 ]]
|
||||||
|
then
|
||||||
|
echo " none" >> cbr2cbz.log
|
||||||
|
fi
|
||||||
|
echo >> cbr2cbz.log
|
||||||
|
echo "Total CBR files: $cbrfiles ($cbrsizeh)" >> cbr2cbz.log
|
||||||
|
echo "Succefully converted: $(( $cbrfiles - $failedfiles )) ($convsizeh)" >> cbr2cbz.log
|
||||||
|
echo "Failed: $failedfiles" >> cbr2cbz.log
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
functions RunTime {
|
||||||
|
temp=$SECONDS
|
||||||
|
days=$(( $temp / 60 / 60 / 24 ))
|
||||||
|
hour=$(( $temp / 60 / 60 % 24 ))
|
||||||
|
mins=$(( $temp / 60 % 60 ))
|
||||||
|
secs=$(( $ttemp % 60 ))
|
||||||
|
echo -n "Runtime: "
|
||||||
|
if [[ $days > 0 ]]
|
||||||
|
then
|
||||||
|
[[ $days = 1 ]] && echo -n "$days day " || echo -n "$days days "
|
||||||
|
fi
|
||||||
|
if [[ $hour > 0 ]]
|
||||||
|
then
|
||||||
|
[[ $hour = 1 ]] && echo -n "$hour hour " || echo -n "$hour hours "
|
||||||
|
fi
|
||||||
|
if [[ $mins > 0 ]]
|
||||||
|
then
|
||||||
|
[[ $mins = 1 ]] && echo -n "$mins minute " || echo -n "$mins minutes "
|
||||||
|
fi
|
||||||
|
if [[ $d = 0 && $h = 0 && $m = 0 ]]
|
||||||
|
then
|
||||||
|
[[ $s = 1 ]] && echo -n "$s second" || echo -n "$s seconds"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
if [[ $isbatch == true ]]
|
||||||
|
then
|
||||||
|
echo -n "Runtime: " >> cbr2cbz.log
|
||||||
|
if [[ $days > 0 ]]
|
||||||
|
then
|
||||||
|
[[ $days = 1 ]] && echo -n "$days day " >> cbr2cbz.log || echo -n "$days days " >> cbr2cbz.log
|
||||||
|
fi
|
||||||
|
if [[ $hour > 0 ]]
|
||||||
|
then
|
||||||
|
[[ $hour = 1 ]] && echo -n "$hour hour " >> cbr2cbz.log || echo -n "$hour hours " >> cbr2cbz.log
|
||||||
|
fi
|
||||||
|
if [[ $mins > 0 ]]
|
||||||
|
then
|
||||||
|
[[ $mins = 1 ]] && echo -n "$mins minute " >> cbr2cbz.log || echo -n "$mins minutes " >> cbr2cbz.log
|
||||||
|
fi
|
||||||
|
if [[ $d = 0 && $h = 0 && $m = 0 ]]
|
||||||
|
then
|
||||||
|
[[ $s = 1 ]] && echo -n "$s second" >> cbr2cbz.log || echo -n "$s seconds" >> cbr2cbz.log
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
SECONDS=0
|
||||||
|
convsize=0
|
||||||
|
|
||||||
if [[ -z $1 ]]
|
if [[ -z $1 ]]
|
||||||
then
|
then
|
||||||
Help
|
Help
|
||||||
|
@ -80,15 +245,7 @@ then
|
||||||
echo "If filename has spaces or special characters please pass it within quotes."
|
echo "If filename has spaces or special characters please pass it within quotes."
|
||||||
Help
|
Help
|
||||||
fi
|
fi
|
||||||
rm -R "/tmp/cbr2cbz"
|
SingleRun
|
||||||
cbr=$2
|
|
||||||
size=$(( ${#cbr} - 1 ))
|
|
||||||
cbz="${cbr:0:$size}z"
|
|
||||||
mkdir -p "/tmp/cbr2cbz"
|
|
||||||
files=1
|
|
||||||
Convert
|
|
||||||
rm -R "/tmp/cbr2cbz"
|
|
||||||
exit
|
|
||||||
fi
|
fi
|
||||||
elif [[ $1 == "help" ]]
|
elif [[ $1 == "help" ]]
|
||||||
then
|
then
|
||||||
|
|
Loading…
Reference in New Issue