Beispiel #1
0
    def test_argument_parsing__list_transcripts(self):
        parsed_args = YouTubeTranscriptCli('--list-transcripts v1 v2'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertTrue(parsed_args.list_transcripts)

        parsed_args = YouTubeTranscriptCli('v1 v2 --list-transcripts'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertTrue(parsed_args.list_transcripts)
Beispiel #2
0
    def test_argument_parsing__json(self):
        parsed_args = YouTubeTranscriptCli('v1 v2 --json'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.json, True)
        self.assertEqual(parsed_args.languages, [])

        parsed_args = YouTubeTranscriptCli('--json v1 v2'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.json, True)
        self.assertEqual(parsed_args.languages, [])
Beispiel #3
0
    def test_argument_parsing__translate(self):
        parsed_args = YouTubeTranscriptCli('v1 v2 --languages de en --translate cz'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.json, False)
        self.assertEqual(parsed_args.languages, ['de', 'en'])
        self.assertEqual(parsed_args.translate, 'cz')

        parsed_args = YouTubeTranscriptCli('v1 v2 --translate cz --languages de en'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.json, False)
        self.assertEqual(parsed_args.languages, ['de', 'en'])
        self.assertEqual(parsed_args.translate, 'cz')
Beispiel #4
0
    def test_argument_parsing__manually_or_generated(self):
        parsed_args = YouTubeTranscriptCli('v1 v2 --exclude-manually-created'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertTrue(parsed_args.exclude_manually_created)
        self.assertFalse(parsed_args.exclude_generated)

        parsed_args = YouTubeTranscriptCli('v1 v2 --exclude-generated'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertFalse(parsed_args.exclude_manually_created)
        self.assertTrue(parsed_args.exclude_generated)

        parsed_args = YouTubeTranscriptCli('v1 v2 --exclude-manually-created --exclude-generated'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertTrue(parsed_args.exclude_manually_created)
        self.assertTrue(parsed_args.exclude_generated)
Beispiel #5
0
    def test_run__failing_transcripts(self):
        YouTubeTranscriptApi.list_transcripts = MagicMock(
            side_effect=VideoUnavailable('video_id'))

        output = YouTubeTranscriptCli('v1 --languages de en'.split()).run()

        self.assertEqual(output, str(VideoUnavailable('video_id')))
Beispiel #6
0
    def test_run__exclude_manually_created(self):
        YouTubeTranscriptCli(
            'v1 v2 --languages de en --exclude-manually-created'.split()).run(
            )

        self.transcript_list_mock.find_generated_transcript.assert_any_call(
            ['de', 'en'])
Beispiel #7
0
    def test_run(self):
        YouTubeTranscriptCli('v1 v2 --languages de en'.split()).run()

        YouTubeTranscriptApi.list_transcripts.assert_any_call('v1', proxies=None, cookies=None)
        YouTubeTranscriptApi.list_transcripts.assert_any_call('v2', proxies=None, cookies=None)

        self.transcript_list_mock.find_transcript.assert_any_call(['de', 'en'])
Beispiel #8
0
    def test_run__list_transcripts(self):
        YouTubeTranscriptCli('--list-transcripts v1 v2'.split()).run()

        YouTubeTranscriptApi.list_transcripts.assert_any_call('v1',
                                                              proxies=None)
        YouTubeTranscriptApi.list_transcripts.assert_any_call('v2',
                                                              proxies=None)
Beispiel #9
0
 def test_run__cookies(self):
     YouTubeTranscriptCli(('v1 v2 --languages de en '
                           '--cookies blahblah.txt').split()).run()
     YouTubeTranscriptApi.list_transcripts.assert_any_call(
         'v1', proxies=None, cookies='blahblah.txt')
     YouTubeTranscriptApi.list_transcripts.assert_any_call(
         'v2', proxies=None, cookies='blahblah.txt')
Beispiel #10
0
    def test_run(self):
        YouTubeTranscriptApi.get_transcripts = MagicMock(return_value=([], []))
        YouTubeTranscriptCli('v1 v2 --languages de en'.split()).run()

        YouTubeTranscriptApi.get_transcripts.assert_called_once_with(
            ['v1', 'v2'],
            languages=['de', 'en'],
            continue_after_error=True,
            proxies=None
        )
    def test_run__json_output(self):
        YouTubeTranscriptApi.get_transcripts = MagicMock(
            return_value=([{
                'boolean': True
            }], []))
        output = YouTubeTranscriptCli(
            'v1 v2 --languages de en --json'.split()).run()

        # will fail if output is not valid json
        json.loads(output)
Beispiel #12
0
    def test_run__proxies(self):
        YouTubeTranscriptApi.get_transcripts = MagicMock(return_value=([], []))
        YouTubeTranscriptCli(
            'v1 v2 --languages de en --http-proxy http://user:pass@domain:port --https-proxy https://user:pass@domain:port'.split()).run()

        YouTubeTranscriptApi.get_transcripts.assert_called_once_with(
            ['v1', 'v2'],
            languages=['de', 'en'],
            continue_after_error=True,
            proxies={'http': 'http://*****:*****@domain:port', 'https': 'https://*****:*****@domain:port'}
        )
Beispiel #13
0
    def test_argument_parsing__proxies(self):
        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --http-proxy http://user:pass@domain:port'.split()
        )._parse_args()
        self.assertEqual(parsed_args.http_proxy, 'http://*****:*****@domain:port')

        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --https-proxy https://user:pass@domain:port'.split()
        )._parse_args()
        self.assertEqual(parsed_args.https_proxy, 'https://*****:*****@domain:port')

        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --http-proxy http://user:pass@domain:port --https-proxy https://user:pass@domain:port'.split()
        )._parse_args()
        self.assertEqual(parsed_args.http_proxy, 'http://*****:*****@domain:port')
        self.assertEqual(parsed_args.https_proxy, 'https://*****:*****@domain:port')

        parsed_args = YouTubeTranscriptCli(
            'v1 v2'.split()
        )._parse_args()
        self.assertEqual(parsed_args.http_proxy, '')
        self.assertEqual(parsed_args.https_proxy, '')
Beispiel #14
0
    def test_argument_parsing(self):
        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --format json --languages de en'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.format, 'json')
        self.assertEqual(parsed_args.languages, ['de', 'en'])
        self.assertEqual(parsed_args.http_proxy, '')
        self.assertEqual(parsed_args.https_proxy, '')

        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --languages de en --format json'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.format, 'json')
        self.assertEqual(parsed_args.languages, ['de', 'en'])
        self.assertEqual(parsed_args.http_proxy, '')
        self.assertEqual(parsed_args.https_proxy, '')

        parsed_args = YouTubeTranscriptCli(
            ' --format json v1 v2 --languages de en'.split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.format, 'json')
        self.assertEqual(parsed_args.languages, ['de', 'en'])
        self.assertEqual(parsed_args.http_proxy, '')
        self.assertEqual(parsed_args.https_proxy, '')

        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --languages de en --format json '
            '--http-proxy http://user:pass@domain:port '
            '--https-proxy https://user:pass@domain:port'.split())._parse_args(
            )
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.format, 'json')
        self.assertEqual(parsed_args.languages, ['de', 'en'])
        self.assertEqual(parsed_args.http_proxy,
                         'http://*****:*****@domain:port')
        self.assertEqual(parsed_args.https_proxy,
                         'https://*****:*****@domain:port')

        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --languages de en --format json --http-proxy http://user:pass@domain:port'
            .split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.format, 'json')
        self.assertEqual(parsed_args.languages, ['de', 'en'])
        self.assertEqual(parsed_args.http_proxy,
                         'http://*****:*****@domain:port')
        self.assertEqual(parsed_args.https_proxy, '')

        parsed_args = YouTubeTranscriptCli(
            'v1 v2 --languages de en --format json --https-proxy https://user:pass@domain:port'
            .split())._parse_args()
        self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
        self.assertEqual(parsed_args.format, 'json')
        self.assertEqual(parsed_args.languages, ['de', 'en'])
        self.assertEqual(parsed_args.https_proxy,
                         'https://*****:*****@domain:port')
        self.assertEqual(parsed_args.http_proxy, '')
