- results = []
- for result in ie_results or []:
- result_type = result.get('_type', 'video') #If not given we suppose it's a video, support the dafault old system
- if result_type == 'video':
- if not 'extractor' in result:
- #The extractor has already been set somewhere else
- result['extractor'] = ie.IE_NAME
- results.append(result)
- elif result_type == 'url':
- #We get the videos pointed by the url
- results.extend(self.extract_info(result['url']))
- elif result_type == 'playlist':
- #We process each entry in the playlist
- entries_result = self.process_ie_results(result['entries'], ie)
- result['entries'] = entries_result
- results.extend([result])
- return results
+ result_type = ie_result.get('_type', 'video') #If not given we suppose it's a video, support the dafault old system
+ if result_type == 'video':
+ if 'playlist' not in ie_result:
+ #It isn't part of a playlist
+ ie_result['playlist'] = None
+ if download:
+ #Do the download:
+ self.process_info(ie_result)
+ return ie_result
+ elif result_type == 'url':
+ #We get the video pointed by the url
+ result = self.extract_info(ie_result['url'], download)[0]
+ return result
+ elif result_type == 'playlist':
+ #We process each entry in the playlist
+ playlist = ie_result.get('title', None) or ie_result.get('id', None)
+ self.to_screen(u'[download] Downloading playlist: %s' % playlist)
+ n_videos = len(ie_result['entries'])
+ playlist_results = []
+ for i,entry in enumerate(ie_result['entries'],1):
+ self.to_screen(u'[download] Downloading video #%s of %s' %(i, n_videos))
+ entry_result = self.process_ie_result(entry, False)
+ entry_result['playlist'] = playlist
+ #We must do the download here to correctly set the 'playlist' key
+ if download:
+ self.process_info(entry_result)
+ playlist_results.append(entry_result)
+ result = ie_result.copy()
+ result['entries'] = playlist_results
+ return result