From 585c70c39d8ae1e3b9b82fae8800417eba5f6444 Mon Sep 17 00:00:00 2001 From: Vitiko Date: Fri, 19 May 2023 02:03:17 -0400 Subject: [PATCH] Add support for custom languages in audio tracks --- bazarr/utilities/video_analyzer.py | 5 +- tests/bazarr/test_utilities_video_analyzer.py | 72 ++++++++++++------- 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/bazarr/utilities/video_analyzer.py b/bazarr/utilities/video_analyzer.py index 89bc48ff0..2b221fde1 100644 --- a/bazarr/utilities/video_analyzer.py +++ b/bazarr/utilities/video_analyzer.py @@ -81,7 +81,7 @@ def embedded_audio_reader(file, file_size, episode_file_id=None, movie_file_id=N return audio_list cache_provider = None - if data["ffprobe"] and "audio" in data["ffprobe"]: + if "ffprobe" in data and data["ffprobe"] and "audio" in data["ffprobe"]: cache_provider = 'ffprobe' elif 'mediainfo' in data and data["mediainfo"] and "audio" in data["mediainfo"]: cache_provider = 'mediainfo' @@ -92,7 +92,8 @@ def embedded_audio_reader(file, file_size, episode_file_id=None, movie_file_id=N audio_list.append(None) continue - language = language_from_alpha3(detected_language["language"].alpha3) + alpha3 = _handle_alpha3(detected_language) + language = language_from_alpha3(alpha3) if language not in audio_list: audio_list.append(language) diff --git a/tests/bazarr/test_utilities_video_analyzer.py b/tests/bazarr/test_utilities_video_analyzer.py index 893415e13..9a6eb21f0 100644 --- a/tests/bazarr/test_utilities_video_analyzer.py +++ b/tests/bazarr/test_utilities_video_analyzer.py @@ -55,34 +55,40 @@ M_INFO = { "BitRate_Maximum": "12749952", "Width": "1920", "Height": "1080", - "Stored_Height": "1088", - "Sampled_Width": "1920", - "Sampled_Height": "1080", - "PixelAspectRatio": "1.000", - "DisplayAspectRatio": "1.778", - "FrameRate_Mode": "CFR", - "FrameRate": "23.976", - "FrameCount": "138251", - "ColorSpace": "YUV", - "ChromaSubsampling": "4:2:0", - "BitDepth": "8", - "ScanType": "Progressive", - "Delay": "0.000", - "Delay_Source": "Container", - "StreamSize": "6096863666", - "Default": "Yes", + }, + { + "@type": "Audio", + "@typeorder": "1", + "StreamOrder": "1", + "ID": "2", + "UniqueID": "12329215851643269509", + "Format": "E-AC-3", + "Format_Commercial_IfAny": "Dolby Digital Plus", + "Format_Settings_Endianness": "Big", + "CodecID": "A_EAC3", + "Duration": "5766.112000000", + "BitRate_Mode": "CBR", + "BitRate": "256000", + "Language": "pt-BR", + "Default": "No", + "Forced": "No", + }, + { + "@type": "Audio", + "@typeorder": "2", + "StreamOrder": "2", + "ID": "3", + "UniqueID": "1232921585164326950923", + "Format": "E-AC-3", + "Format_Commercial_IfAny": "Dolby Digital Plus", + "Format_Settings_Endianness": "Big", + "CodecID": "A_EAC3", + "Duration": "5766.112000000", + "BitRate_Mode": "CBR", + "BitRate": "256000", + "Language": "pt", + "Default": "No", "Forced": "No", - "BufferSize": "17000000", - "colour_description_present": "Yes", - "colour_description_present_Source": "Container / Stream", - "colour_range": "Limited", - "colour_range_Source": "Stream", - "colour_primaries": "BT.709", - "colour_primaries_Source": "Container / Stream", - "transfer_characteristics": "BT.709", - "transfer_characteristics_Source": "Container / Stream", - "matrix_coefficients": "BT.709", - "matrix_coefficients_Source": "Container / Stream", }, { "@type": "Text", @@ -227,3 +233,15 @@ def test_embedded_subs_reader(mocker, mediainfo_data, video_file): assert ["spl", False, False, "SubRip"] in result assert ["pob", False, False, "SubRip"] in result assert ["zht", False, False, "SubRip"] in result + + +def test_embedded_audio_reader(mocker, mediainfo_data, video_file): + mocker.patch( + "bazarr.utilities.video_analyzer.parse_video_metadata", + return_value={"mediainfo": mediainfo_data}, + ) + mocker.patch( + "bazarr.utilities.video_analyzer.language_from_alpha3", lambda alpha3: alpha3 + ) + result = video_analyzer.embedded_audio_reader(1e6, video_file) + assert {"pob", "por"} == set(result)