Beispiel #15
0
    def test_run__proxies(self):
        YouTubeTranscriptCli(
            ('v1 v2 --languages de en '
             '--http-proxy http://user:pass@domain:port '
             '--https-proxy https://user:pass@domain:port').split()).run()

        YouTubeTranscriptApi.list_transcripts.assert_any_call(
            'v1',
            proxies={
                'http': 'http://*****:*****@domain:port',
                'https': 'https://*****:*****@domain:port'
            })

        YouTubeTranscriptApi.list_transcripts.assert_any_call(
            'v2',
            proxies={
                'http': 'http://*****:*****@domain:port',
                'https': 'https://*****:*****@domain:port'
            })
Beispiel #16
0
    def test_run__json_output(self):
        output = YouTubeTranscriptCli(
            'v1 v2 --languages de en --json'.split()).run()

        # will fail if output is not valid json
        json.loads(output)
Beispiel #17
0
    def test_run__translate(self):
        YouTubeTranscriptCli(
            'v1 v2 --languages de en --translate cz'.split()).run(),

        self.transcript_mock.translate.assert_any_call('cz')
Beispiel #18
0
 def test_run__exclude_manually_created_and_generated(self):
     self.assertEqual(
         YouTubeTranscriptCli(
             'v1 v2 --languages de en --exclude-manually-created --exclude-generated'
             .split()).run(), '')
Beispiel #19
0
 def test_argument_parsing__languages(self):
     parsed_args = YouTubeTranscriptCli(
         'v1 v2 --languages de en'.split())._parse_args()
     self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
     self.assertEqual(parsed_args.format, 'pretty')
     self.assertEqual(parsed_args.languages, ['de', 'en'])
Beispiel #20
0
 def test_argument_parsing__fail_without_video_ids(self):
     with self.assertRaises(SystemExit):
         YouTubeTranscriptCli('--json'.split())._parse_args()
Beispiel #21
0
 def test_argument_parsing__only_video_ids(self):
     parsed_args = YouTubeTranscriptCli('v1 v2'.split())._parse_args()
     self.assertEqual(parsed_args.video_ids, ['v1', 'v2'])
     self.assertEqual(parsed_args.json, False)
     self.assertEqual(parsed_args.languages, ['en'])
Beispiel #22
0
 def test_argument_parsing__video_ids_starting_with_dash(self):
     parsed_args = YouTubeTranscriptCli(
         '\-v1 \-\-v2 \--v3'.split())._parse_args()
     self.assertEqual(parsed_args.video_ids, ['-v1', '--v2', '--v3'])
     self.assertEqual(parsed_args.format, 'pretty')
     self.assertEqual(parsed_args.languages, ['en'])