movie.py: minor refactoring

This commit is contained in:
rolux 2012-08-20 20:16:36 +02:00
parent 73fa8fbecc
commit c1a2bd4d3d

View file

@ -220,23 +220,20 @@ def parse_paths(paths):
versions = sorted(version_files.keys()) versions = sorted(version_files.keys())
for version in versions: for version in versions:
data[version] = {'isMainVersion': False, 'files': [], 'videoExtensions': [], 'subtitleLanguages': []} data[version] = {'isMainVersion': False, 'files': [], 'videoExtensions': [], 'subtitleLanguages': []}
parts = sorted(list(set([ parts = sorted(list(set([file['part'] for file in version_files[version]])))
file['part'] for file in version_files[version]
])))
# videoExtensions # videoExtensions
extensions = sorted(list(set([ for extension in sorted(
file['extension'] for file in version_files[version] if file['type'] == 'video' list(set([file['extension'] for file in version_files[version] if file['type'] == 'video']))
]))) ):
for extension in extensions:
if len([ if len([
file for file in version_files[version] if file['extension'] == extension file for file in version_files[version] if file['extension'] == extension
]) >= len(parts): ]) >= len(parts):
data[version]['videoExtensions'].append(extension) data[version]['videoExtensions'].append(extension)
# subtitleLanguages # subtitleLanguages
languages = sorted(list(set([ for language in sorted(
file['language'] for file in version_files[version] if file['extension'] == 'srt' list(set([file['language'] for file in version_files[version] if file['extension'] == 'srt'])),
]))) key=lambda x: LANGUAGES.index(x) if x in LANGUAGES else x
for language in sorted(languages, key=lambda x: LANGUAGES.index(x) if x in LANGUAGES else x): ):
if len([ if len([
file for file in version_files[version] if file['extension'] == 'srt' and file['language'] == language file for file in version_files[version] if file['extension'] == 'srt' and file['language'] == language
]) >= len(parts): ]) >= len(parts):
@ -250,8 +247,8 @@ def parse_paths(paths):
subtitles = [ subtitles = [
file for file in files_by_part if file['extension'] == 'srt' and file['language'] == data[version]['subtitleLanguages'][0] file for file in files_by_part if file['extension'] == 'srt' and file['language'] == data[version]['subtitleLanguages'][0]
] if data[version]['subtitleLanguages'] else [] ] if data[version]['subtitleLanguages'] else []
for i, file in enumerate(files_by_part): for file in files_by_part:
files_by_part[i]['isMainFile'] = ( file['isMainFile'] = (
len(videos) > 0 and file['path'] == videos[0]['path'] len(videos) > 0 and file['path'] == videos[0]['path']
) or ( ) or (
len(subtitles) > 0 and file['path'] == subtitles[0]['path'] len(subtitles) > 0 and file['path'] == subtitles[0]['path']