Fixed exception thrown when Radarr (and potentially Sonarr) return a null audio or video codec for a movie. #1657

This commit is contained in:
morpheus65535 2022-01-01 16:41:00 -05:00
parent d8f14560e3
commit e239fc2826
2 changed files with 96 additions and 71 deletions

View File

@ -217,43 +217,49 @@ def sync_one_episode(episode_id):
def SonarrFormatAudioCodec(audio_codec):
if audio_codec == 'AC-3':
return 'AC3'
if audio_codec == 'E-AC-3':
return 'EAC3'
if audio_codec == 'MPEG Audio':
return 'MP3'
return audio_codec
if type(audio_codec) is not str:
return audio_codec
else:
if audio_codec == 'AC-3':
return 'AC3'
elif audio_codec == 'E-AC-3':
return 'EAC3'
elif audio_codec == 'MPEG Audio':
return 'MP3'
else:
return audio_codec
def SonarrFormatVideoCodec(video_codec):
if video_codec == 'x264' or video_codec == 'AVC':
return 'h264'
elif video_codec == 'x265' or video_codec == 'HEVC':
return 'h265'
elif video_codec.startswith('XviD'):
return 'XviD'
elif video_codec.startswith('DivX'):
return 'DivX'
elif video_codec == 'MPEG-1 Video':
return 'Mpeg'
elif video_codec == 'MPEG-2 Video':
return 'Mpeg2'
elif video_codec == 'MPEG-4 Video':
return 'Mpeg4'
elif video_codec == 'VC-1':
return 'VC1'
elif video_codec.endswith('VP6'):
return 'VP6'
elif video_codec.endswith('VP7'):
return 'VP7'
elif video_codec.endswith('VP8'):
return 'VP8'
elif video_codec.endswith('VP9'):
return 'VP9'
else:
if type(video_codec) is not str:
return video_codec
else:
if video_codec == 'x264' or video_codec == 'AVC':
return 'h264'
elif video_codec == 'x265' or video_codec == 'HEVC':
return 'h265'
elif video_codec.startswith('XviD'):
return 'XviD'
elif video_codec.startswith('DivX'):
return 'DivX'
elif video_codec == 'MPEG-1 Video':
return 'Mpeg'
elif video_codec == 'MPEG-2 Video':
return 'Mpeg2'
elif video_codec == 'MPEG-4 Video':
return 'Mpeg4'
elif video_codec == 'VC-1':
return 'VC1'
elif video_codec.endswith('VP6'):
return 'VP6'
elif video_codec.endswith('VP7'):
return 'VP7'
elif video_codec.endswith('VP8'):
return 'VP8'
elif video_codec.endswith('VP9'):
return 'VP9'
else:
return video_codec
def episodeParser(episode):

View File

@ -282,49 +282,68 @@ def profile_id_to_language(id, profiles):
def RadarrFormatAudioCodec(audioFormat, audioCodecID, audioProfile, audioAdditionalFeatures):
if audioFormat == "AC-3": return "AC3"
if audioFormat == "E-AC-3": return "EAC3"
if audioFormat == "AAC":
if audioCodecID == "A_AAC/MPEG4/LC/SBR":
return "HE-AAC"
if type(audioFormat) is not str:
return audioFormat
else:
if audioFormat == "AC-3":
return "AC3"
elif audioFormat == "E-AC-3":
return "EAC3"
elif audioFormat == "AAC":
if audioCodecID == "A_AAC/MPEG4/LC/SBR":
return "HE-AAC"
else:
return "AAC"
elif audioFormat.strip() == "mp3":
return "MP3"
elif audioFormat == "MPEG Audio":
if audioCodecID == "55" or audioCodecID == "A_MPEG/L3" or audioProfile == "Layer 3":
return "MP3"
if audioCodecID == "A_MPEG/L2" or audioProfile == "Layer 2":
return "MP2"
elif audioFormat == "MLP FBA":
if audioAdditionalFeatures == "16-ch":
return "TrueHD Atmos"
else:
return "TrueHD"
else:
return "AAC"
if audioFormat.strip() == "mp3": return "MP3"
if audioFormat == "MPEG Audio":
if audioCodecID == "55" or audioCodecID == "A_MPEG/L3" or audioProfile == "Layer 3": return "MP3"
if audioCodecID == "A_MPEG/L2" or audioProfile == "Layer 2": return "MP2"
if audioFormat == "MLP FBA":
if audioAdditionalFeatures == "16-ch":
return "TrueHD Atmos"
else:
return "TrueHD"
return audioFormat
return audioFormat
def RadarrFormatVideoCodec(videoFormat, videoCodecID, videoCodecLibrary):
if videoFormat == "x264": return "h264"
if videoFormat == "AVC" or videoFormat == "V.MPEG4/ISO/AVC": return "h264"
if videoCodecLibrary and (videoFormat == "HEVC" or videoFormat == "V_MPEGH/ISO/HEVC"):
if videoCodecLibrary.startswith("x265"): return "h265"
if videoCodecID and videoFormat == "MPEG Video":
if videoCodecID == "2" or videoCodecID == "V_MPEG2":
return "Mpeg2"
else:
if type(videoFormat) is not str:
return videoFormat
else:
if videoFormat == "x264":
return "h264"
elif videoFormat == "AVC" or videoFormat == "V.MPEG4/ISO/AVC":
return "h264"
elif videoCodecLibrary and (videoFormat == "HEVC" or videoFormat == "V_MPEGH/ISO/HEVC"):
if videoCodecLibrary.startswith("x265"):
return "h265"
elif videoCodecID and videoFormat == "MPEG Video":
if videoCodecID == "2" or videoCodecID == "V_MPEG2":
return "Mpeg2"
else:
return "Mpeg"
elif videoFormat == "MPEG-1 Video":
return "Mpeg"
if videoFormat == "MPEG-1 Video": return "Mpeg"
if videoFormat == "MPEG-2 Video": return "Mpeg2"
if videoCodecLibrary and videoCodecID and videoFormat == "MPEG-4 Visual":
if videoCodecID.endswith("XVID") or videoCodecLibrary.startswith("XviD"): return "XviD"
if videoCodecID.endswith("DIV3") or videoCodecID.endswith("DIVX") or videoCodecID.endswith(
"DX50") or videoCodecLibrary.startswith("DivX"): return "DivX"
if videoFormat == "VC-1": return "VC1"
if videoFormat == "WMV2":
return "WMV"
if videoFormat == "DivX" or videoFormat == "div3":
return "DivX"
return videoFormat
elif videoFormat == "MPEG-2 Video":
return "Mpeg2"
elif videoCodecLibrary and videoCodecID and videoFormat == "MPEG-4 Visual":
if videoCodecID.endswith("XVID") or videoCodecLibrary.startswith("XviD"):
return "XviD"
if videoCodecID.endswith("DIV3") or videoCodecID.endswith("DIVX") or videoCodecID.endswith(
"DX50") or videoCodecLibrary.startswith("DivX"):
return "DivX"
elif videoFormat == "VC-1":
return "VC1"
elif videoFormat == "WMV2":
return "WMV"
elif videoFormat == "DivX" or videoFormat == "div3":
return "DivX"
else:
return videoFormat
def get_tags():