Skip to content

Commit

Permalink
(Fix) new language format remove parenthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
werrpy committed Jan 12, 2023
1 parent 04d13d4 commit 92d072b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions vdator/checks/text_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .mixins import IsCommentaryTrack, SectionId

from collections import OrderedDict
import re


class CheckTextOrder(Check, IsCommentaryTrack, SectionId):
Expand All @@ -27,7 +28,9 @@ def get_reply(self):
return reply

# text_langs = ['German', 'English', ...]
text_langs = [text["language"] for text in self.mediainfo["text"]]
text_langs = [
self._format_lang(text["language"]) for text in self.mediainfo["text"]
]
# remove duplicates from list and preserve order
text_langs = list(dict.fromkeys(text_langs))

Expand All @@ -45,10 +48,12 @@ def get_reply(self):
for i, text in enumerate(self.mediainfo["text"]):
text["title"] = text["title"] if "title" in text else ""
if self._is_commentary_track(text["title"]):
commentary_tracks_by_lang[text["language"]].append(text)
commentary_tracks_by_lang[self._format_lang(text["language"])].append(
text
)
has_commentary = True
else:
text_tracks_by_lang[text["language"]].append(text)
text_tracks_by_lang[self._format_lang(text["language"])].append(text)
# forced english track should be first
reply += self._forced_english_track_first(i, text)

Expand Down Expand Up @@ -77,6 +82,13 @@ def get_reply(self):

return reply

def _format_lang(self, lang):
"""
Format a text language to remove parenthesis
English (US) becomes English
"""
return re.sub(r"\([^)]*\)", "", lang).strip()

def _forced_english_track_first(self, i, text_track):
"""
Forced english track should be first
Expand Down

0 comments on commit 92d072b

Please sign in to comment.