py3 sort fixes

This commit is contained in:
j 2017-02-18 13:01:33 +01:00
parent ac55ef0fbd
commit 6475bb8120

View file

@ -70,7 +70,7 @@ def parse_item_files(files):
duplicate_files = []
for key in [get_file_key(file) for file in files]:
key_files = sorted(
sorted([file for file in files if get_file_key(file) == key]),
[file for file in files if get_file_key(file) == key],
key=lambda x: len(x['path'])
)
unique_files.append(key_files[0])
@ -114,10 +114,8 @@ def parse_item_files(files):
# determine preferred subtitle language
language[version_key] = None
subtitle_files = [file for file in version_files[version_key] if file['extension'] == 'srt']
for subtitle_language in sorted(
list(set([file['language'] for file in subtitle_files])),
key=lambda x: '%d' % LANGUAGES.index(x) if x in LANGUAGES else x
):
subtitle_languages = list(set([file['language'] for file in subtitle_files]))
for subtitle_language in sorted(subtitle_languages, key=subtitle_sort):
language_files = [file for file in subtitle_files if file['language'] == subtitle_language]
if len(subtitle_files) == len(parts):
language[version_key] = subtitle_language
@ -487,3 +485,11 @@ def get_oxid(title, director=[], year='',
oxid = get_hash('\n'.join([director, title, str(year), str(season)]))[:8] + \
get_hash('\n'.join([str(episode), episode_director, episode_title, str(episode_year)]))[:8]
return u'0x' + oxid
def subtitle_sort(language):
if language in LANGUAGES:
return str(LANGUAGES.index(language))
elif language is None:
return str(len(LANGUAGES))
else:
return language