This method resolves genre references (IDs) to genre names.
Before this change, we would iterate the list of genre (names)
and then iterate the list of genre IDs to look for matches.
The same result can be established more efficiently by iterating
the genre references followed by lookups for their associated names.
Error handling for lookup failures has been left intact from the
original implementation.
List of genres
"""
video_genres = []
List of genres
"""
video_genres = []
- for genre_key in dict(genres).keys():
- if self._is_size_key(key=genre_key) == False and genre_key != 'summary':
- for show_genre_key in dict(video['genres']).keys():
- if self._is_size_key(key=show_genre_key) == False and show_genre_key != 'summary':
- if video['genres'][show_genre_key][1] == genre_key:
- video_genres.append(genres[genre_key]['name'])
+
+ for video_genre_key, video_genre in video['genres'].iteritems():
+ if self._is_size_key(video_genre_key) == False and video_genre_key != 'summary':
+ name = genres.get(video_genre[1], {}).get('name')
+
+ if name:
+ video_genres.append(name)
+
return video_genres
def parse_tags_for_video (self, video):
return video_genres
def parse_tags_for_video (self, video):