From d224b02a80517de075178f6cb707f0a43516c176 Mon Sep 17 00:00:00 2001 From: danielcliu Date: Sun, 10 Nov 2019 22:44:24 -0800 Subject: [PATCH] Languages argument defaults to a tuple instead of a list. --- youtube_transcript_api/_api.py | 16 +++++++++++----- youtube_transcript_api/test/test_api.py | 7 +++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/youtube_transcript_api/_api.py b/youtube_transcript_api/_api.py index 9805f80..2a38340 100644 --- a/youtube_transcript_api/_api.py +++ b/youtube_transcript_api/_api.py @@ -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): diff --git a/youtube_transcript_api/test/test_api.py b/youtube_transcript_api/test/test_api.py index c53f81c..a151c6b 100644 --- a/youtube_transcript_api/test/test_api.py +++ b/youtube_transcript_api/test/test_api.py @@ -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)