filter/map return generators in py3, wrap in list

This commit is contained in:
j 2015-03-07 23:46:59 +05:30
parent dc6f25aac1
commit 7f7b0c3ee8

View file

@ -29,7 +29,7 @@ def format_path(data, directory_key='director'):
director = data['directorSort'] or ['Unknown Director'] director = data['directorSort'] or ['Unknown Director']
title = data['seriesTitle' if data['isEpisode'] else 'title'] or 'Untitled' title = data['seriesTitle' if data['isEpisode'] else 'title'] or 'Untitled'
year = data['seriesYear' if data['isEpisode'] else 'year'] or None year = data['seriesYear' if data['isEpisode'] else 'year'] or None
parts = map(format_underscores, filter(lambda x: x != None, [ parts = list(map(format_underscores, filter(lambda x: x != None, [
u'; '.join(director[:10]), u'; '.join(director[:10]),
u'%s%s' % (title, u' (%s)' % year if year else ''), u'%s%s' % (title, u' (%s)' % year if year else ''),
u'%s%s%s%s%s%s' % ( u'%s%s%s%s%s%s' % (
@ -40,7 +40,7 @@ def format_path(data, directory_key='director'):
u'.%s' % data['language'] if data['language'] else '', u'.%s' % data['language'] if data['language'] else '',
u'.%s' % data['extension'] if data['extension'] else '' u'.%s' % data['extension'] if data['extension'] else ''
) )
])) ])))
if data.get('subdirectory'): if data.get('subdirectory'):
parts.insert(-1, data['subdirectory']) parts.insert(-1, data['subdirectory'])
return unicodedata.normalize('NFD', u'/'.join(parts)) return unicodedata.normalize('NFD', u'/'.join(parts))
@ -208,7 +208,7 @@ def parse_path(path, directory_key='director'):
string = re.sub('(?<=\w)_ ', ': ', string) string = re.sub('(?<=\w)_ ', ': ', string)
return string return string
data = {} data = {}
parts = map(lambda x: parse_underscores(x.strip()), unicodedata.normalize('NFD', path).split('/')) parts = list(map(lambda x: parse_underscores(x.strip()), unicodedata.normalize('NFD', path).split('/')))
# subdirectory # subdirectory
if len(parts) > 4: if len(parts) > 4:
data['subdirectory'] = '/'.join(parts[3:-1]) data['subdirectory'] = '/'.join(parts[3:-1])
@ -224,14 +224,14 @@ def parse_path(path, directory_key='director'):
# directorSort, director # directorSort, director
data['directorSort'] = data['director'] = [] data['directorSort'] = data['director'] = []
if director: if director:
data['directorSort'] = filter( data['directorSort'] = list(filter(
lambda x: x != 'Unknown Director', lambda x: x != 'Unknown Director',
director.split('; ') director.split('; ')
) ))
data['director'] = map( data['director'] = list(map(
lambda x: ' '.join(reversed(x.split(', '))), lambda x: ' '.join(reversed(x.split(', '))),
data['directorSort'] data['directorSort']
) ))
# title, year # title, year
data['title'] = data['year'] = None data['title'] = data['year'] = None
if title: if title: