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
				
			
		
							
								
								
									
										13
									
								
								config
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								config
									
									
									
									
									
								
							|  | @ -9,11 +9,20 @@ function funcConfigPre {	# These values are set at the beginning of the script | |||
| 	delugeDir="/etc/deluged"										# Config dir of DelugeD | ||||
| 	inDir="/Multimedia/Video/.Downloaded"							# Dir with .otrkeys | ||||
| 	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) | ||||
| 
 | ||||
| 	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 | ||||
| 	# 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. | ||||
|  |  | |||
							
								
								
									
										89
									
								
								otrDecodeAll
									
									
									
									
									
								
							
							
						
						
									
										89
									
								
								otrDecodeAll
									
									
									
									
									
								
							|  | @ -13,6 +13,8 @@ logLevel=0 | |||
| echoLevel=5 | ||||
| lastKodiCheck=0 | ||||
| cutAppendix="-cut.mkv" | ||||
| declare -A label2Dir | ||||
| declare -A label2SaneRename | ||||
| 
 | ||||
| 
 | ||||
| PwD=$(readlink -e $0)	# Get the path to this script | ||||
|  | @ -39,6 +41,48 @@ function funcLog { | |||
| 	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 { | ||||
| 	if [ ! -r "$PwD/config" ]; then | ||||
| 		funcLog 1 "$PwD/config does not exist" | ||||
|  | @ -184,8 +228,13 @@ function funcUnlock { | |||
| } | ||||
| 
 | ||||
| function funcGetLabel { | ||||
| 	if [ -n "$torrentDb" -a -r "$torrentDb" ]; then | ||||
| 		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 { | ||||
|  | @ -214,20 +263,19 @@ function funcMakeVars { | |||
| 	# 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 | ||||
| 		case $label in | ||||
| 			"movie")					# Normal movies | ||||
| 				pathAbsOutDecoded="Filme";; | ||||
| 			"movie-en")					# English movies | ||||
| 				pathAbsOutDecoded="Filme-En";; | ||||
| 			"docu")						# Documentations | ||||
| 				pathAbsOutDecoded="Dokumentationen";; | ||||
| 			"tvserie")					# TV Series. Use saneRenamix here | ||||
| 				pathAbsOutDecoded="Serien" | ||||
| 				if [ -n "$cmdSaneRenamix" ]; then | ||||
| 	if [ ${#label2Dir[@]} -gt 0 -a "$label" != "N\\A" ]; then				# if we want to use labels | ||||
| 		if [ -z "$label" ]; then													# don't allow empty labels | ||||
| 			pathAbsOutDecoded="" | ||||
| 		else | ||||
| 			pathAbsOutDecoded="${label2Dir["$label"]}"								# get relative output directory for this label | ||||
| 			if [ -z "$pathAbsOutDecoded" ]; then | ||||
| 				funcLog 2 "Unrecognized label: $label" | ||||
| 				label="" | ||||
| 				pathAbsOutDecoded="" | ||||
| 			elif [ ${label2SaneRename["$label"]} -eq 1 ]; then						# call SaneRenamix if indicated | ||||
| 				tmp="$($cmdSaneRenamix $cmdSaneRenamixArgs $filename)" | ||||
| 					err=$? | ||||
| 					case $err in | ||||
| 				local err=$? | ||||
| 				case $err in		# return value conversion | ||||
| 				0) | ||||
| 					bibname="${tmp%%..*}" | ||||
| 					sanename="$tmp" | ||||
|  | @ -253,16 +301,11 @@ function funcMakeVars { | |||
| 				*) | ||||
| 					funcLog 1 "SaneRenamix: Unknown error $err";; | ||||
| 				esac | ||||
| 				fi;; | ||||
| 			*) | ||||
| 				funcLog 2 "Unrecognized label: $label" | ||||
| 				label="" | ||||
| 				pathAbsOutDecoded="";; | ||||
| 		esac | ||||
| 		pathAbsOutDecoded="$pathAbsOutDecoded/$bibname"		# Append bibname: This is the series name or the movie name (Kodi likes this) | ||||
| 	else | ||||
| 		pathAbsOutDecoded="" | ||||
| 			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 | ||||
| 	if [ $sanename != $filename ]; then	# No sanename | ||||
|  | @ -307,7 +350,7 @@ function funcProcessFiles { | |||
| 			funcLog 4 "Label did not match filter. Skipping"; | ||||
| 			continue; | ||||
| 		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" | ||||
| 			continue; | ||||
| 		fi | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue