Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions resources/lib/putio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import os
import re
import json
import logging
import binascii
Expand Down Expand Up @@ -204,23 +205,20 @@ def subtitles(self):
subtitle_directory_path = '%s/%s' % (video_directory_path, truncated_subtitle_key)
xbmcvfs.mkdirs(subtitle_directory_path)

subtitle_name = subtitle['name']
if subtitle_name.endswith('.srt'):
subtitle_name = subtitle_name[:-4]
# NOTE: split subtitle name/extension while allowing multiple dots within the name -- both as word/part separator and as ellipsis.
(subtitle_name, subtitle_ext) = os.path.splitext(subtitle['name'])
subtitle_ext = subtitle_ext.lstrip('.') if subtitle_ext != '' else None
subtitle_parts = subtitle_name.split('.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do:

subtitle_parts = [subtitle_name]
if ...:
   subtitle_parts.append(lang_code)
subtitle_parts.append(subtitle_ext)
subtitle_fullname = '.'.join(subtitle_parts)

subtitle_lang = subtitle['language_code'] if subtitle['language_code'] != 'und' else None

subtitle_lang = subtitle['language_code'] or ''
if len(subtitle_lang) not in (2, 3): # sometimes this returns wrong
subtitle_lang = 'und'

# language is unknown for folder subtitles, use last part if name ends with `.` + 2-3 chars
if subtitle['source'] == 'folder':
parts = subtitle_name.split('.')
if len(parts) > 1 and len(parts[-1]) in (2, 3):
subtitle_lang = parts[-1]

# add language even if it's also in name, this way shown name will always be the original name
subtitle_fullname = subtitle_name + '.' + subtitle_lang + '.srt'
# NOTE: append known subtitle language to subtitle name, if it is not already a (delimited) part of it
# NOTE: separators (dot, space, dash) found on kodi's wiki.
# https://kodi.wiki/view/Subtitles
if subtitle_lang != None and subtitle_lang.lower() not in re.split(r"[. -]", subtitle_name.lower()):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check only last part (if has parts).

Also, we can check subtitle['language'].

Does returning also the 2-letter code makes sense? If we do, what should it be called (without touching others) in your opinion?

subtitle_parts.append(subtitle_lang)

subtitle_parts.append(subtitle_ext)
subtitle_fullname = '.'.join(subtitle_parts)
subtitle_path = '%s/%s' % (subtitle_directory_path, subtitle_fullname)

# FIXME: Parallelize downloads.
Expand Down