mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-30 11:38:30 -07:00
Too broad exceptions.
* Use .get() with default value instead.
This commit is contained in:
parent
1cd073cd52
commit
df8c6bc20f
4 changed files with 37 additions and 129 deletions
|
@ -11,44 +11,18 @@ from core import logger
|
||||||
def autoFork(section, inputCategory):
|
def autoFork(section, inputCategory):
|
||||||
# auto-detect correct section
|
# auto-detect correct section
|
||||||
# config settings
|
# config settings
|
||||||
try:
|
|
||||||
host = core.CFG[section][inputCategory]["host"]
|
|
||||||
port = core.CFG[section][inputCategory]["port"]
|
|
||||||
except:
|
|
||||||
host = None
|
|
||||||
port = None
|
|
||||||
|
|
||||||
try:
|
cfg = core.CFG[section][inputCategory]
|
||||||
username = core.CFG[section][inputCategory]["username"]
|
|
||||||
password = core.CFG[section][inputCategory]["password"]
|
|
||||||
except:
|
|
||||||
username = None
|
|
||||||
password = None
|
|
||||||
|
|
||||||
try:
|
host = cfg.get("host")
|
||||||
apikey = core.CFG[section][inputCategory]["apikey"]
|
port = cfg.get("port")
|
||||||
except:
|
username = cfg.get("username")
|
||||||
apikey = None
|
password = cfg.get("password")
|
||||||
|
apikey = cfg.get("apikey")
|
||||||
try:
|
ssl = int(cfg.get("ssl", 0))
|
||||||
ssl = int(core.CFG[section][inputCategory]["ssl"])
|
web_root = cfg.get("web_root", "")
|
||||||
except:
|
fork = core.FORKS.items()[core.FORKS.keys().index(cfg.get("fork", "auto"))]
|
||||||
ssl = 0
|
protocol = "https://" if ssl else "http://"
|
||||||
|
|
||||||
try:
|
|
||||||
web_root = core.CFG[section][inputCategory]["web_root"]
|
|
||||||
except:
|
|
||||||
web_root = ""
|
|
||||||
|
|
||||||
try:
|
|
||||||
fork = core.FORKS.items()[core.FORKS.keys().index(core.CFG[section][inputCategory]["fork"])]
|
|
||||||
except:
|
|
||||||
fork = "auto"
|
|
||||||
|
|
||||||
if ssl:
|
|
||||||
protocol = "https://"
|
|
||||||
else:
|
|
||||||
protocol = "http://"
|
|
||||||
|
|
||||||
detected = False
|
detected = False
|
||||||
if section == "NzbDrone":
|
if section == "NzbDrone":
|
||||||
|
|
|
@ -16,11 +16,10 @@ def external_script(outputDestination, torrentName, torrentLabel, settings):
|
||||||
core.USER_SCRIPT_MEDIAEXTENSIONS = core.USER_SCRIPT_MEDIAEXTENSIONS.split(',')
|
core.USER_SCRIPT_MEDIAEXTENSIONS = core.USER_SCRIPT_MEDIAEXTENSIONS.split(',')
|
||||||
except:
|
except:
|
||||||
core.USER_SCRIPT_MEDIAEXTENSIONS = []
|
core.USER_SCRIPT_MEDIAEXTENSIONS = []
|
||||||
try:
|
|
||||||
core.USER_SCRIPT = settings["user_script_path"]
|
core.USER_SCRIPT = settings.get("user_script_path")
|
||||||
except:
|
|
||||||
core.USER_SCRIPT = None
|
if not core.USER_SCRIPT or core.USER_SCRIPT == "None": # do nothing and return success.
|
||||||
if core.USER_SCRIPT is None or core.USER_SCRIPT == "None": # do nothing and return success.
|
|
||||||
return [0, ""]
|
return [0, ""]
|
||||||
try:
|
try:
|
||||||
core.USER_SCRIPT_PARAM = settings["user_script_param"]
|
core.USER_SCRIPT_PARAM = settings["user_script_param"]
|
||||||
|
@ -34,14 +33,9 @@ def external_script(outputDestination, torrentName, torrentLabel, settings):
|
||||||
core.USER_SCRIPT_SUCCESSCODES = core.USER_SCRIPT_SUCCESSCODES.split(',')
|
core.USER_SCRIPT_SUCCESSCODES = core.USER_SCRIPT_SUCCESSCODES.split(',')
|
||||||
except:
|
except:
|
||||||
core.USER_SCRIPT_SUCCESSCODES = 0
|
core.USER_SCRIPT_SUCCESSCODES = 0
|
||||||
try:
|
|
||||||
core.USER_SCRIPT_CLEAN = int(settings["user_script_clean"])
|
core.USER_SCRIPT_CLEAN = int(settings.get("user_script_clean", 1))
|
||||||
except:
|
core.USER_SCRIPT_RUNONCE = int(settings.get("user_script_runOnce", 1))
|
||||||
core.USER_SCRIPT_CLEAN = 1
|
|
||||||
try:
|
|
||||||
core.USER_SCRIPT_RUNONCE = int(settings["user_script_runOnce"])
|
|
||||||
except:
|
|
||||||
core.USER_SCRIPT_RUNONCE = 1
|
|
||||||
|
|
||||||
if core.CHECK_MEDIA:
|
if core.CHECK_MEDIA:
|
||||||
for video in listMediaFiles(outputDestination, media=True, audio=False, meta=False, archives=False):
|
for video in listMediaFiles(outputDestination, media=True, audio=False, meta=False, archives=False):
|
||||||
|
|
|
@ -740,14 +740,8 @@ def cleanDir(path, section, subsection):
|
||||||
logger.info('Doing Forceful Clean of {0}'.format(path), 'CLEANDIR')
|
logger.info('Doing Forceful Clean of {0}'.format(path), 'CLEANDIR')
|
||||||
rmDir(path)
|
rmDir(path)
|
||||||
return
|
return
|
||||||
try:
|
minSize = int(core.CFG[section][subsection].get('minSize', 0))
|
||||||
minSize = int(core.CFG[section][subsection]['minSize'])
|
delete_ignored = int(core.CFG[section][subsection].get('delete_ignored', 0))
|
||||||
except:
|
|
||||||
minSize = 0
|
|
||||||
try:
|
|
||||||
delete_ignored = int(core.CFG[section][subsection]['delete_ignored'])
|
|
||||||
except:
|
|
||||||
delete_ignored = 0
|
|
||||||
try:
|
try:
|
||||||
num_files = len(listMediaFiles(path, minSize=minSize, delete_ignored=delete_ignored))
|
num_files = len(listMediaFiles(path, minSize=minSize, delete_ignored=delete_ignored))
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -208,18 +208,9 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
||||||
|
|
||||||
for video in videoStreams:
|
for video in videoStreams:
|
||||||
codec = video["codec_name"]
|
codec = video["codec_name"]
|
||||||
try:
|
fr = video.get("avg_frame_rate", 0)
|
||||||
fr = video["avg_frame_rate"]
|
width = video.get("width", 0)
|
||||||
except:
|
height = video.get("height", 0)
|
||||||
fr = 0
|
|
||||||
try:
|
|
||||||
width = video["width"]
|
|
||||||
except:
|
|
||||||
width = 0
|
|
||||||
try:
|
|
||||||
height = video["height"]
|
|
||||||
except:
|
|
||||||
height = 0
|
|
||||||
scale = core.VRESOLUTION
|
scale = core.VRESOLUTION
|
||||||
if codec in core.VCODEC_ALLOW or not core.VCODEC:
|
if codec in core.VCODEC_ALLOW or not core.VCODEC:
|
||||||
video_cmd.extend(['-c:v', 'copy'])
|
video_cmd.extend(['-c:v', 'copy'])
|
||||||
|
@ -270,26 +261,14 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
||||||
if audio2: # right language and codec...
|
if audio2: # right language and codec...
|
||||||
map_cmd.extend(['-map', '0:' + str(audio2[0]["index"])])
|
map_cmd.extend(['-map', '0:' + str(audio2[0]["index"])])
|
||||||
a_mapped.extend([audio2[0]["index"]])
|
a_mapped.extend([audio2[0]["index"]])
|
||||||
try:
|
bitrate = int(audio2[0].get("bit_rate", 0)) / 1000
|
||||||
bitrate = int(audio2[0]["bit_rate"]) / 1000
|
channels = int(audio2[0].get("channels", 0))
|
||||||
except:
|
|
||||||
bitrate = 0
|
|
||||||
try:
|
|
||||||
channels = int(audio2[0]["channels"])
|
|
||||||
except:
|
|
||||||
channels = 0
|
|
||||||
audio_cmd.extend(['-c:a:' + str(used_audio), 'copy'])
|
audio_cmd.extend(['-c:a:' + str(used_audio), 'copy'])
|
||||||
elif audio1: # right language wrong codec.
|
elif audio1: # right language wrong codec.
|
||||||
map_cmd.extend(['-map', '0:' + str(audio1[0]["index"])])
|
map_cmd.extend(['-map', '0:' + str(audio1[0]["index"])])
|
||||||
a_mapped.extend([audio1[0]["index"]])
|
a_mapped.extend([audio1[0]["index"]])
|
||||||
try:
|
bitrate = int(audio1[0].get("bit_rate", 0)) / 1000
|
||||||
bitrate = int(audio1[0]["bit_rate"]) / 1000
|
channels = int(audio1[0].get("channels", 0))
|
||||||
except:
|
|
||||||
bitrate = 0
|
|
||||||
try:
|
|
||||||
channels = int(audio1[0]["channels"])
|
|
||||||
except:
|
|
||||||
channels = 0
|
|
||||||
if core.ACODEC:
|
if core.ACODEC:
|
||||||
audio_cmd.extend(['-c:a:' + str(used_audio), core.ACODEC])
|
audio_cmd.extend(['-c:a:' + str(used_audio), core.ACODEC])
|
||||||
else:
|
else:
|
||||||
|
@ -297,14 +276,8 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
||||||
elif audio3: # just pick the default audio track
|
elif audio3: # just pick the default audio track
|
||||||
map_cmd.extend(['-map', '0:' + str(audio3[0]["index"])])
|
map_cmd.extend(['-map', '0:' + str(audio3[0]["index"])])
|
||||||
a_mapped.extend([audio3[0]["index"]])
|
a_mapped.extend([audio3[0]["index"]])
|
||||||
try:
|
bitrate = int(audio3[0].get("bit_rate", 0)) / 1000
|
||||||
bitrate = int(audio3[0]["bit_rate"]) / 1000
|
channels = int(audio3[0].get("channels", 0))
|
||||||
except:
|
|
||||||
bitrate = 0
|
|
||||||
try:
|
|
||||||
channels = int(audio3[0]["channels"])
|
|
||||||
except:
|
|
||||||
channels = 0
|
|
||||||
if core.ACODEC:
|
if core.ACODEC:
|
||||||
audio_cmd.extend(['-c:a:' + str(used_audio), core.ACODEC])
|
audio_cmd.extend(['-c:a:' + str(used_audio), core.ACODEC])
|
||||||
else:
|
else:
|
||||||
|
@ -331,26 +304,14 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
||||||
if audio4: # right language and codec.
|
if audio4: # right language and codec.
|
||||||
map_cmd.extend(['-map', '0:' + str(audio4[0]["index"])])
|
map_cmd.extend(['-map', '0:' + str(audio4[0]["index"])])
|
||||||
a_mapped.extend([audio4[0]["index"]])
|
a_mapped.extend([audio4[0]["index"]])
|
||||||
try:
|
bitrate = int(audio4[0].get("bit_rate", 0)) / 1000
|
||||||
bitrate = int(audio4[0]["bit_rate"]) / 1000
|
channels = int(audio4[0].get("channels", 0))
|
||||||
except:
|
|
||||||
bitrate = 0
|
|
||||||
try:
|
|
||||||
channels = int(audio4[0]["channels"])
|
|
||||||
except:
|
|
||||||
channels = 0
|
|
||||||
audio_cmd2.extend(['-c:a:' + str(used_audio), 'copy'])
|
audio_cmd2.extend(['-c:a:' + str(used_audio), 'copy'])
|
||||||
elif audio1: # right language wrong codec.
|
elif audio1: # right language wrong codec.
|
||||||
map_cmd.extend(['-map', '0:' + str(audio1[0]["index"])])
|
map_cmd.extend(['-map', '0:' + str(audio1[0]["index"])])
|
||||||
a_mapped.extend([audio1[0]["index"]])
|
a_mapped.extend([audio1[0]["index"]])
|
||||||
try:
|
bitrate = int(audio1[0].get("bit_rate", 0)) / 1000
|
||||||
bitrate = int(audio1[0]["bit_rate"]) / 1000
|
channels = int(audio1[0].get("channels", 0))
|
||||||
except:
|
|
||||||
bitrate = 0
|
|
||||||
try:
|
|
||||||
channels = int(audio1[0]["channels"])
|
|
||||||
except:
|
|
||||||
channels = 0
|
|
||||||
if core.ACODEC2:
|
if core.ACODEC2:
|
||||||
audio_cmd2.extend(['-c:a:' + str(used_audio), core.ACODEC2])
|
audio_cmd2.extend(['-c:a:' + str(used_audio), core.ACODEC2])
|
||||||
else:
|
else:
|
||||||
|
@ -358,14 +319,8 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
||||||
elif audio3: # just pick the default audio track
|
elif audio3: # just pick the default audio track
|
||||||
map_cmd.extend(['-map', '0:' + str(audio3[0]["index"])])
|
map_cmd.extend(['-map', '0:' + str(audio3[0]["index"])])
|
||||||
a_mapped.extend([audio3[0]["index"]])
|
a_mapped.extend([audio3[0]["index"]])
|
||||||
try:
|
bitrate = int(audio3[0].get("bit_rate", 0)) / 1000
|
||||||
bitrate = int(audio3[0]["bit_rate"]) / 1000
|
channels = int(audio3[0].get("channels", 0))
|
||||||
except:
|
|
||||||
bitrate = 0
|
|
||||||
try:
|
|
||||||
channels = int(audio3[0]["channels"])
|
|
||||||
except:
|
|
||||||
channels = 0
|
|
||||||
if core.ACODEC2:
|
if core.ACODEC2:
|
||||||
audio_cmd2.extend(['-c:a:' + str(used_audio), core.ACODEC2])
|
audio_cmd2.extend(['-c:a:' + str(used_audio), core.ACODEC2])
|
||||||
else:
|
else:
|
||||||
|
@ -394,14 +349,8 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
||||||
used_audio += 1
|
used_audio += 1
|
||||||
map_cmd.extend(['-map', '0:' + str(audio["index"])])
|
map_cmd.extend(['-map', '0:' + str(audio["index"])])
|
||||||
audio_cmd3 = []
|
audio_cmd3 = []
|
||||||
try:
|
bitrate = int(audio.get("bit_rate", 0)) / 1000
|
||||||
bitrate = int(audio["bit_rate"]) / 1000
|
channels = int(audio.get("channels", 0))
|
||||||
except:
|
|
||||||
bitrate = 0
|
|
||||||
try:
|
|
||||||
channels = int(audio["channels"])
|
|
||||||
except:
|
|
||||||
channels = 0
|
|
||||||
if audio["codec_name"] in core.ACODEC3_ALLOW:
|
if audio["codec_name"] in core.ACODEC3_ALLOW:
|
||||||
audio_cmd3.extend(['-c:a:' + str(used_audio), 'copy'])
|
audio_cmd3.extend(['-c:a:' + str(used_audio), 'copy'])
|
||||||
else:
|
else:
|
||||||
|
@ -540,10 +489,7 @@ def extract_subs(file, newfilePath, bitbucket):
|
||||||
for n in range(num):
|
for n in range(num):
|
||||||
sub = subStreams[n]
|
sub = subStreams[n]
|
||||||
idx = sub["index"]
|
idx = sub["index"]
|
||||||
try:
|
lan = sub.geet("tags", {}).get("language", "unk")
|
||||||
lan = sub["tags"]["language"]
|
|
||||||
except:
|
|
||||||
lan = "unk"
|
|
||||||
|
|
||||||
if num == 1:
|
if num == 1:
|
||||||
outputFile = os.path.join(subdir, "{0}.srt".format(name))
|
outputFile = os.path.join(subdir, "{0}.srt".format(name))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue