Languages argument defaults to a tuple instead of a list.
This commit is contained in:
		
							parent
							
								
									c7cb3117be
								
							
						
					
					
						commit
						d224b02a80
					
				|  | @ -40,7 +40,7 @@ class YouTubeTranscriptApi(): | |||
|             self.video_id = video_id | ||||
| 
 | ||||
|     @classmethod | ||||
|     def get_transcripts(cls, video_ids, languages=['en'], continue_after_error=False, proxies=None): | ||||
|     def get_transcripts(cls, video_ids, languages=('en',), continue_after_error=False, proxies=None): | ||||
|         """ | ||||
|         Retrieves the transcripts for a list of videos. | ||||
| 
 | ||||
|  | @ -75,7 +75,7 @@ class YouTubeTranscriptApi(): | |||
|         return data, unretrievable_videos | ||||
| 
 | ||||
|     @classmethod | ||||
|     def get_transcript(cls, video_id, languages=['en'], proxies=None): | ||||
|     def get_transcript(cls, video_id, languages=('en',), proxies=None): | ||||
|         """ | ||||
|         Retrieves the transcript for a single video. | ||||
| 
 | ||||
|  | @ -106,7 +106,6 @@ class _TranscriptFetcher(): | |||
|     def __init__(self, video_id, languages, proxies): | ||||
|         self.video_id = video_id | ||||
|         self.languages = languages | ||||
|         print(languages) | ||||
|         self.proxies = proxies | ||||
| 
 | ||||
|     def fetch(self): | ||||
|  | @ -131,9 +130,16 @@ class _TranscriptFetcher(): | |||
| 
 | ||||
|         return None | ||||
| 
 | ||||
|     #Sorting the matched splits by string length because we want non-asr options returned first | ||||
|     #However, we don't want to include the length of the 'name' argument as it could possible throw this off | ||||
|     def _sort_splits(self, matched_split): | ||||
|         """Returns a value related to a given caption track url. | ||||
| 
 | ||||
|         This function is used to sort the matched splits by string  | ||||
|         length because we want non-asr and non-dialect options returned first. | ||||
|         With this in mind, it is remove the 'name' arugument from the url as  | ||||
|         it could possibly make the values inaccurate to what we desire. | ||||
| 
 | ||||
|         matched_split: The caption track url we want to return a value for.         | ||||
|         """ | ||||
|         return len(re.sub(self.NAME_REGEX, r'\1', matched_split)) | ||||
| 
 | ||||
|     def _execute_api_request(self, timedtext_url): | ||||
|  |  | |||
|  | @ -99,8 +99,8 @@ class TestYouTubeTranscriptApi(TestCase): | |||
| 
 | ||||
|         YouTubeTranscriptApi.get_transcripts(['video_id_1', 'video_id_2'], continue_after_error=True) | ||||
| 
 | ||||
|         YouTubeTranscriptApi.get_transcript.assert_any_call(video_id_1, ['en'], None) | ||||
|         YouTubeTranscriptApi.get_transcript.assert_any_call(video_id_2, ['en'], None) | ||||
|         YouTubeTranscriptApi.get_transcript.assert_any_call(video_id_1, ('en',), None) | ||||
|         YouTubeTranscriptApi.get_transcript.assert_any_call(video_id_2, ('en',), None) | ||||
| 
 | ||||
|     def test_get_transcript__with_proxies(self): | ||||
|         proxies = {'http': '', 'https:': ''} | ||||
|  | @ -118,5 +118,4 @@ class TestYouTubeTranscriptApi(TestCase): | |||
|         ) | ||||
|         YouTubeTranscriptApi.get_transcript = MagicMock() | ||||
|         YouTubeTranscriptApi.get_transcripts(['GJLlxj_dtq8'], proxies=proxies) | ||||
|         print(YouTubeTranscriptApi.get_transcript.mock_calls) | ||||
|         YouTubeTranscriptApi.get_transcript.assert_any_call('GJLlxj_dtq8', ['en'], proxies) | ||||
|         YouTubeTranscriptApi.get_transcript.assert_any_call('GJLlxj_dtq8', ('en',), proxies) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue