From 4887066000a461d2026e95ba8d493bd667d9bfb2 Mon Sep 17 00:00:00 2001 From: Anderson Shindy Oki Date: Sun, 25 Aug 2024 22:46:57 +0900 Subject: Fixed chinese audio language (#2632) --- bazarr/languages/get_languages.py | 7 +++++++ bazarr/radarr/sync/parser.py | 6 ++---- bazarr/sonarr/sync/parser.py | 5 +++-- frontend/src/components/bazarr/AudioList.tsx | 3 ++- frontend/src/pages/views/ItemOverview.tsx | 3 ++- frontend/src/utilities/languages.ts | 4 ++++ 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/bazarr/languages/get_languages.py b/bazarr/languages/get_languages.py index 2fbd52c89..881dd6ce0 100644 --- a/bazarr/languages/get_languages.py +++ b/bazarr/languages/get_languages.py @@ -54,6 +54,13 @@ def create_languages_dict(): TableSettingsLanguages.code3b)) .all()] +def audio_language_from_alpha2(lang): + lang_map = { + 'Chinese': 'zh', + 'Portuguese (Brazil)': 'pb' + } + + return language_from_alpha2(lang_map.get(lang, lang)) def language_from_alpha2(lang): return next((item['name'] for item in languages_dict if item['code2'] == lang[:2]), None) diff --git a/bazarr/radarr/sync/parser.py b/bazarr/radarr/sync/parser.py index d5f3e08c8..11b2a6687 100644 --- a/bazarr/radarr/sync/parser.py +++ b/bazarr/radarr/sync/parser.py @@ -3,7 +3,7 @@ import os from app.config import settings -from languages.get_languages import language_from_alpha2 +from languages.get_languages import audio_language_from_alpha2 from radarr.info import get_radarr_info from utilities.video_analyzer import embedded_audio_reader from utilities.path_mappings import path_mappings @@ -117,9 +117,7 @@ def movieParser(movie, action, tags_dict, language_profiles, movie_default_profi for item in movie['movieFile']['languages']: if isinstance(item, dict): if 'name' in item: - language = item['name'] - if item['name'] == 'Portuguese (Brazil)': - language = language_from_alpha2('pb') + language = audio_language_from_alpha2(item['name']) audio_language.append(language) tags = [d['label'] for d in tags_dict if d['id'] in movie['tags']] diff --git a/bazarr/sonarr/sync/parser.py b/bazarr/sonarr/sync/parser.py index 32980cbab..24c92c575 100644 --- a/bazarr/sonarr/sync/parser.py +++ b/bazarr/sonarr/sync/parser.py @@ -5,6 +5,7 @@ import os from app.config import settings from app.database import TableShows, database, select from constants import MINIMUM_VIDEO_SIZE +from languages.get_languages import audio_language_from_alpha2 from utilities.path_mappings import path_mappings from utilities.video_analyzer import embedded_audio_reader from sonarr.info import get_sonarr_info @@ -115,13 +116,13 @@ def episodeParser(episode): item = episode['episodeFile']['language'] if isinstance(item, dict): if 'name' in item: - audio_language.append(item['name']) + audio_language.append(audio_language_from_alpha2(item['name'])) elif 'languages' in episode['episodeFile'] and len(episode['episodeFile']['languages']): items = episode['episodeFile']['languages'] if isinstance(items, list): for item in items: if 'name' in item: - audio_language.append(item['name']) + audio_language.append(audio_language_from_alpha2(item['name'])) else: audio_language = database.execute( select(TableShows.audio_language) diff --git a/frontend/src/components/bazarr/AudioList.tsx b/frontend/src/components/bazarr/AudioList.tsx index f1af7ff3c..f0dc07c0d 100644 --- a/frontend/src/components/bazarr/AudioList.tsx +++ b/frontend/src/components/bazarr/AudioList.tsx @@ -1,6 +1,7 @@ import { FunctionComponent } from "react"; import { Badge, BadgeProps, Group, GroupProps } from "@mantine/core"; import { BuildKey } from "@/utilities"; +import { normalizeAudioLanguage } from "@/utilities/languages"; export type AudioListProps = GroupProps & { audios: Language.Info[]; @@ -16,7 +17,7 @@ const AudioList: FunctionComponent = ({ {audios.map((audio, idx) => ( - {audio.name} + {normalizeAudioLanguage(audio.name)} ))} diff --git a/frontend/src/pages/views/ItemOverview.tsx b/frontend/src/pages/views/ItemOverview.tsx index d03da3b80..36d296850 100644 --- a/frontend/src/pages/views/ItemOverview.tsx +++ b/frontend/src/pages/views/ItemOverview.tsx @@ -31,6 +31,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Language } from "@/components/bazarr"; import { BuildKey } from "@/utilities"; import { + normalizeAudioLanguage, useLanguageProfileBy, useProfileItemsToLanguages, } from "@/utilities/languages"; @@ -87,7 +88,7 @@ const ItemOverview: FunctionComponent = (props) => { icon={faMusic} title="Audio Language" > - {v.name} + {normalizeAudioLanguage(v.name)} )) ?? [], [item?.audio_language], diff --git a/frontend/src/utilities/languages.ts b/frontend/src/utilities/languages.ts index 1b59aa4e7..7885e9667 100644 --- a/frontend/src/utilities/languages.ts +++ b/frontend/src/utilities/languages.ts @@ -51,3 +51,7 @@ export function useLanguageFromCode3(code3: string) { [data, code3], ); } + +export const normalizeAudioLanguage = (name: string) => { + return name === "Chinese Simplified" ? "Chinese" : name; +}; -- cgit v1.2.3