mirror of
https://github.com/Jonny007-MKD/OTR-DecodeAll
synced 2025-01-22 08:49:50 +01:00
Renamed path variables
This commit is contained in:
parent
c89dc512f0
commit
a2f62dd3d4
1 changed files with 71 additions and 54 deletions
125
otrDecodeAll
125
otrDecodeAll
|
@ -189,30 +189,41 @@ function funcGetLabel {
|
||||||
}
|
}
|
||||||
|
|
||||||
function funcMakeVars {
|
function funcMakeVars {
|
||||||
|
# This contains the OTR name of the file (e.g. Good_Wife_15.02.17_23-55_sixx_50_TVOON_DE.mpg.HQ.avi)
|
||||||
funcLog 5 "filename: $filename"
|
funcLog 5 "filename: $filename"
|
||||||
|
|
||||||
pathEncoded="$inDir/$filename.otrkey"
|
# This will be our name for the subfolder (movie name, e.g. Good.Wife)
|
||||||
funcLog 5 "pathEncoded: $pathEncoded"
|
|
||||||
|
|
||||||
pathDecoded="$uncutDir/$filename"
|
|
||||||
funcLog 5 "pathDecoded: $pathDecoded"
|
|
||||||
|
|
||||||
pathCut="$cutDir/$filename.mkv"
|
|
||||||
funcLog 5 "pathCut: $pathCut"
|
|
||||||
|
|
||||||
sanename=$filename # Default value (in case of error)
|
|
||||||
bibname=${filename%%_[0-9][0-9].*}
|
bibname=${filename%%_[0-9][0-9].*}
|
||||||
bibname="${bibname//_/.}"
|
bibname="${bibname//_/.}"
|
||||||
funcLog 5 "bibname: $bibname"
|
funcLog 5 "bibname: $bibname"
|
||||||
|
|
||||||
|
|
||||||
|
# This is the absolute path to the encoded file (e.g. /stuff/Good_Wife_15.02.17_23-55_sixx_50_TVOON_DE.mpg.HQ.avi.otrkey)
|
||||||
|
pathAbsEncoded="$inDir/$filename.otrkey"
|
||||||
|
funcLog 5 "pathAbsEncoded: $pathAbsEncoded"
|
||||||
|
|
||||||
|
# This is the absolute path to the decoded file (e.g. /stuff/Good_Wife_15.02.17_23-55_sixx_50_TVOON_DE.mpg.HQ.avi)
|
||||||
|
pathTmpAbsDecoded="$uncutDir/$filename"
|
||||||
|
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"
|
||||||
|
funcLog 5 "pathTmpAbsCut: $pathTmpAbsCut"
|
||||||
|
|
||||||
|
# Now we will determine the path where to put the file in the end (depends on label and saneRenamix)
|
||||||
|
# sanename is normally the filename. In case of tv series the sanename will also contain the series and episode number and title
|
||||||
|
## TODO: Introduce some dictionary in the config and make this more general
|
||||||
|
sanename=$filename # Default value (in case of error)
|
||||||
if [ -n "$label" ]; then
|
if [ -n "$label" ]; then
|
||||||
case $label in
|
case $label in
|
||||||
"movie")
|
"movie") # Normal movies
|
||||||
pathOut="Filme";;
|
pathAbsOutDecoded="Filme";;
|
||||||
"movie-en")
|
"movie-en") # English movies
|
||||||
pathOut="Filme-En";;
|
pathAbsOutDecoded="Filme-En";;
|
||||||
"tvserie")
|
"docu") # Documentations
|
||||||
pathOut="Serien"
|
pathAbsOutDecoded="Dokumentationen";;
|
||||||
|
"tvserie") # TV Series. Use saneRenamix here
|
||||||
|
pathAbsOutDecoded="Serien"
|
||||||
if [ -n "$cmdSaneRenamix" ]; then
|
if [ -n "$cmdSaneRenamix" ]; then
|
||||||
tmp="$($cmdSaneRenamix $cmdSaneRenamixArgs $filename)"
|
tmp="$($cmdSaneRenamix $cmdSaneRenamixArgs $filename)"
|
||||||
err=$?
|
err=$?
|
||||||
|
@ -243,23 +254,29 @@ function funcMakeVars {
|
||||||
funcLog 1 "SaneRenamix: Unknown error $err";;
|
funcLog 1 "SaneRenamix: Unknown error $err";;
|
||||||
esac
|
esac
|
||||||
fi;;
|
fi;;
|
||||||
"docu")
|
|
||||||
pathOut="Dokumentationen";;
|
|
||||||
*)
|
*)
|
||||||
funcLog 2 "Unrecognized label: $label"
|
funcLog 2 "Unrecognized label: $label"
|
||||||
label=""
|
label=""
|
||||||
pathOut="";;
|
pathAbsOutDecoded="";;
|
||||||
esac
|
esac
|
||||||
pathOut="$pathOut/$bibname"
|
pathAbsOutDecoded="$pathAbsOutDecoded/$bibname" # Append bibname: This is the series name or the movie name (Kodi likes this)
|
||||||
else
|
else
|
||||||
pathOut=""
|
pathAbsOutDecoded=""
|
||||||
fi
|
fi
|
||||||
if [ $sanename != $filename ]; then
|
|
||||||
pathOutFilename="$outDir/$pathOut/$filename"
|
# Save the insane filename in case saneRenamix did not work once before
|
||||||
funcLog 5 "pathOutFilename: $pathOutFilename"
|
if [ $sanename != $filename ]; then # No sanename
|
||||||
|
pathAbsOutDecodedInsane="$outDir/$pathAbsOutDecoded/$filename"
|
||||||
|
funcLog 5 "pathAbsOutDecodedInsane: $pathAbsOutDecodedInsane"
|
||||||
fi
|
fi
|
||||||
pathOut="$outDir/$pathOut/$sanename"
|
|
||||||
funcLog 5 "pathOut: $pathOut"
|
# This will be the absolute path to the output file (e.g. /final/Good.Wife/Good.Wife..S05E14..Ein.paar.Worte.HQ.avi)
|
||||||
|
pathAbsOutDecoded="$outDir/$pathAbsOutDecoded/$sanename"
|
||||||
|
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"
|
||||||
|
funcLog 5 "pathAbsOutCut: $pathAbsOutCut"
|
||||||
}
|
}
|
||||||
|
|
||||||
function funcProcessFiles {
|
function funcProcessFiles {
|
||||||
|
@ -287,17 +304,17 @@ function funcProcessFiles {
|
||||||
echo -e " >> \033[32m$sanename\033[37m";
|
echo -e " >> \033[32m$sanename\033[37m";
|
||||||
|
|
||||||
|
|
||||||
if [ -n "$pathOutFilename" -a -f "$pathOutFilename" ]; then # Sanerenamix could not name this file before, but now it can
|
if [ -n "$pathAbsOutDecodedInsane" -a -f "$pathAbsOutDecodedInsane" ]; then # Sanerenamix could not name this file before, but now it can
|
||||||
funcLog 4 "Renamed $filename to $sanename"
|
funcLog 4 "Renamed $filename to $sanename"
|
||||||
mv $pathOutFilename $pathOut
|
mv $pathAbsOutDecodedInsane $pathAbsOutDecoded
|
||||||
fi
|
fi
|
||||||
if [ -f "$pathOut" ]; then
|
if [ -f "$pathAbsOutDecoded" ]; then
|
||||||
funcLog 4 "File was already handled."
|
funcLog 4 "File was already handled."
|
||||||
funcRemove $file
|
funcRemove $file
|
||||||
continue;
|
continue;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
funcDecode "$pathEncoded";
|
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
|
||||||
|
@ -307,7 +324,7 @@ function funcProcessFiles {
|
||||||
continue;
|
continue;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#funcCut "$pathDecoded"
|
#funcCut "$pathTmpAbsDecoded"
|
||||||
if [ $success -ne 1 ]; then # Cutting failed, we can skip the rest
|
if [ $success -ne 1 ]; then # Cutting failed, we can skip the rest
|
||||||
continue;
|
continue;
|
||||||
fi
|
fi
|
||||||
|
@ -324,30 +341,30 @@ function funcProcessFiles {
|
||||||
function funcDecode {
|
function funcDecode {
|
||||||
local sizeEn;
|
local sizeEn;
|
||||||
local sizeDe;
|
local sizeDe;
|
||||||
if [ -e "$pathDecoded" ]; then # If we decoded this file before
|
if [ -e "$pathTmpAbsDecoded" ]; then # If we decoded this file before
|
||||||
sizeEn=`stat -c%s "$pathEncoded"`
|
sizeEn=`stat -c%s "$pathAbsEncoded"`
|
||||||
sizeDe=`stat -c%s "$pathDecoded"`
|
sizeDe=`stat -c%s "$pathTmpAbsDecoded"`
|
||||||
if [ $(($sizeEn-$sizeDe)) -eq 522 ]; then # If decoding was successful
|
if [ $(($sizeEn-$sizeDe)) -eq 522 ]; then # If decoding was successful
|
||||||
funcLog 3 "File was already decoded: $pathDecoded" # Simply do nothing
|
funcLog 3 "File was already decoded: $pathTmpAbsDecoded" # Simply do nothing
|
||||||
pathMovie="$pathDecoded"
|
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"
|
||||||
rm "$pathDecoded"
|
rm "$pathTmpAbsDecoded"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ ! -e "$pathDecoded" ]; then # If don't find the decoded file in $uncutDir
|
if [ ! -e "$pathTmpAbsDecoded" ]; then # If don't find the decoded file in $uncutDir
|
||||||
funcLog 4 "Decoding $filename"
|
funcLog 4 "Decoding $filename"
|
||||||
funcLog 5 " $cmdDecode $cmdDecodeArgs $pathEncoded"
|
funcLog 5 " $cmdDecode $cmdDecodeArgs $pathAbsEncoded"
|
||||||
#echo " $cmdDecode $cmdDecodeArgs $pathEncoded"
|
#echo " $cmdDecode $cmdDecodeArgs $pathAbsEncoded"
|
||||||
|
|
||||||
$cmdDecode $cmdDecodeArgs "$pathEncoded" # Deocde the file
|
$cmdDecode $cmdDecodeArgs "$pathAbsEncoded" # Deocde the file
|
||||||
|
|
||||||
success=$?
|
success=$?
|
||||||
if [ $success -eq 0 ]; then # if otrdecoder exited successfully
|
if [ $success -eq 0 ]; then # if otrdecoder exited successfully
|
||||||
if [ -f "$pathDecoded" ]; 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="$pathDecoded"
|
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!"
|
||||||
|
@ -363,15 +380,15 @@ function funcDecode {
|
||||||
function funcRemove {
|
function funcRemove {
|
||||||
case $remove in
|
case $remove in
|
||||||
2) # if we shall delete the file
|
2) # if we shall delete the file
|
||||||
funcLog 4 "Deleting $pathEncoded"
|
funcLog 4 "Deleting $pathAbsEncoded"
|
||||||
rm -f "$pathEncoded";;
|
rm -f "$pathAbsEncoded";;
|
||||||
1)
|
1)
|
||||||
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"
|
funcLog 3 "Deleting otrkey, torrent was removed"
|
||||||
rm -f "$pathEncoded"; # Delete otrkey, too
|
rm -f "$pathAbsEncoded"; # Delete otrkey, too
|
||||||
fi
|
fi
|
||||||
fi;;
|
fi;;
|
||||||
esac
|
esac
|
||||||
|
@ -379,19 +396,19 @@ function funcRemove {
|
||||||
}
|
}
|
||||||
|
|
||||||
function funcCut {
|
function funcCut {
|
||||||
funcLog 4 "Cutting $pathDecoded"
|
funcLog 4 "Cutting $pathTmpAbsDecoded"
|
||||||
funcLog 5 " $cmdCut $cmdCutArgs $pathDecoded"
|
funcLog 5 " $cmdCut $cmdCutArgs $pathTmpAbsDecoded"
|
||||||
|
|
||||||
$cmdCut $cmdCutArgs "$pathDecoded"
|
$cmdCut $cmdCutArgs "$pathTmpAbsDecoded"
|
||||||
success=$?
|
success=$?
|
||||||
case $success in
|
case $success in
|
||||||
0)
|
0)
|
||||||
funcLog 4 "Successfully cut"
|
funcLog 4 "Successfully cut"
|
||||||
pathMove="$pathCut"
|
pathMove="$pathTmpAbsCut"
|
||||||
success=1;;
|
success=1;;
|
||||||
5)
|
5)
|
||||||
funcLog 3 "No cutlist found"
|
funcLog 3 "No cutlist found"
|
||||||
pathMove="$pathCut"
|
pathMove="$pathTmpAbsCut"
|
||||||
success=1;;
|
success=1;;
|
||||||
*)
|
*)
|
||||||
funcLog 1 "An error occured while cutting: $success!"
|
funcLog 1 "An error occured while cutting: $success!"
|
||||||
|
@ -400,10 +417,10 @@ function funcCut {
|
||||||
}
|
}
|
||||||
|
|
||||||
function funcMove {
|
function funcMove {
|
||||||
if [ ! -d "$pathOut" ]; then
|
if [ ! -d "$pathAbsOutDecoded" ]; then
|
||||||
mkdir -p "$(dirname $pathOut)"
|
mkdir -p "$(dirname $pathAbsOutDecoded)"
|
||||||
fi
|
fi
|
||||||
mv -f "$pathMovie" "$pathOut"
|
mv -f "$pathMovie" "$pathAbsOutDecoded"
|
||||||
success=1
|
success=1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue