mirror of
https://git.lecygnenoir.info/LecygneNoir/prismedia.git
synced 2025-10-03 09:29:16 +02:00
Modify the NFO functions to allow an enhanced use with priorities in options
This commit is contained in:
parent
e91ada951f
commit
17017ae90c
1 changed files with 62 additions and 58 deletions
|
@ -107,6 +107,7 @@ def remove_empty_kwargs(**kwargs):
|
||||||
good_kwargs[key] = value
|
good_kwargs[key] = value
|
||||||
return good_kwargs
|
return good_kwargs
|
||||||
|
|
||||||
|
|
||||||
def searchThumbnail(options):
|
def searchThumbnail(options):
|
||||||
video_directory = dirname(options.get('--file')) + "/"
|
video_directory = dirname(options.get('--file')) + "/"
|
||||||
# First, check for thumbnail based on videoname
|
# First, check for thumbnail based on videoname
|
||||||
|
@ -124,73 +125,76 @@ def searchThumbnail(options):
|
||||||
options['--thumbnail'] = video_directory + video_file + ".jpeg"
|
options['--thumbnail'] = video_directory + video_file + ".jpeg"
|
||||||
return options
|
return options
|
||||||
|
|
||||||
# return the nfo as a RawConfigParser object
|
|
||||||
def loadNFO(options):
|
|
||||||
video_directory = dirname(options.get('--file')) + "/"
|
|
||||||
if options.get('--nfo'):
|
|
||||||
try:
|
|
||||||
logging.info("Using " + options.get('--nfo') + " as NFO, loading...")
|
|
||||||
if isfile(options.get('--nfo')):
|
|
||||||
nfo = RawConfigParser()
|
|
||||||
nfo.read(options.get('--nfo'), encoding='utf-8')
|
|
||||||
return nfo
|
|
||||||
else:
|
|
||||||
logging.error("Given NFO file does not exist, please check your path.")
|
|
||||||
exit(1)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error("Problem with NFO file: " + str(e))
|
|
||||||
exit(1)
|
|
||||||
else:
|
|
||||||
if options.get('--name'):
|
|
||||||
nfo_file = video_directory + options.get('--name') + ".txt"
|
|
||||||
if isfile(nfo_file):
|
|
||||||
try:
|
|
||||||
logging.info("Using " + nfo_file + " as NFO, loading...")
|
|
||||||
nfo = RawConfigParser()
|
|
||||||
nfo.read(nfo_file, encoding='utf-8')
|
|
||||||
return nfo
|
|
||||||
except Exception as e:
|
|
||||||
logging.error("Problem with NFO file: " + str(e))
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
# if --nfo and --name does not exist, use --file as default
|
# return the nfo as a RawConfigParser object
|
||||||
video_file = splitext(basename(options.get('--file')))[0]
|
def loadNFO(filename):
|
||||||
nfo_file = video_directory + video_file + ".txt"
|
try:
|
||||||
if isfile(nfo_file):
|
logging.info("Loading " + filename + " as NFO")
|
||||||
try:
|
nfo = RawConfigParser()
|
||||||
logging.info("Using " + nfo_file + " as NFO, loading...")
|
nfo.read(filename, encoding='utf-8')
|
||||||
nfo = RawConfigParser()
|
return nfo
|
||||||
nfo.read(nfo_file, encoding='utf-8')
|
except Exception as e:
|
||||||
return nfo
|
logging.error("Problem loading NFO file " + filename + ": " + str(e))
|
||||||
except Exception as e:
|
exit(1)
|
||||||
logging.error("Problem with nfo file: " + str(e))
|
|
||||||
exit(1)
|
|
||||||
logging.info("No suitable NFO found, skipping.")
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def parseNFO(options):
|
def parseNFO(options):
|
||||||
nfo = loadNFO(options)
|
video_directory = dirname(options.get('--file'))
|
||||||
if nfo:
|
directory_name = basename(video_directory)
|
||||||
# We need to check all options and replace it with the nfo value if not defined (None or False)
|
nfo_txt = False
|
||||||
for key, value in options.items():
|
nfo_directory = False
|
||||||
key = key.replace("-", "")
|
nfo_videoname = False
|
||||||
try:
|
nfo_file = False
|
||||||
# get string options
|
nfo_cli = False
|
||||||
if value is None and nfo.get('video', key):
|
|
||||||
options['--' + key] = nfo.get('video', key)
|
if isfile(video_directory + "/" + "nfo.txt"):
|
||||||
# get boolean options
|
nfo_txt = loadNFO(video_directory + "/" + "nfo.txt")
|
||||||
elif value is False and nfo.getboolean('video', key):
|
|
||||||
options['--' + key] = nfo.getboolean('video', key)
|
if isfile(video_directory + "/" + directory_name+ ".txt"):
|
||||||
except NoOptionError:
|
nfo_directory = loadNFO(video_directory + "/" + directory_name+ ".txt")
|
||||||
continue
|
|
||||||
except NoSectionError:
|
if options.get('--name'):
|
||||||
logging.error("Given NFO file miss section [video], please check syntax of your NFO.")
|
if isfile(video_directory + "/" + options.get('--name')):
|
||||||
exit(1)
|
nfo_videoname = loadNFO(video_directory + "/" + options.get('--name') + ".txt")
|
||||||
|
|
||||||
|
video_file = splitext(basename(options.get('--file')))[0]
|
||||||
|
if isfile(video_directory + "/" + video_file + ".txt"):
|
||||||
|
nfo_file = loadNFO(video_directory + "/" + video_file + ".txt")
|
||||||
|
|
||||||
|
if options.get('--nfo'):
|
||||||
|
if isfile(options.get('--nfo')):
|
||||||
|
nfo_cli = loadNFO(options.get('--nfo'))
|
||||||
|
else:
|
||||||
|
logging.error("Given NFO file does not exist, please check your path.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
# We need to load NFO in this exact order to keep the priorities
|
||||||
|
# options in cli > nfo_cli > nfo_file > nfo_videoname > nfo_directory > nfo_txt
|
||||||
|
for nfo in [nfo_cli, nfo_file, nfo_videoname, nfo_directory, nfo_txt]:
|
||||||
|
if nfo:
|
||||||
|
# We need to check all options and replace it with the nfo value if not defined (None or False)
|
||||||
|
for key, value in options.items():
|
||||||
|
key = key.replace("-", "")
|
||||||
|
try:
|
||||||
|
# get string options
|
||||||
|
if value is None and nfo.get('video', key):
|
||||||
|
options['--' + key] = nfo.get('video', key)
|
||||||
|
# get boolean options
|
||||||
|
elif value is False and nfo.getboolean('video', key):
|
||||||
|
options['--' + key] = nfo.getboolean('video', key)
|
||||||
|
except NoOptionError:
|
||||||
|
continue
|
||||||
|
except NoSectionError:
|
||||||
|
logging.error(nfo + " misses section [video], please check syntax of your NFO.")
|
||||||
|
exit(1)
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
def upcaseFirstLetter(s):
|
def upcaseFirstLetter(s):
|
||||||
return s[0].upper() + s[1:]
|
return s[0].upper() + s[1:]
|
||||||
|
|
||||||
|
|
||||||
def cleanString(toclean):
|
def cleanString(toclean):
|
||||||
toclean = unidecode.unidecode(toclean)
|
toclean = unidecode.unidecode(toclean)
|
||||||
cleaned = re.sub('[^A-Za-z0-9]+', '', toclean)
|
cleaned = re.sub('[^A-Za-z0-9]+', '', toclean)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue