1
0
Fork 0
mirror of https://github.com/Jonny007-MKD/OTR-DecodeAll synced 2025-01-22 08:49:50 +01: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 logLevel=0
echoLevel=5 echoLevel=5
lastKodiCheck=0 lastKodiCheck=0
cutAppendix="-cut.mkv"
umask 0002 # Set permissions 775/664 per default umask 0002 # Set permissions 775/664 per default
@ -207,7 +208,7 @@ function funcMakeVars {
funcLog 5 "pathTmpAbsDecoded: $pathTmpAbsDecoded" 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) # 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" funcLog 5 "pathTmpAbsCut: $pathTmpAbsCut"
# Now we will determine the path where to put the file in the end (depends on label and saneRenamix) # 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 if [ $sanename != $filename ]; then # No sanename
pathAbsOutDecodedInsane="$outDir/$pathAbsOutDecoded/$filename" pathAbsOutDecodedInsane="$outDir/$pathAbsOutDecoded/$filename"
funcLog 5 "pathAbsOutDecodedInsane: $pathAbsOutDecodedInsane" funcLog 5 "pathAbsOutDecodedInsane: $pathAbsOutDecodedInsane"
pathAbsOutCutInsane="$pathAbsOutDecodedInsane$cutAppendix"
funcLog 5 "pathAbsOutCutInsane: $pathAbsOutCutInsane"
fi fi
# This will be the absolute path to the output file (e.g. /final/Good.Wife/Good.Wife..S05E14..Ein.paar.Worte.HQ.avi) # This will be the absolute path to the output file (e.g. /final/Good.Wife/Good.Wife..S05E14..Ein.paar.Worte.HQ.avi)
@ -275,87 +279,126 @@ function funcMakeVars {
funcLog 5 "pathAbsOutDecoded: $pathAbsOutDecoded" 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) # 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" funcLog 5 "pathAbsOutCut: $pathAbsOutCut"
} }
# In here lives the main loop
function funcProcessFiles { 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 for file in $files; do # For each otrkey
funcPerformKodiCheck # Check whether Kodi is running funcPerformKodiCheck # Check whether Kodi is running
filename="$(basename $file)"
filename="${filename%.otrkey}"
echo; echo;
filename="$(basename $file)" # Determine the filename
filename="${filename%.otrkey}"
funcLog 0 "Processing $filename"; 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"; funcLog 4 "Label did not match filter. Skipping";
continue; continue;
fi fi
if [ -z "$label" ]; then if [ -z "$label" ]; then # Empty label --> skip
funcLog 1 "No label specified for this movie. Skipping" funcLog 1 "No label specified for this movie. Skipping"
continue; continue;
fi fi
funcMakeVars funcMakeVars # Make all path variables
echo -e " >> \033[32m$sanename\033[37m"; echo -e " >> \033[32m$sanename\033[37m";
status=1;
# If file was already cut
if [ -n "$pathAbsOutDecodedInsane" -a -f "$pathAbsOutDecodedInsane" ]; then # Sanerenamix could not name this file before, but now it can if [ -n "$pathAbsOutCutInsane" -a -f "$pathAbsOutCutInsane" ]; then # Sanerenamix could not name this file before, but now it cans
funcLog 4 "Renamed $filename to $sanename" funcLog 4 "Renamed $filename to $sanename"
mv $pathAbsOutDecodedInsane $pathAbsOutDecoded mv $pathAbsOutCutInsane $pathAbsOutCut
fi status=3;
if [ -f "$pathAbsOutDecoded" ]; then elif [ -f "$pathAbsOutCut" ]; then # The final output file already exists
funcLog 4 "File was already handled." funcLog 4 "File was already decoded and cut."
funcRemove $file status=4;
continue;
fi fi
# 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"; funcDecode "$pathAbsEncoded";
if [ $success -ne 1 ]; then # Decoding failed, we can skip the rest if [ $success -ne 1 ]; then # Decoding failed, we can skip the rest
continue; continue;
fi 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 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 done
} }
# Make the decoding stuff
# Do the decoding stuff
function funcDecode { function funcDecode {
local sizeEn; local sizeEnc;
local sizeDe; local sizeDec;
if [ -e "$pathTmpAbsDecoded" ]; then # If we decoded this file before if [ -f "$pathTmpAbsDecoded" ]; then # If we decoded this file before
sizeEn=`stat -c%s "$pathAbsEncoded"` sizeEnc=`stat -L -c%s "$pathAbsEncoded"`
sizeDe=`stat -c%s "$pathTmpAbsDecoded"` sizeDec=`stat -L -c%s "$pathTmpAbsDecoded"`
if [ $(($sizeEn-$sizeDe)) -eq 522 ]; then # If decoding was successful if [ $(($sizeEnc-$sizeDec)) -eq 522 ]; then # If decoding was successful
funcLog 3 "File was already decoded: $pathTmpAbsDecoded" # Simply do nothing funcLog 3 "File was already decoded: $pathTmpAbsDecoded" # Simply do nothing
pathMovie="$pathTmpAbsDecoded"
else # Else decode it again else # Else decode it again
funcLog 3 "Previous decoding was not successfull" funcLog 3 "Previous decoding was not successfull (filesize difference: $(($sizeEnc-$sizeDec)), should be 522)"
rm "$pathTmpAbsDecoded" rm "$pathTmpAbsDecoded"
fi fi
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 4 "Decoding $filename"
funcLog 5 " $cmdDecode $cmdDecodeArgs $pathAbsEncoded" funcLog 5 " $cmdDecode $cmdDecodeArgs $pathAbsEncoded"
#echo " $cmdDecode $cmdDecodeArgs $pathAbsEncoded"
$cmdDecode $cmdDecodeArgs "$pathAbsEncoded" # Deocde the file $cmdDecode $cmdDecodeArgs "$pathAbsEncoded" # Deocde the file
@ -364,7 +407,6 @@ function funcDecode {
if [ -f "$pathTmpAbsDecoded" ]; then if [ -f "$pathTmpAbsDecoded" ]; then
funcLog 4 "Successfully decoded" funcLog 4 "Successfully decoded"
echo -e "\033[32mDecoding successfull\033[37m"; echo -e "\033[32mDecoding successfull\033[37m";
pathMovie="$pathTmpAbsDecoded"
success=1; success=1;
else else
funcLog 1 "Decoding failed but decoder exited with success status!" funcLog 1 "Decoding failed but decoder exited with success status!"
@ -377,24 +419,44 @@ function funcDecode {
fi fi
} }
# Remove all unneeded files
function funcRemove { function funcRemove {
case $remove in case $status in
2) # if we shall delete the file 3) # Cut -> remove decoded file
funcLog 4 "Deleting $pathAbsEncoded" funcRemoveFile "$pathTmpAbsCut"
rm -f "$pathAbsEncoded";; funcRemoveFile "$pathAbsOutDecoded" # decoded file in output dir
1) 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 "$delugeDir" ] && [ -d "$delugeDir/state" ]; then # If deluge config dir is defined
if [ -n "`grep "$filename" "$delugeDir/state" -R --include=*.torrent`" ]; then if [ -n "`grep "$filename" "$delugeDir/state" -R --include=*.torrent`" ]; then
funcLog 4 "Torrent still exists in Deluge" funcLog 4 "Torrent still exists in Deluge"
else else
funcLog 3 "Deleting otrkey, torrent was removed" funcRemoveFile "$pathAbsEncoded";
rm -f "$pathAbsEncoded"; # Delete otrkey, too
fi fi
fi;; fi
fi
;;
esac esac
success=1; 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 { function funcCut {
funcLog 4 "Cutting $pathTmpAbsDecoded" funcLog 4 "Cutting $pathTmpAbsDecoded"
funcLog 5 " $cmdCut $cmdCutArgs $pathTmpAbsDecoded" funcLog 5 " $cmdCut $cmdCutArgs $pathTmpAbsDecoded"
@ -404,26 +466,35 @@ function funcCut {
case $success in case $success in
0) 0)
funcLog 4 "Successfully cut" funcLog 4 "Successfully cut"
pathMove="$pathTmpAbsCut"
success=1;; success=1;;
5) 5)
funcLog 3 "No cutlist found" funcLog 3 "No cutlist found"
pathMove="$pathTmpAbsCut" pathMove="$pathTmpAbsCut"
success=1;; success=0;;
*) *)
funcLog 1 "An error occured while cutting: $success!" funcLog 1 "An error occured while cutting: $success!"
success=0;; success=0;;
esac esac
} }
function funcMove { function funcMove {
if [ ! -d "$pathAbsOutDecoded" ]; then if [ "$pathMoveFrom" != "$pathMoveTo" ]; then
mkdir -p "$(dirname $pathAbsOutDecoded)" local dir="$(dirname $pathMoveTo)"
if [ ! -d "$dir" ]; then
mkdir -p "$dir"
fi
mv -f "$pathMoveFrom" "$pathMoveTo"
fi fi
mv -f "$pathMovie" "$pathAbsOutDecoded"
success=1 success=1
} }
######
# This is our main program flow
######
funcGetConfig funcGetConfig
funcParam "$@" funcParam "$@"
funcPerformChecks funcPerformChecks