From 4f9f7bc7c98a97139e136c8d21c6d98750039209 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 19 Sep 2020 15:21:02 +0200 Subject: [PATCH] Fix playback failing due to caching of subtitles with non-ascii chars --- resources/lib/plex_api/media.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/resources/lib/plex_api/media.py b/resources/lib/plex_api/media.py index 60353d7c..e6eb7a59 100644 --- a/resources/lib/plex_api/media.py +++ b/resources/lib/plex_api/media.py @@ -261,10 +261,19 @@ class Media(object): if int(stream.get('streamType')) != 3 or 'key' not in stream.attrib: # Not a subtitle or not not an external subtitle continue - path = self.download_external_subtitles( - '{server}%s' % stream.get('key'), - stream.get('displayTitle'), - stream.get('codec')) + try: + path = self.download_external_subtitles( + '{server}%s' % stream.get('key'), + stream.get('displayTitle'), + stream.get('codec')) + except IOError: + # Catch "IOError: [Errno 22] invalid mode ('wb') or filename" + # Due to stream.get('displayTitle') returning chars that our + # OS is not supporting, e.g. "српски језик (SRT External)" + path = self.download_external_subtitles( + '{server}%s' % stream.get('key'), + stream.get('languageCode', 'Unknown'), + stream.get('codec')) if path: externalsubs.append(path) LOG.info('Found external subs: %s', externalsubs)