1
0
Fork 0
mirror of https://github.com/Jonny007-MKD/OTR-DecodeAll synced 2024-05-02 20:54:06 +02:00

Introduced cutting with multicutmkv

This commit is contained in:
Jonny007-MKD 2015-02-25 16:16:26 +01:00
parent be17e21b0a
commit 356ca33e16

View file

@ -12,6 +12,7 @@ logMsgColor=("\033[37m" "\033[31m" "\033[33m" "\033[37m" "\033[37m" "\033[37m")
logLevel=0
echoLevel=5
lastKodiCheck=0
cutAppendix="-cut.mkv"
umask 0002 # Set permissions 775/664 per default
@ -207,7 +208,7 @@ function funcMakeVars {
funcLog 5 "pathTmpAbsDecoded: $pathTmpAbsDecoded"
# This is the absolute path to the cut file (e.g. /stuff/Good_Wife_15.02.17_23-55_sixx_50_TVOON_DE.mpg.HQ.avi-cut.mkv)
pathTmpAbsCut="$cutDir/$filename-cut.mkv"
pathTmpAbsCut="$cutDir/$filename$cutAppendix"
funcLog 5 "pathTmpAbsCut: $pathTmpAbsCut"
# Now we will determine the path where to put the file in the end (depends on label and saneRenamix)
@ -268,6 +269,9 @@ function funcMakeVars {
if [ $sanename != $filename ]; then # No sanename
pathAbsOutDecodedInsane="$outDir/$pathAbsOutDecoded/$filename"
funcLog 5 "pathAbsOutDecodedInsane: $pathAbsOutDecodedInsane"
pathAbsOutCutInsane="$pathAbsOutDecodedInsane$cutAppendix"
funcLog 5 "pathAbsOutCutInsane: $pathAbsOutCutInsane"
fi
# This will be the absolute path to the output file (e.g. /final/Good.Wife/Good.Wife..S05E14..Ein.paar.Worte.HQ.avi)
@ -275,96 +279,134 @@ function funcMakeVars {
funcLog 5 "pathAbsOutDecoded: $pathAbsOutDecoded"
# This will be the absolute path to the cut output file (e.g. /final/Good.Wife/Good.Wife..S05E14..Ein.paar.Worte.HQ.avi-cut.mkv)
pathAbsOutCut="$pathAbsOutDecoded-cut.mkv"
pathAbsOutCut="$pathAbsOutDecoded$cutAppendix"
funcLog 5 "pathAbsOutCut: $pathAbsOutCut"
}
# In here lives the main loop
function funcProcessFiles {
local files="`ls $inDir/*.otrkey 2> /dev/null `" # All otrkeys
local nextStep
local status # 0 undef; 1 encoded; 2 decoded; 3 cut; 4 moved;
local files="`ls $inDir/*.otrkey 2> /dev/null`" # All otrkeys in input dir
for file in $files; do # For each otrkey
funcPerformKodiCheck # Check whether Kodi is running
filename="$(basename $file)"
filename="${filename%.otrkey}"
funcPerformKodiCheck # Check whether Kodi is running
echo;
filename="$(basename $file)" # Determine the filename
filename="${filename%.otrkey}"
funcLog 0 "Processing $filename";
funcGetLabel
status=0;
funcGetLabel # Read the label from the database
if [ -n "$labelFilter" ] && [[ "$labelFilter" != "$label" ]]; then
if [ -n "$labelFilter" ] && [[ "$labelFilter" != "$label" ]]; then # This label shall not be handled --> skip
funcLog 4 "Label did not match filter. Skipping";
continue;
fi
if [ -z "$label" ]; then
if [ -z "$label" ]; then # Empty label --> skip
funcLog 1 "No label specified for this movie. Skipping"
continue;
fi
funcMakeVars
funcMakeVars # Make all path variables
echo -e " >> \033[32m$sanename\033[37m";
status=1;
if [ -n "$pathAbsOutDecodedInsane" -a -f "$pathAbsOutDecodedInsane" ]; then # Sanerenamix could not name this file before, but now it can
# If file was already cut
if [ -n "$pathAbsOutCutInsane" -a -f "$pathAbsOutCutInsane" ]; then # Sanerenamix could not name this file before, but now it cans
funcLog 4 "Renamed $filename to $sanename"
mv $pathAbsOutDecodedInsane $pathAbsOutDecoded
fi
if [ -f "$pathAbsOutDecoded" ]; then
funcLog 4 "File was already handled."
funcRemove $file
continue;
mv $pathAbsOutCutInsane $pathAbsOutCut
status=3;
elif [ -f "$pathAbsOutCut" ]; then # The final output file already exists
funcLog 4 "File was already decoded and cut."
status=4;
fi
funcDecode "$pathAbsEncoded";
if [ $success -ne 1 ]; then # Decoding failed, we can skip the rest
continue;
# If file was already decoded
if [ $status -le 2 ]; then
if [ -n "$pathAbsOutDecodedInsane" -a -f "$pathAbsOutDecodedInsane" ]; then # Sanerenamix could not name this file before, but now it cans
funcLog 4 "Renamed decoded $filename to $sanename" # We were unable to cut the last time
mv $pathAbsOutDecodedInsane $pathAbsOutDecoded
status=2;
elif [ -f "$pathAbsOutDecoded" ]; then
funcLog 4 "File was already decoded."
status=2;
fi
if [ $status -eq 2 ]; then
pathTmpAbsDecoded="$pathAbsOutDecoded" # Cut the file in the output dir directly
funcLog 5 "pathTmpAbsDecoded: $pathTmpAbsDecoded"
pathTmpAbsCut="$pathTmpAbsDecoded$cutAppendix"
funcLog 5 "pathTmpAbsCut: $pathTmpAbsCut"
fi
fi
if [ $status -eq 1 ]; then
# Decode the file if neccessary
funcDecode "$pathAbsEncoded";
if [ $success -ne 1 ]; then # Decoding failed, we can skip the rest
continue;
fi
status=2
fi
if [ $status -eq 2 ]; then
# Cut the file if neccessary
funcCut "$pathTmpAbsDecoded"
if [ $success -eq 1 ]; then # Cutting did not fail
status=3;
fi
fi
# Move the final file to its destination
if [ $status -eq 2 ]; then # only decoded
pathMoveFrom="$pathTmpAbsDecoded"
pathMoveTo="$pathAbsOutDecoded"
elif [ $status -eq 3 ]; then # also cut
pathMoveFrom="$pathTmpAbsCut"
pathMoveTo="$pathAbsOutCut"
fi
if [ $status -ge 2 ]; then
funcMove "$pathMoveFrom" "$pathMoveTo"
if [ $success -eq 1 ]; then # Moving the file failed, we can skip the rest
status=4
fi
fi
# delete the otrkey if applicable
funcRemove $file
if [ $success -ne 1 ]; then # Removing failed, we can skip the rest
continue;
fi
#funcCut "$pathTmpAbsDecoded"
if [ $success -ne 1 ]; then # Cutting failed, we can skip the rest
continue;
fi
funcMove "$pathMovie"
if [ $success -ne 1 ]; then # Moving the file failed, we can skip the rest
continue;
fi
done
}
# Make the decoding stuff
# Do the decoding stuff
function funcDecode {
local sizeEn;
local sizeDe;
if [ -e "$pathTmpAbsDecoded" ]; then # If we decoded this file before
sizeEn=`stat -c%s "$pathAbsEncoded"`
sizeDe=`stat -c%s "$pathTmpAbsDecoded"`
if [ $(($sizeEn-$sizeDe)) -eq 522 ]; then # If decoding was successful
local sizeEnc;
local sizeDec;
if [ -f "$pathTmpAbsDecoded" ]; then # If we decoded this file before
sizeEnc=`stat -L -c%s "$pathAbsEncoded"`
sizeDec=`stat -L -c%s "$pathTmpAbsDecoded"`
if [ $(($sizeEnc-$sizeDec)) -eq 522 ]; then # If decoding was successful
funcLog 3 "File was already decoded: $pathTmpAbsDecoded" # Simply do nothing
pathMovie="$pathTmpAbsDecoded"
else # Else decode it again
funcLog 3 "Previous decoding was not successfull"
else # Else decode it again
funcLog 3 "Previous decoding was not successfull (filesize difference: $(($sizeEnc-$sizeDec)), should be 522)"
rm "$pathTmpAbsDecoded"
fi
fi
if [ ! -e "$pathTmpAbsDecoded" ]; then # If don't find the decoded file in $uncutDir
if [ -f "$pathTmpAbsDecoded" ]; then
success=1
else # If we don't find the decoded file in $uncutDir
funcLog 4 "Decoding $filename"
funcLog 5 " $cmdDecode $cmdDecodeArgs $pathAbsEncoded"
#echo " $cmdDecode $cmdDecodeArgs $pathAbsEncoded"
$cmdDecode $cmdDecodeArgs "$pathAbsEncoded" # Deocde the file
$cmdDecode $cmdDecodeArgs "$pathAbsEncoded" # Deocde the file
success=$?
if [ $success -eq 0 ]; then # if otrdecoder exited successfully
if [ $success -eq 0 ]; then # if otrdecoder exited successfully
if [ -f "$pathTmpAbsDecoded" ]; then
funcLog 4 "Successfully decoded"
echo -e "\033[32mDecoding successfull\033[37m";
pathMovie="$pathTmpAbsDecoded"
success=1;
else
funcLog 1 "Decoding failed but decoder exited with success status!"
@ -377,53 +419,82 @@ function funcDecode {
fi
}
# Remove all unneeded files
function funcRemove {
case $remove in
2) # if we shall delete the file
funcLog 4 "Deleting $pathAbsEncoded"
rm -f "$pathAbsEncoded";;
1)
case $status in
3) # Cut -> remove decoded file
funcRemoveFile "$pathTmpAbsCut"
funcRemoveFile "$pathAbsOutDecoded" # decoded file in output dir
funcRemoveFile "$pathAbsOutDecodedInsane" # "
;&
2) # Decoded -> remove otrkey
funcRemoveFile "$pathTmpAbsDecoded" # temporary decoded file
if [ $remove -eq 2 ]; then # force deleting
funcRemoveFile "$pathAbsEncoded";
elif [ $remove -eq 1 ]; then # test torrent client
## TODO: Add more checks here, not only Deluge. Therefore we need a new config var
if [ -n "$delugeDir" ] && [ -d "$delugeDir/state" ]; then # If deluge config dir is defined
if [ -n "`grep "$filename" "$delugeDir/state" -R --include=*.torrent`" ]; then
funcLog 4 "Torrent still exists in Deluge"
else
funcLog 3 "Deleting otrkey, torrent was removed"
rm -f "$pathAbsEncoded"; # Delete otrkey, too
funcRemoveFile "$pathAbsEncoded";
fi
fi;;
fi
fi
;;
esac
success=1;
}
function funcRemoveFile
{
local file="$1"
if [ -e $file ]; then
funcLog 4 "Deleting $file"
rm -f "$file";
fi
}
# Cut our decoded file
function funcCut {
funcLog 4 "Cutting $pathTmpAbsDecoded"
funcLog 5 " $cmdCut $cmdCutArgs $pathTmpAbsDecoded"
$cmdCut $cmdCutArgs "$pathTmpAbsDecoded"
success=$?
case $success in
0)
funcLog 4 "Successfully cut"
pathMove="$pathTmpAbsCut"
success=1;;
5)
funcLog 3 "No cutlist found"
pathMove="$pathTmpAbsCut"
success=1;;
success=0;;
*)
funcLog 1 "An error occured while cutting: $success!"
success=0;;
esac
}
function funcMove {
if [ ! -d "$pathAbsOutDecoded" ]; then
mkdir -p "$(dirname $pathAbsOutDecoded)"
if [ "$pathMoveFrom" != "$pathMoveTo" ]; then
local dir="$(dirname $pathMoveTo)"
if [ ! -d "$dir" ]; then
mkdir -p "$dir"
fi
mv -f "$pathMoveFrom" "$pathMoveTo"
fi
mv -f "$pathMovie" "$pathAbsOutDecoded"
success=1
}
######
# This is our main program flow
######
funcGetConfig
funcParam "$@"
funcPerformChecks