get_transcripts now returns a list of exceptions instead of video ids of failed videos
This commit is contained in:
		
							parent
							
								
									66d02c08a1
								
							
						
					
					
						commit
						4b75a47a74
					
				|  | @ -72,11 +72,11 @@ class YouTubeTranscriptApi(): | |||
|         :param proxies: a dictionary mapping of http and https proxies to be used for the network requests | ||||
|         :type proxies: {'http': str, 'https': str} - http://docs.python-requests.org/en/master/user/advanced/#proxies | ||||
|         :return: a tuple containing a dictionary mapping video ids onto their corresponding transcripts, and a list of | ||||
|         video ids, which could not be retrieved | ||||
|         :rtype ({str: [{'text': str, 'start': float, 'end': float}]}, [str]}): | ||||
|         exceptions which occurred for the videos which could not be retrieved | ||||
|         :rtype ({str: [{'text': str, 'start': float, 'end': float}]}, [CouldNotRetrieveTranscript]}): | ||||
|         """ | ||||
|         data = {} | ||||
|         unretrievable_videos = [] | ||||
|         exceptions = [] | ||||
| 
 | ||||
|         for video_id in video_ids: | ||||
|             try: | ||||
|  | @ -85,9 +85,9 @@ class YouTubeTranscriptApi(): | |||
|                 if not continue_after_error: | ||||
|                     raise exception | ||||
| 
 | ||||
|                 unretrievable_videos.append(video_id) | ||||
|                 exceptions.append(exception) | ||||
| 
 | ||||
|         return data, unretrievable_videos | ||||
|         return data, exceptions | ||||
| 
 | ||||
|     @classmethod | ||||
|     def get_transcript(cls, video_id, languages=('en',), proxies=None): | ||||
|  |  | |||
|  | @ -26,7 +26,7 @@ class YouTubeTranscriptCli(): | |||
|         ) | ||||
| 
 | ||||
|         return '\n\n'.join( | ||||
|             [str(YouTubeTranscriptApi.CouldNotRetrieveTranscript(video_id)) for video_id in unretrievable_videos] | ||||
|             [str(exception) for exception in unretrievable_videos] | ||||
|             + ([json.dumps(transcripts) if parsed_args.json else pprint.pformat(transcripts)] if transcripts else []) | ||||
|         ) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue