Too broad exceptions.

* Use .get() with default value instead.
This commit is contained in:
Labrys 2016-06-05 13:35:46 -04:00
parent 1cd073cd52
commit df8c6bc20f
4 changed files with 37 additions and 129 deletions

View file

@ -11,44 +11,18 @@ from core import logger
def autoFork(section, inputCategory):
# auto-detect correct section
# config settings
try:
host = core.CFG[section][inputCategory]["host"]
port = core.CFG[section][inputCategory]["port"]
except:
host = None
port = None
try:
username = core.CFG[section][inputCategory]["username"]
password = core.CFG[section][inputCategory]["password"]
except:
username = None
password = None
cfg = core.CFG[section][inputCategory]
try:
apikey = core.CFG[section][inputCategory]["apikey"]
except:
apikey = None
try:
ssl = int(core.CFG[section][inputCategory]["ssl"])
except:
ssl = 0
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://"
host = cfg.get("host")
port = cfg.get("port")
username = cfg.get("username")
password = cfg.get("password")
apikey = cfg.get("apikey")
ssl = int(cfg.get("ssl", 0))
web_root = cfg.get("web_root", "")
fork = core.FORKS.items()[core.FORKS.keys().index(cfg.get("fork", "auto"))]
protocol = "https://" if ssl else "http://"
detected = False
if section == "NzbDrone":

View file

@ -16,11 +16,10 @@ def external_script(outputDestination, torrentName, torrentLabel, settings):
core.USER_SCRIPT_MEDIAEXTENSIONS = core.USER_SCRIPT_MEDIAEXTENSIONS.split(',')
except:
core.USER_SCRIPT_MEDIAEXTENSIONS = []
try:
core.USER_SCRIPT = settings["user_script_path"]
except:
core.USER_SCRIPT = None
if core.USER_SCRIPT is None or core.USER_SCRIPT == "None": # do nothing and return success.
core.USER_SCRIPT = settings.get("user_script_path")
if not core.USER_SCRIPT or core.USER_SCRIPT == "None": # do nothing and return success.
return [0, ""]
try:
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(',')
except:
core.USER_SCRIPT_SUCCESSCODES = 0
try:
core.USER_SCRIPT_CLEAN = int(settings["user_script_clean"])
except:
core.USER_SCRIPT_CLEAN = 1
try:
core.USER_SCRIPT_RUNONCE = int(settings["user_script_runOnce"])
except:
core.USER_SCRIPT_RUNONCE = 1
core.USER_SCRIPT_CLEAN = int(settings.get("user_script_clean", 1))
core.USER_SCRIPT_RUNONCE = int(settings.get("user_script_runOnce", 1))
if core.CHECK_MEDIA:
for video in listMediaFiles(outputDestination, media=True, audio=False, meta=False, archives=False):

View file

@ -740,14 +740,8 @@ def cleanDir(path, section, subsection):
logger.info('Doing Forceful Clean of {0}'.format(path), 'CLEANDIR')
rmDir(path)
return
try:
minSize = int(core.CFG[section][subsection]['minSize'])
except:
minSize = 0
try:
delete_ignored = int(core.CFG[section][subsection]['delete_ignored'])
except:
delete_ignored = 0
minSize = int(core.CFG[section][subsection].get('minSize', 0))
delete_ignored = int(core.CFG[section][subsection].get('delete_ignored', 0))
try:
num_files = len(listMediaFiles(path, minSize=minSize, delete_ignored=delete_ignored))
except:

View file

@ -208,18 +208,9 @@ def buildCommands(file, newDir, movieName, bitbucket):
for video in videoStreams:
codec = video["codec_name"]
try:
fr = video["avg_frame_rate"]
except:
fr = 0
try:
width = video["width"]
except:
width = 0
try:
height = video["height"]
except:
height = 0
fr = video.get("avg_frame_rate", 0)
width = video.get("width", 0)
height = video.get("height", 0)
scale = core.VRESOLUTION
if codec in core.VCODEC_ALLOW or not core.VCODEC:
video_cmd.extend(['-c:v', 'copy'])
@ -270,26 +261,14 @@ def buildCommands(file, newDir, movieName, bitbucket):
if audio2: # right language and codec...
map_cmd.extend(['-map', '0:' + str(audio2[0]["index"])])
a_mapped.extend([audio2[0]["index"]])
try:
bitrate = int(audio2[0]["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio2[0]["channels"])
except:
channels = 0
bitrate = int(audio2[0].get("bit_rate", 0)) / 1000
channels = int(audio2[0].get("channels", 0))
audio_cmd.extend(['-c:a:' + str(used_audio), 'copy'])
elif audio1: # right language wrong codec.
map_cmd.extend(['-map', '0:' + str(audio1[0]["index"])])
a_mapped.extend([audio1[0]["index"]])
try:
bitrate = int(audio1[0]["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio1[0]["channels"])
except:
channels = 0
bitrate = int(audio1[0].get("bit_rate", 0)) / 1000
channels = int(audio1[0].get("channels", 0))
if core.ACODEC:
audio_cmd.extend(['-c:a:' + str(used_audio), core.ACODEC])
else:
@ -297,14 +276,8 @@ def buildCommands(file, newDir, movieName, bitbucket):
elif audio3: # just pick the default audio track
map_cmd.extend(['-map', '0:' + str(audio3[0]["index"])])
a_mapped.extend([audio3[0]["index"]])
try:
bitrate = int(audio3[0]["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio3[0]["channels"])
except:
channels = 0
bitrate = int(audio3[0].get("bit_rate", 0)) / 1000
channels = int(audio3[0].get("channels", 0))
if core.ACODEC:
audio_cmd.extend(['-c:a:' + str(used_audio), core.ACODEC])
else:
@ -331,26 +304,14 @@ def buildCommands(file, newDir, movieName, bitbucket):
if audio4: # right language and codec.
map_cmd.extend(['-map', '0:' + str(audio4[0]["index"])])
a_mapped.extend([audio4[0]["index"]])
try:
bitrate = int(audio4[0]["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio4[0]["channels"])
except:
channels = 0
bitrate = int(audio4[0].get("bit_rate", 0)) / 1000
channels = int(audio4[0].get("channels", 0))
audio_cmd2.extend(['-c:a:' + str(used_audio), 'copy'])
elif audio1: # right language wrong codec.
map_cmd.extend(['-map', '0:' + str(audio1[0]["index"])])
a_mapped.extend([audio1[0]["index"]])
try:
bitrate = int(audio1[0]["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio1[0]["channels"])
except:
channels = 0
bitrate = int(audio1[0].get("bit_rate", 0)) / 1000
channels = int(audio1[0].get("channels", 0))
if core.ACODEC2:
audio_cmd2.extend(['-c:a:' + str(used_audio), core.ACODEC2])
else:
@ -358,14 +319,8 @@ def buildCommands(file, newDir, movieName, bitbucket):
elif audio3: # just pick the default audio track
map_cmd.extend(['-map', '0:' + str(audio3[0]["index"])])
a_mapped.extend([audio3[0]["index"]])
try:
bitrate = int(audio3[0]["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio3[0]["channels"])
except:
channels = 0
bitrate = int(audio3[0].get("bit_rate", 0)) / 1000
channels = int(audio3[0].get("channels", 0))
if core.ACODEC2:
audio_cmd2.extend(['-c:a:' + str(used_audio), core.ACODEC2])
else:
@ -394,14 +349,8 @@ def buildCommands(file, newDir, movieName, bitbucket):
used_audio += 1
map_cmd.extend(['-map', '0:' + str(audio["index"])])
audio_cmd3 = []
try:
bitrate = int(audio["bit_rate"]) / 1000
except:
bitrate = 0
try:
channels = int(audio["channels"])
except:
channels = 0
bitrate = int(audio.get("bit_rate", 0)) / 1000
channels = int(audio.get("channels", 0))
if audio["codec_name"] in core.ACODEC3_ALLOW:
audio_cmd3.extend(['-c:a:' + str(used_audio), 'copy'])
else:
@ -540,10 +489,7 @@ def extract_subs(file, newfilePath, bitbucket):
for n in range(num):
sub = subStreams[n]
idx = sub["index"]
try:
lan = sub["tags"]["language"]
except:
lan = "unk"
lan = sub.geet("tags", {}).get("language", "unk")
if num == 1:
outputFile = os.path.join(subdir, "{0}.srt".format(name))