mirror of
				https://github.com/Jonny007-MKD/OTR-DecodeAll
				synced 2025-10-31 15:45:35 +01:00 
			
		
		
		
	Let user define labels and their directories in config
This commit is contained in:
		
							parent
							
								
									a8de4e2bc2
								
							
						
					
					
						commit
						78f86eba63
					
				
					 2 changed files with 107 additions and 55 deletions
				
			
		
							
								
								
									
										19
									
								
								config
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								config
									
									
									
									
									
								
							|  | @ -9,15 +9,24 @@ function funcConfigPre {	# These values are set at the beginning of the script | ||||||
| 	delugeDir="/etc/deluged"										# Config dir of DelugeD | 	delugeDir="/etc/deluged"										# Config dir of DelugeD | ||||||
| 	inDir="/Multimedia/Video/.Downloaded"							# Dir with .otrkeys | 	inDir="/Multimedia/Video/.Downloaded"							# Dir with .otrkeys | ||||||
| 	tempDir="/Multimedia/Video/.Temp"								# Dir with decoded and cut videos (output of decoder and cutter) | 	tempDir="/Multimedia/Video/.Temp"								# Dir with decoded and cut videos (output of decoder and cutter) | ||||||
| 	outDir="/Multimedia/Video/"										# Final dir with videos | 	outDir="/Multimedia/Video"										# Final dir with videos | ||||||
| 
 | 
 | ||||||
| 	torrentDb="/home/deluged/torrents.db"							# File with file names and labels (see at github: OTR-TorrentDb) |  | ||||||
| 	kodiUrl="user:password@localhost:8080"							# Specify user, password and port for Kodi JSON API (HTTP interface) | 	kodiUrl="user:password@localhost:8080"							# Specify user, password and port for Kodi JSON API (HTTP interface) | ||||||
| 
 | 
 | ||||||
|  | 	torrentDb="/home/deluged/torrents.db"							# File with file names and labels (see at github: OTR-TorrentDb) (optional) | ||||||
|  | 	# Add label to directory mapping. (optional) | ||||||
|  | 	#   1st arg: Label | ||||||
|  | 	#   2nd arg: Each movie with this label will be moved to this subdirectory of $outDir | ||||||
|  | 	#   3rd arg: (optional) Whether SaneRenamix shall be used for movies with this label (default: false) | ||||||
|  | 	addLabel "movie"	"Filme"				0 | ||||||
|  | 	addLabel "movie-en" "Filme-En"			"false" | ||||||
|  | 	addLabel "docu"		"Dokumentationen" | ||||||
|  | 	addLabel "tvserie"	"Serien"			true | ||||||
|  | 
 | ||||||
| 	logFile="/home/deluged/otrDecodeAll.log"						# path to the log file | 	logFile="/home/deluged/otrDecodeAll.log"						# path to the log file | ||||||
| 	# log levels:	0=off; 1=error; 2=warn; 3=info; 4 debug; 5 verbose debug | 	# log levels:	0=off; 1=error; 2=warn; 3=info; 4 debug; 5 verbose debug | ||||||
| 	logLevel=2														#level, which messages shall be written into the log. | 	logLevel=2														# level, which messages shall be written into the log. | ||||||
| 	echoLevel=5														#level, which messages shall be written to stdout. | 	echoLevel=5														# level, which messages shall be written to stdout. | ||||||
| 
 | 
 | ||||||
| 	umask 0002														# Set permissions 775/664 per default | 	umask 0002														# Set permissions 775/664 per default | ||||||
| } | } | ||||||
|  | @ -30,7 +39,7 @@ function funcConfigPost { | ||||||
| 	cmdDecodeArgs="-x -e $user -p $pass -D $tempDir"				# for pyropeters otrdecoder | 	cmdDecodeArgs="-x -e $user -p $pass -D $tempDir"				# for pyropeters otrdecoder | ||||||
| 
 | 
 | ||||||
| 	#cmdDecode="/home/pi/bin/qemu-x86_64 -L /home/pi/ /home/pi/bin64/otrdecoder-64" | 	#cmdDecode="/home/pi/bin/qemu-x86_64 -L /home/pi/ /home/pi/bin64/otrdecoder-64" | ||||||
| 	#cmdDecodeArgs="-e $user -p $pass -o "$tempDir" -i"			# for original otrdecoder | 	#cmdDecodeArgs="-e $user -p $pass -o "$tempDir" -i"				# for original otrdecoder | ||||||
| 
 | 
 | ||||||
| 	#cmdDecode="/usr/bin/otrpidecoder"								# path to NYrks otrdecoder | 	#cmdDecode="/usr/bin/otrpidecoder"								# path to NYrks otrdecoder | ||||||
| 	#cmdDecodeArgs="-d -e $user -p $pass"							 | 	#cmdDecodeArgs="-d -e $user -p $pass"							 | ||||||
|  |  | ||||||
							
								
								
									
										143
									
								
								otrDecodeAll
									
									
									
									
									
								
							
							
						
						
									
										143
									
								
								otrDecodeAll
									
									
									
									
									
								
							|  | @ -13,6 +13,8 @@ logLevel=0 | ||||||
| echoLevel=5 | echoLevel=5 | ||||||
| lastKodiCheck=0 | lastKodiCheck=0 | ||||||
| cutAppendix="-cut.mkv" | cutAppendix="-cut.mkv" | ||||||
|  | declare -A label2Dir | ||||||
|  | declare -A label2SaneRename | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| PwD=$(readlink -e $0)	# Get the path to this script | PwD=$(readlink -e $0)	# Get the path to this script | ||||||
|  | @ -39,6 +41,48 @@ function funcLog { | ||||||
| 	fi | 	fi | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function addLabel { | ||||||
|  | 	success=1; | ||||||
|  | 	case $# in | ||||||
|  | 	[0-1]) | ||||||
|  | 		funcLog 1 "Not enough arguments given for addLabel! Give at least name and directory" | ||||||
|  | 		success=0;; | ||||||
|  | 	2) | ||||||
|  | 		sr=0;; | ||||||
|  | 	3) | ||||||
|  | 		case $3 in | ||||||
|  | 		0)     ;& | ||||||
|  | 		[fF])  ;& | ||||||
|  | 		false) ;& | ||||||
|  | 		no) | ||||||
|  | 			sr=0;; | ||||||
|  | 
 | ||||||
|  | 		1)     ;& | ||||||
|  | 		[tT])  ;& | ||||||
|  | 		true)  ;& | ||||||
|  | 		yes) | ||||||
|  | 			sr=1;; | ||||||
|  | 		*) | ||||||
|  | 			funcLog 1 "addLabel: Could not understand third argument \"$3\"! Please give \"true\" or \"false\" to specify whether SaneRenamix shall be used for this label." | ||||||
|  | 			success=0;; | ||||||
|  | 		esac;; | ||||||
|  | 	*) | ||||||
|  | 		funcLog 1 "Too many arguments for addLabel! Give no more than name, directory and bool whether we shall use sanerenamix for this label" | ||||||
|  | 		success=0;; | ||||||
|  | 	esac | ||||||
|  | 
 | ||||||
|  | 	if [ ! -d "$outDir/$2" ]; then | ||||||
|  | 		funcLog 1 "addLabel: Directory $outDir/$2 does not exist. Please create it first!" | ||||||
|  | 		success=0; | ||||||
|  | 	fi | ||||||
|  | 
 | ||||||
|  | 	if [ $success -eq 1 ]; then | ||||||
|  | 		funcLog 5 "Adding label \"$1\"	with dir = \"$2\"	and sanerename = $sr" | ||||||
|  | 		label2Dir["$1"]="$2"; | ||||||
|  | 		label2SaneRename["$1"]=$sr; | ||||||
|  | 	fi | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function funcGetConfig { | function funcGetConfig { | ||||||
| 	if [ ! -r "$PwD/config" ]; then | 	if [ ! -r "$PwD/config" ]; then | ||||||
| 		funcLog 1 "$PwD/config does not exist" | 		funcLog 1 "$PwD/config does not exist" | ||||||
|  | @ -184,8 +228,13 @@ function funcUnlock { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function funcGetLabel { | function funcGetLabel { | ||||||
| 	label="$(grep -m 1 "$filename" $torrentDb | grep -o ' [a-zA-Z0-9_-]*$' | grep -o '[a-zA-Z0-9_-]*$')" | 	if [ -n "$torrentDb" -a -r "$torrentDb" ]; then | ||||||
| 	funcLog 5 "label: $label" | 		label="$(grep -m 1 "$filename" $torrentDb | grep -o ' [a-zA-Z0-9_-]*$' | grep -o '[a-zA-Z0-9_-]*$')" | ||||||
|  | 		funcLog 5 "label: $label" | ||||||
|  | 	else | ||||||
|  | 		funcLog 5 "no/incorrect torrentDb given" | ||||||
|  | 		label="N\\A" | ||||||
|  | 	fi | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function funcMakeVars { | function funcMakeVars { | ||||||
|  | @ -214,55 +263,49 @@ function funcMakeVars { | ||||||
| 	# sanename is normally the filename. In case of tv series the sanename will also contain the series and episode number and title | 	# 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 | 	## TODO: Introduce some dictionary in the config and make this more general | ||||||
| 	sanename=$filename		# Default value (in case of error) | 	sanename=$filename		# Default value (in case of error) | ||||||
| 	if [ -n "$label" ]; then | 	if [ ${#label2Dir[@]} -gt 0 -a "$label" != "N\\A" ]; then				# if we want to use labels | ||||||
| 		case $label in | 		if [ -z "$label" ]; then													# don't allow empty labels | ||||||
| 			"movie")					# Normal movies | 			pathAbsOutDecoded="" | ||||||
| 				pathAbsOutDecoded="Filme";; | 		else | ||||||
| 			"movie-en")					# English movies | 			pathAbsOutDecoded="${label2Dir["$label"]}"								# get relative output directory for this label | ||||||
| 				pathAbsOutDecoded="Filme-En";; | 			if [ -z "$pathAbsOutDecoded" ]; then | ||||||
| 			"docu")						# Documentations |  | ||||||
| 				pathAbsOutDecoded="Dokumentationen";; |  | ||||||
| 			"tvserie")					# TV Series. Use saneRenamix here |  | ||||||
| 				pathAbsOutDecoded="Serien" |  | ||||||
| 				if [ -n "$cmdSaneRenamix" ]; then |  | ||||||
| 					tmp="$($cmdSaneRenamix $cmdSaneRenamixArgs $filename)" |  | ||||||
| 					err=$? |  | ||||||
| 					case $err in |  | ||||||
| 						0) |  | ||||||
| 							bibname="${tmp%%..*}" |  | ||||||
| 							sanename="$tmp" |  | ||||||
| 							funcLog 5 "sanename: $sanename";; |  | ||||||
| 						1) |  | ||||||
| 							funcLog 1 "SaneRenamix: General error!";; |  | ||||||
| 						2) |  | ||||||
| 							funcLog 1 "SaneRenamix: Specified language not recognized";; |  | ||||||
| 						3) |  | ||||||
| 							funcLog 3 "SaneRenamix: Aborted (Ctrl+C)";; |  | ||||||
| 						10) |  | ||||||
| 							funcLog 2 "SaneRenamix: Series not found in TvDB";; |  | ||||||
| 						11) |  | ||||||
| 							funcLog 2 "SaneRenamix: Series not found in EPG";; |  | ||||||
| 						20) |  | ||||||
| 							funcLog 2 "SaneRenamix: No info for this episode found";; |  | ||||||
| 						21) |  | ||||||
| 							funcLog 2 "SaneRenamix: No episode title found in EPG";; |  | ||||||
| 						40) |  | ||||||
| 							funcLog 1 "SaneRenamix: Downloading EPG data failed";; |  | ||||||
| 						41) |  | ||||||
| 							funcLog 1 "SaneRenamix: Downloading list of episodes from TvDB failed";; |  | ||||||
| 						*) |  | ||||||
| 							funcLog 1 "SaneRenamix: Unknown error $err";; |  | ||||||
| 						esac |  | ||||||
| 				fi;; |  | ||||||
| 			*) |  | ||||||
| 				funcLog 2 "Unrecognized label: $label" | 				funcLog 2 "Unrecognized label: $label" | ||||||
| 				label="" | 				label="" | ||||||
| 				pathAbsOutDecoded="";; | 				pathAbsOutDecoded="" | ||||||
| 		esac | 			elif [ ${label2SaneRename["$label"]} -eq 1 ]; then						# call SaneRenamix if indicated | ||||||
| 		pathAbsOutDecoded="$pathAbsOutDecoded/$bibname"		# Append bibname: This is the series name or the movie name (Kodi likes this) | 				tmp="$($cmdSaneRenamix $cmdSaneRenamixArgs $filename)" | ||||||
| 	else | 				local err=$? | ||||||
| 		pathAbsOutDecoded="" | 				case $err in		# return value conversion | ||||||
| 	fi | 				0) | ||||||
|  | 					bibname="${tmp%%..*}" | ||||||
|  | 					sanename="$tmp" | ||||||
|  | 					funcLog 5 "sanename: $sanename";; | ||||||
|  | 				1) | ||||||
|  | 					funcLog 1 "SaneRenamix: General error!";; | ||||||
|  | 				2) | ||||||
|  | 					funcLog 1 "SaneRenamix: Specified language not recognized";; | ||||||
|  | 				3) | ||||||
|  | 					funcLog 3 "SaneRenamix: Aborted (Ctrl+C)";; | ||||||
|  | 				10) | ||||||
|  | 					funcLog 2 "SaneRenamix: Series not found in TvDB";; | ||||||
|  | 				11) | ||||||
|  | 					funcLog 2 "SaneRenamix: Series not found in EPG";; | ||||||
|  | 				20) | ||||||
|  | 					funcLog 2 "SaneRenamix: No info for this episode found";; | ||||||
|  | 				21) | ||||||
|  | 					funcLog 2 "SaneRenamix: No episode title found in EPG";; | ||||||
|  | 				40) | ||||||
|  | 					funcLog 1 "SaneRenamix: Downloading EPG data failed";; | ||||||
|  | 				41) | ||||||
|  | 					funcLog 1 "SaneRenamix: Downloading list of episodes from TvDB failed";; | ||||||
|  | 				*) | ||||||
|  | 					funcLog 1 "SaneRenamix: Unknown error $err";; | ||||||
|  | 				esac | ||||||
|  | 			fi | ||||||
|  | 		fi | ||||||
|  | 	fi																			# if we do not want to use labels | ||||||
|  | 
 | ||||||
|  | 	pathAbsOutDecoded="$pathAbsOutDecoded/$bibname"		# Append bibname: This is the series name or the movie name (Kodi likes this) | ||||||
| 
 | 
 | ||||||
| 	# Save the insane filename in case saneRenamix did not work once before | 	# Save the insane filename in case saneRenamix did not work once before | ||||||
| 	if [ $sanename != $filename ]; then	# No sanename | 	if [ $sanename != $filename ]; then	# No sanename | ||||||
|  | @ -307,7 +350,7 @@ function funcProcessFiles { | ||||||
| 			funcLog 4 "Label did not match filter. Skipping"; | 			funcLog 4 "Label did not match filter. Skipping"; | ||||||
| 			continue; | 			continue; | ||||||
| 		fi | 		fi | ||||||
| 		if [ -z "$label" ]; then											# Empty label --> skip | 		if [ -z "$label" -a "$label" != "N\\A" ]; then						# Empty label and torrentDb does exist --> skip | ||||||
| 			funcLog 1 "No label specified for this movie. Skipping" | 			funcLog 1 "No label specified for this movie. Skipping" | ||||||
| 			continue; | 			continue; | ||||||
| 		fi | 		fi | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Jonny007-MKD
						Jonny007-MKD