From 345a24f89647e081115f82e30fb08c78a1e9323f Mon Sep 17 00:00:00 2001 From: croneter Date: Thu, 28 Sep 2017 14:13:00 +0200 Subject: [PATCH] Fix subtitle languages showing up as unknown - Fixes #342 --- resources/lib/PlexAPI.py | 8 ++++-- resources/lib/variables.py | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index 8de6fbcf..561a68c0 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -2369,11 +2369,15 @@ class API(): # ext = stream.attrib.get('format') if key: # We do know the language - temporarily download - if stream.attrib.get('language') is not None: + if stream.attrib.get('languageCode') is not None: + try: + language = v.LANGUAGECODE_TO_LANGUAGE[stream.attrib['languageCode']] + except KeyError: + language = stream.attrib['languageCode'] path = self.download_external_subtitles( "{server}%s" % key, "subtitle%02d.%s.%s" % (fileindex, - stream.attrib['language'], + language, stream.attrib['codec'])) fileindex += 1 # We don't know the language - no need to download diff --git a/resources/lib/variables.py b/resources/lib/variables.py index 856197d3..5e8b6b43 100644 --- a/resources/lib/variables.py +++ b/resources/lib/variables.py @@ -21,8 +21,66 @@ def tryDecode(string, encoding='utf-8'): string = string.decode() return string +# When does Plex mark a video as completely played? MARK_PLAYED_AT = 0.9 +# Matching table for using Plex XML's stream 'languageCode' +LANGUAGECODE_TO_LANGUAGE = { + 'afr': 'Afrikaans', + 'ara': 'Arabic', + 'hye': 'Armenian', + 'bul': 'Bulgarian', + 'cat': 'Catala', + 'chi': 'Mandarin', + 'hrv': 'Hrvatski', + 'cze': 'Cesky', + 'dan': 'Dansk', + 'dut': 'Nederlands', + 'eng': 'English', + 'epo': 'Esperanto', + 'fin': 'Suomi', + 'fre': 'Francais', + 'ger': 'Deutsch', + 'geo': 'Georgian', + 'gre': 'Greek', + 'heb': 'Hebrew', + 'hin': 'Hindi', + 'hun': 'Magyar', + 'ind': 'Bahasa Indonesia', + 'gle': 'Gaeilge', + 'ice': 'Islenska', + 'ita': 'Italiano', + 'jpn': 'Japanese', + 'kor': 'Korean', + 'kur': 'Kurdi', + 'lat': 'Latin', + 'mac': 'Macedonian', + 'may': 'Malay', + 'mlt': 'Malti', + 'nep': 'Nepali', + 'nor': 'Norsk', + 'per': 'Persian', + 'pol': 'Polszczyzna', + 'por': 'Portugues', + 'rum': 'Romana', + 'rus': 'Russian', + 'srp': 'Serbian', + 'gla': 'Gaidhlig', + 'slo': 'Slovencina', + 'slv': 'Slovenski Jezik', + 'spa': 'Espanol', + 'swe': 'Svenska', + 'tam': 'Tamil', + 'tha': 'Thai', + 'tur': 'Turkish', + 'tah': 'Tahitian', + 'ukr': 'Ukrainian', + 'uzb': 'Ozbek', + 'vie': 'Tieng Viet', + 'wel': 'Cymraeg', + 'yid': 'Yiddish', +} + _ADDON = Addon() ADDON_NAME = 'PlexKodiConnect' ADDON_ID = 'plugin.video.plexkodiconnect'