Skip to content

Commit

Permalink
Fixed chinese audio language (#2632)
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson-oki authored Aug 25, 2024
1 parent 609349b commit 4887066
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
7 changes: 7 additions & 0 deletions bazarr/languages/get_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions bazarr/radarr/sync/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']]
Expand Down
5 changes: 3 additions & 2 deletions bazarr/sonarr/sync/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/bazarr/AudioList.tsx
Original file line number Diff line number Diff line change
@@ -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[];
Expand All @@ -16,7 +17,7 @@ const AudioList: FunctionComponent<AudioListProps> = ({
<Group gap="xs" {...group}>
{audios.map((audio, idx) => (
<Badge color="blue" key={BuildKey(idx, audio.code2)} {...badgeProps}>
{audio.name}
{normalizeAudioLanguage(audio.name)}
</Badge>
))}
</Group>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/views/ItemOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -87,7 +88,7 @@ const ItemOverview: FunctionComponent<Props> = (props) => {
icon={faMusic}
title="Audio Language"
>
{v.name}
{normalizeAudioLanguage(v.name)}
</ItemBadge>
)) ?? [],
[item?.audio_language],
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/utilities/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ export function useLanguageFromCode3(code3: string) {
[data, code3],
);
}

export const normalizeAudioLanguage = (name: string) => {
return name === "Chinese Simplified" ? "Chinese" : name;
};

0 comments on commit 4887066

Please sign in to comment.