Skip to content

Commit e0780dd

Browse files
committed
Use list comprehensions everywhere
Instead of map and filter, use list comprehensions.
1 parent 153c008 commit e0780dd

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

download_trailers.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def get_trailer_file_urls(page_url, res, types, download_all_urls):
7676
apple_size = map_res_to_apple_size(res)
7777

7878
# Remove beginning, end, and duplicate whitespace from titles
79-
all_video_types = list(map(lambda c: ' '.join(c['title'].split()),
80-
film_data['clips']))
79+
all_video_types = [' '.join(c['title'].split()) for c
80+
in film_data['clips']]
8181
download_types = get_download_types(types, all_video_types)
8282

8383
# The user wants all videos from this movie regardless of the video_types
@@ -91,14 +91,12 @@ def get_trailer_file_urls(page_url, res, types, download_all_urls):
9191
if video_type in download_types or download_all:
9292
if apple_size in clip['versions']['enus']['sizes']:
9393
file_info = clip['versions']['enus']['sizes'][apple_size]
94-
url_info = {
94+
urls.append({
9595
'res': res,
9696
'title': title,
9797
'type': video_type,
9898
'url': convert_src_url_to_file_url(file_info['src'], res),
99-
}
100-
101-
urls.append(url_info)
99+
})
102100
else:
103101
logging.error('*** No %sp file found for %s', res, video_type)
104102

@@ -131,10 +129,10 @@ def get_download_types(requested_types, all_video_types):
131129
requested_types = requested_types.lower()
132130

133131
# Normalize whitespace
134-
video_types = list(map(lambda t: ' '.join(t.split()), all_video_types))
132+
video_types = [' '.join(t.split()) for t in all_video_types]
135133

136134
# Remove types that were empty or only whitespace
137-
video_types = list(filter(lambda t: t, video_types))
135+
video_types = [t for t in video_types if t]
138136

139137
# Remove duplicates
140138
video_types = list(set(video_types))
@@ -146,16 +144,15 @@ def get_download_types(requested_types, all_video_types):
146144
download_types = video_types
147145

148146
elif requested_types == 'single_trailer':
149-
video_types = list(filter(lambda t: t.lower().startswith('trailer'),
150-
video_types))
147+
video_types = [t for t in video_types
148+
if t.lower().startswith('trailer')]
151149
download_types = video_types[0:1]
152150

153151
elif requested_types == 'trailers':
154-
download_types = list(filter(lambda t:
155-
t.lower().startswith('trailer')
156-
or t.lower().startswith('teaser')
157-
or t.lower() == 'first look',
158-
video_types))
152+
download_types = [t for t in video_types
153+
if t.lower().startswith('trailer')
154+
or t.lower().startswith('teaser')
155+
or t.lower() == 'first look']
159156

160157
return download_types
161158

0 commit comments

Comments
 (0)