コード例 #1
0
 def test_youtube_playlist_noplaylist(self):
     dl = FakeYDL()
     dl.params['noplaylist'] = True
     ie = YoutubePlaylistIE(dl)
     result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
     self.assertEqual(result['_type'], 'url')
     self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg')
コード例 #2
0
 def test_youtube_playlist_noplaylist(self):
     dl = FakeYDL()
     dl.params["noplaylist"] = True
     ie = YoutubePlaylistIE(dl)
     result = ie.extract("https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re")
     self.assertEqual(result["_type"], "url")
     self.assertEqual(YoutubeIE()._extract_id(result["url"]), "FXxLjLQi3Fg")
コード例 #3
0
 def test_youtube_flat_playlist_titles(self):
     dl = FakeYDL()
     dl.params['extract_flat'] = True
     ie = YoutubePlaylistIE(dl)
     result = ie.extract('https://www.youtube.com/playlist?list=PL-KKIb8rvtMSrAO9YFbeM6UQrAqoFTUWv')
     self.assertIsPlaylist(result)
     for entry in result['entries']:
         self.assertTrue(entry.get('title'))
コード例 #4
0
ファイル: test_socks.py プロジェクト: 0wnrepo/youtube-dl
    def _get_ip(self, protocol):
        if self._SKIP_SOCKS_TEST:
            return '127.0.0.1'

        ydl = FakeYDL({
            'proxy': '%s://127.0.0.1:%d' % (protocol, self.port),
        })
        return ydl.urlopen('http://yt-dl.org/ip').read().decode('utf-8')
コード例 #5
0
 def test_youtube_flat_playlist_titles(self):
     dl = FakeYDL()
     dl.params['extract_flat'] = True
     ie = YoutubePlaylistIE(dl)
     result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
     self.assertIsPlaylist(result)
     for entry in result['entries']:
         self.assertTrue(entry.get('title'))
コード例 #6
0
ファイル: test_socks.py プロジェクト: 0wnrepo/youtube-dl
 def test_secondary_proxy_https(self):
     params = self._check_params(['secondary_proxy', 'secondary_server_ip'])
     if params is None:
         return
     ydl = FakeYDL()
     req = compat_urllib_request.Request('https://yt-dl.org/ip')
     req.add_header('Ytdl-request-proxy', params['secondary_proxy'])
     self.assertEqual(
         ydl.urlopen(req).read().decode('utf-8'),
         params['secondary_server_ip'])
コード例 #7
0
ファイル: test_socks.py プロジェクト: 0wnrepo/youtube-dl
 def test_proxy_https(self):
     params = self._check_params(['primary_proxy', 'primary_server_ip'])
     if params is None:
         return
     ydl = FakeYDL({
         'proxy': params['primary_proxy']
     })
     self.assertEqual(
         ydl.urlopen('https://yt-dl.org/ip').read().decode('utf-8'),
         params['primary_server_ip'])
コード例 #8
0
 def test_youtube_mix(self):
     dl = FakeYDL()
     ie = YoutubePlaylistIE(dl)
     result = ie.extract(
         'https://www.youtube.com/watch?v=W01L70IGBgE&index=2&list=RDOQpdSVF_k_w'
     )
     entries = result['entries']
     self.assertTrue(len(entries) >= 20)
     original_video = entries[0]
     self.assertEqual(original_video['id'], 'OQpdSVF_k_w')
コード例 #9
0
 def test_youtube_mix(self):
     dl = FakeYDL()
     ie = YoutubeTabIE(dl)
     result = ie.extract(
         'https://www.youtube.com/watch?v=tyITL_exICo&list=RDCLAK5uy_kLWIr9gv1XLlPbaDS965-Db4TrBoUTxQ8'
     )
     entries = list(result['entries'])
     self.assertTrue(len(entries) >= 50)
     original_video = entries[0]
     self.assertEqual(original_video['id'], 'tyITL_exICo')
コード例 #10
0
    def test_iqiyi_sdk_interpreter(self):
        '''
        Test the functionality of IqiyiSDKInterpreter by trying to log in

        If `sign` is incorrect, /validate call throws an HTTP 556 error
        '''
        logger = WarningLogger()
        ie = IqiyiIEWithCredentials(FakeYDL({'logger': logger}))
        ie._login()
        self.assertTrue('unable to log in:' in logger.messages[0])
コード例 #11
0
 def test_youtube_flat_playlist_extraction(self):
     dl = FakeYDL()
     dl.params['extract_flat'] = True
     ie = YoutubeTabIE(dl)
     result = ie.extract(
         'https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc'
     )
     self.assertIsPlaylist(result)
     entries = list(result['entries'])
     self.assertTrue(len(entries) == 1)
     video = entries[0]
     self.assertEqual(video['_type'], 'url')
     self.assertEqual(video['ie_key'], 'Youtube')
     self.assertEqual(video['id'], 'BaW_jenozKc')
     self.assertEqual(video['url'],
                      'https://www.youtube.com/watch?v=BaW_jenozKc')
     self.assertEqual(video['title'], 'youtube-dl test video "\'/\\ä↭𝕐')
     self.assertEqual(video['duration'], 10)
     self.assertEqual(video['uploader'], 'Philipp Hagemeister')
コード例 #12
0
 def test_CSpan_playlist(self):
     dl = FakeYDL()
     ie = CSpanIE(dl)
     result = ie.extract(
         'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall')
     self.assertIsPlaylist(result)
     self.assertEqual(result['id'], '342759')
     self.assertEqual(result['title'],
                      'General Motors Ignition Switch Recall')
     whole_duration = sum(e['duration'] for e in result['entries'])
     self.assertEqual(whole_duration, 14855)
コード例 #13
0
 def test_youtube_course(self):
     print('Skipping: Course URLs no longer exists')
     return
     dl = FakeYDL()
     ie = YoutubePlaylistIE(dl)
     # TODO find a > 100 (paginating?) videos course
     result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
     entries = list(result['entries'])
     self.assertEqual(YoutubeIE.extract_id(entries[0]['url']), 'j9WZyLZCBzs')
     self.assertEqual(len(entries), 25)
     self.assertEqual(YoutubeIE.extract_id(entries[-1]['url']), 'rYefUsYuEp0')
コード例 #14
0
 def test_youtube_channel(self):
     dl = FakeYDL()
     ie = YoutubeChannelIE(dl)
     #test paginated channel
     result = ie.extract(
         'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')
     self.assertTrue(len(result['entries']) > 90)
     #test autogenerated channel
     result = ie.extract(
         'https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
     self.assertTrue(len(result['entries']) >= 18)
コード例 #15
0
ファイル: test_YoutubeDL.py プロジェクト: zsh2020/youtube-dl
    def test_default_times(self):
        """Test addition of missing upload/release/_date from /release_/timestamp"""
        info = {
            'id': '1234',
            'url': TEST_URL,
            'title': 'Title',
            'ext': 'mp4',
            'timestamp': 1631352900,
            'release_timestamp': 1632995931,
        }

        params = {
            'simulate': True,
        }
        ydl = FakeYDL(params)
        out_info = ydl.process_ie_result(info)
        self.assertTrue(isinstance(out_info['upload_date'], compat_str))
        self.assertEqual(out_info['upload_date'], '20210911')
        self.assertTrue(isinstance(out_info['release_date'], compat_str))
        self.assertEqual(out_info['release_date'], '20210930')
コード例 #16
0
 def test_aol_playlist(self):
     dl = FakeYDL()
     ie = AolIE(dl)
     result = ie.extract(
         'http://on.aol.com/playlist/brace-yourself---todays-weirdest-news-152147?icid=OnHomepageC4_Omg_Img#_videoid=518184316'
     )
     self.assertIsPlaylist(result)
     self.assertEqual(result['id'], '152147')
     self.assertEqual(result['title'],
                      'Brace Yourself - Today\'s Weirdest News')
     assertGreaterEqual(self, len(result['entries']), 10)
コード例 #17
0
 def test_youtube_playlist_with_deleted(self):
     #651
     dl = FakeYDL()
     ie = YoutubePlaylistIE(dl)
     result = ie.extract(
         'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC'
     )
     ytie_results = [
         YoutubeIE().extract_id(url['url']) for url in result['entries']
     ]
     self.assertFalse('pElCt5oNDuI' in ytie_results)
     self.assertFalse('KdPEApIVdWM' in ytie_results)
コード例 #18
0
 def test_soundcloud_playlist(self):
     dl = FakeYDL()
     ie = SoundcloudPlaylistIE(dl)
     result = ie.extract('http://api.soundcloud.com/playlists/4110309')
     self.assertIsPlaylist(result)
     self.assertEqual(result['id'], '4110309')
     self.assertEqual(
         result['title'],
         'TILT Brass - Bowery Poetry Club, August \'03 [Non-Site SCR 02]')
     assertRegexpMatches(self, result['description'],
                         r'.*?TILT Brass - Bowery Poetry Club')
     self.assertEqual(len(result['entries']), 6)
コード例 #19
0
ファイル: test_playlists.py プロジェクト: 0m15/youtube-dl
 def test_InstagramUser(self):
     dl = FakeYDL()
     ie = InstagramUserIE(dl)
     result = ie.extract("http://instagram.com/porsche")
     self.assertIsPlaylist(result)
     self.assertEqual(result["id"], "porsche")
     self.assertTrue(len(result["entries"]) >= 2)
     test_video = next(e for e in result["entries"] if e["id"] == "614605558512799803_462752227")
     dl.add_default_extra_info(test_video, ie, "(irrelevant URL)")
     dl.process_video_result(test_video, download=False)
     EXPECTED = {
         "id": "614605558512799803_462752227",
         "ext": "mp4",
         "title": "#Porsche Intelligent Performance.",
         "thumbnail": "re:^https?://.*\.jpg",
         "uploader": "Porsche",
         "uploader_id": "porsche",
         "timestamp": 1387486713,
         "upload_date": "20131219",
     }
     expect_info_dict(self, EXPECTED, test_video)
コード例 #20
0
 def test_AcademicEarthCourse(self):
     dl = FakeYDL()
     ie = AcademicEarthCourseIE(dl)
     result = ie.extract(
         'http://academicearth.org/playlists/laws-of-nature/')
     self.assertIsPlaylist(result)
     self.assertEqual(result['id'], 'laws-of-nature')
     self.assertEqual(result['title'], 'Laws of Nature')
     self.assertEqual(
         result['description'],
         u'Introduce yourself to the laws of nature with these free online college lectures from Yale, Harvard, and MIT.'
     )  # u"Today's websites are increasingly dynamic. Pages are no longer static HTML files but instead generated by scripts and database calls. User interfaces are more seamless, with technologies like Ajax replacing traditional page reloads. This course teaches students how to build dynamic websites with Ajax and with Linux, Apache, MySQL, and PHP (LAMP), one of today's most popular frameworks. Students learn how to set up domain names with DNS, how to structure pages with XHTML and CSS, how to program in JavaScript and PHP, how to configure Apache and MySQL, how to design and query databases with SQL, how to use Ajax with both XML and JSON, and how to build mashups. The course explores issues of security, scalability, and cross-browser support and also discusses enterprise-level deployments of websites, including third-party hosting, virtualization, colocation in data centers, firewalling, and load-balancing.")
     self.assertEqual(len(result['entries']), 4)
コード例 #21
0
 def test_khanacademy_topic(self):
     dl = FakeYDL()
     ie = KhanAcademyIE(dl)
     result = ie.extract(
         'https://www.khanacademy.org/math/applied-math/cryptography')
     self.assertIsPlaylist(result)
     self.assertEqual(result['id'], 'cryptography')
     self.assertEqual(result['title'], 'Journey into cryptography')
     self.assertEqual(
         result['description'],
         'How have humans protected their secret messages through history? What has changed today?'
     )
     assertGreaterEqual(self, len(result['entries']), 3)
コード例 #22
0
 def test_youtube_playlist(self):
     dl = FakeYDL()
     ie = YoutubePlaylistIE(dl)
     result = ie.extract(
         'https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re'
     )
     self.assertIsPlaylist(result)
     self.assertEqual(result['title'], 'ytdl test PL')
     ytie_results = [
         YoutubeIE().extract_id(url['url']) for url in result['entries']
     ]
     self.assertEqual(ytie_results,
                      ['bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
コード例 #23
0
ファイル: test_playlists.py プロジェクト: 668/youtube-dl
 def test_InstagramUser(self):
     dl = FakeYDL()
     ie = InstagramUserIE(dl)
     result = ie.extract('http://instagram.com/porsche')
     self.assertIsPlaylist(result)
     self.assertEqual(result['id'], 'porsche')
     self.assertTrue(len(result['entries']) >= 2)
     test_video = next(
         e for e in result['entries']
         if e['id'] == '614605558512799803_462752227')
     dl.add_default_extra_info(test_video, ie, '(irrelevant URL)')
     dl.process_video_result(test_video, download=False)
     EXPECTED = {
         'id': '614605558512799803_462752227',
         'ext': 'mp4',
         'title': '#Porsche Intelligent Performance.',
         'thumbnail': 're:^https?://.*\.jpg',
         'uploader': 'Porsche',
         'uploader_id': 'porsche',
         'timestamp': 1387486713,
         'upload_date': '20131219',
     }
     expect_info_dict(self, EXPECTED, test_video)
コード例 #24
0
class BaseTestSubtitles(unittest.TestCase):
    url = None
    IE = None

    def setUp(self):
        self.DL = FakeYDL()
        self.ie = self.IE()
        self.DL.add_info_extractor(self.ie)

    def getInfoDict(self):
        info_dict = self.DL.extract_info(self.url, download=False)
        return info_dict

    def getSubtitles(self):
        info_dict = self.getInfoDict()
        subtitles = info_dict['requested_subtitles']
        if not subtitles:
            return subtitles
        for sub_info in subtitles.values():
            if sub_info.get('data') is None:
                uf = self.DL.urlopen(sub_info['url'])
                sub_info['data'] = uf.read().decode('utf-8')
        return {l: sub_info['data'] for l, sub_info in subtitles.items()}
コード例 #25
0
ファイル: test_subtitles.py プロジェクト: bastik/youtube-dl
class BaseTestSubtitles(unittest.TestCase):
    url = None
    IE = None

    def setUp(self):
        self.DL = FakeYDL()
        self.ie = self.IE()
        self.DL.add_info_extractor(self.ie)

    def getInfoDict(self):
        info_dict = self.DL.extract_info(self.url, download=False)
        return info_dict

    def getSubtitles(self):
        info_dict = self.getInfoDict()
        subtitles = info_dict['requested_subtitles']
        if not subtitles:
            return subtitles
        for sub_info in subtitles.values():
            if sub_info.get('data') is None:
                uf = self.DL.urlopen(sub_info['url'])
                sub_info['data'] = uf.read().decode('utf-8')
        return dict((l, sub_info['data']) for l, sub_info in subtitles.items())
コード例 #26
0
 def test_multiple_brightcove_videos(self):
     # https://github.com/rg3/youtube-dl/issues/2283
     dl = FakeYDL()
     ie = GenericIE(dl)
     result = ie.extract(
         'http://www.newyorker.com/online/blogs/newsdesk/2014/01/always-never-nuclear-command-and-control.html'
     )
     self.assertIsPlaylist(result)
     self.assertEqual(result['id'],
                      'always-never-nuclear-command-and-control')
     self.assertEqual(
         result['title'],
         'Always/Never: A Little-Seen Movie About Nuclear Command and Control : The New Yorker'
     )
     self.assertEqual(len(result['entries']), 3)
コード例 #27
0
    def test_func(self):
        basename = 'player-%s.js' % test_id
        fn = os.path.join(self.TESTDATA_DIR, basename)

        if not os.path.exists(fn):
            compat_urlretrieve(url, fn)

        ydl = FakeYDL()
        ie = YoutubeIE(ydl)
        with io.open(fn, encoding='utf-8') as testf:
            jscode = testf.read()
        func = ie._parse_sig_js(jscode)
        src_sig = (compat_str(string.printable[:sig_input]) if isinstance(
            sig_input, int) else sig_input)
        got_sig = func(src_sig)
        self.assertEqual(got_sig, expected_sig)
コード例 #28
0
ファイル: test_cache.py プロジェクト: RobinD42/yt-dlc
 def test_cache(self):
     ydl = FakeYDL({
         'cachedir': self.test_dir,
     })
     c = Cache(ydl)
     obj = {'x': 1, 'y': ['ä', '\\a', True]}
     self.assertEqual(c.load('test_cache', 'k.'), None)
     c.store('test_cache', 'k.', obj)
     self.assertEqual(c.load('test_cache', 'k2'), None)
     self.assertFalse(_is_empty(self.test_dir))
     self.assertEqual(c.load('test_cache', 'k.'), obj)
     self.assertEqual(c.load('test_cache', 'y'), None)
     self.assertEqual(c.load('test_cache2', 'k.'), None)
     c.remove()
     self.assertFalse(os.path.exists(self.test_dir))
     self.assertEqual(c.load('test_cache', 'k.'), None)
コード例 #29
0
class TestDailymotionSubtitles(unittest.TestCase):
    def setUp(self):
        self.DL = FakeYDL()
        self.url = 'http://www.dailymotion.com/video/xczg00'
    def getInfoDict(self):
        IE = DailymotionIE(self.DL)
        info_dict = IE.extract(self.url)
        return info_dict
    def getSubtitles(self):
        info_dict = self.getInfoDict()
        return info_dict['subtitles']
    def test_no_writesubtitles(self):
        subtitles = self.getSubtitles()
        self.assertEqual(subtitles, None)
    def test_subtitles(self):
        self.DL.params['writesubtitles'] = True
        subtitles = self.getSubtitles()
        self.assertEqual(md5(subtitles['en']), '976553874490cba125086bbfea3ff76f')
    def test_subtitles_lang(self):
        self.DL.params['writesubtitles'] = True
        self.DL.params['subtitleslangs'] = ['fr']
        subtitles = self.getSubtitles()
        self.assertEqual(md5(subtitles['fr']), '594564ec7d588942e384e920e5341792')
    def test_allsubtitles(self):
        self.DL.params['writesubtitles'] = True
        self.DL.params['allsubtitles'] = True
        subtitles = self.getSubtitles()
        self.assertEqual(len(subtitles.keys()), 5)
    def test_list_subtitles(self):
        self.DL.expect_warning(u'Automatic Captions not supported by this server')
        self.DL.params['listsubtitles'] = True
        info_dict = self.getInfoDict()
        self.assertEqual(info_dict, None)
    def test_automatic_captions(self):
        self.DL.expect_warning(u'Automatic Captions not supported by this server')
        self.DL.params['writeautomaticsub'] = True
        self.DL.params['subtitleslang'] = ['en']
        subtitles = self.getSubtitles()
        self.assertTrue(len(subtitles.keys()) == 0)
    def test_nosubtitles(self):
        self.DL.expect_warning(u'video doesn\'t have subtitles')
        self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
        self.DL.params['writesubtitles'] = True
        self.DL.params['allsubtitles'] = True
        subtitles = self.getSubtitles()
        self.assertEqual(len(subtitles), 0)
    def test_multiple_langs(self):
        self.DL.params['writesubtitles'] = True
        langs = ['es', 'fr', 'de']
        self.DL.params['subtitleslangs'] = langs
        subtitles = self.getSubtitles()
        for lang in langs:
            self.assertTrue(subtitles.get(lang) is not None, u'Subtitles for \'%s\' not extracted' % lang)
コード例 #30
0
 def test_InstagramUser(self):
     dl = FakeYDL()
     ie = InstagramUserIE(dl)
     result = ie.extract('http://instagram.com/porsche')
     self.assertIsPlaylist(result)
     self.assertEqual(result['id'], 'porsche')
     assertGreaterEqual(self, len(result['entries']), 2)
     test_video = next(e for e in result['entries']
                       if e['id'] == '614605558512799803_462752227')
     dl.add_default_extra_info(test_video, ie, '(irrelevant URL)')
     dl.process_video_result(test_video, download=False)
     EXPECTED = {
         'id': '614605558512799803_462752227',
         'ext': 'mp4',
         'title': '#Porsche Intelligent Performance.',
         'thumbnail': 're:^https?://.*\.jpg',
         'uploader': 'Porsche',
         'uploader_id': 'porsche',
         'timestamp': 1387486713,
         'upload_date': '20131219',
     }
     expect_info_dict(self, EXPECTED, test_video)
コード例 #31
0
ファイル: test_subtitles.py プロジェクト: bastik/youtube-dl
 def setUp(self):
     self.DL = FakeYDL()
     self.ie = self.IE()
     self.DL.add_info_extractor(self.ie)
コード例 #32
0
 def setUp(self):
     self.DL = FakeYDL()
     self.url = 'http://www.dailymotion.com/video/xczg00'
コード例 #33
0
def signature(jscode, sig_input):
    func = YoutubeIE(FakeYDL())._parse_sig_js(jscode)
    src_sig = (compat_str(string.printable[:sig_input]) if isinstance(
        sig_input, int) else sig_input)
    return func(src_sig)
コード例 #34
0
 def test_youtube_show(self):
     dl = FakeYDL()
     ie = YoutubeShowIE(dl)
     result = ie.extract('http://www.youtube.com/show/airdisasters')
     self.assertTrue(len(result) >= 3)
コード例 #35
0
class TestYoutubeSubtitles(unittest.TestCase):
    def setUp(self):
        self.DL = FakeYDL()
        self.url = 'QRS8MkLhQmM'

    def getInfoDict(self):
        IE = YoutubeIE(self.DL)
        info_dict = IE.extract(self.url)
        return info_dict

    def getSubtitles(self):
        info_dict = self.getInfoDict()
        return info_dict[0]['subtitles']

    def test_youtube_no_writesubtitles(self):
        self.DL.params['writesubtitles'] = False
        subtitles = self.getSubtitles()
        self.assertEqual(subtitles, None)

    def test_youtube_subtitles(self):
        self.DL.params['writesubtitles'] = True
        subtitles = self.getSubtitles()
        self.assertEqual(md5(subtitles['en']), '4cd9278a35ba2305f47354ee13472260')

    def test_youtube_subtitles_lang(self):
        self.DL.params['writesubtitles'] = True
        self.DL.params['subtitleslangs'] = ['it']
        subtitles = self.getSubtitles()
        self.assertEqual(md5(subtitles['it']), '164a51f16f260476a05b50fe4c2f161d')

    def test_youtube_allsubtitles(self):
        self.DL.params['writesubtitles'] = True
        self.DL.params['allsubtitles'] = True
        subtitles = self.getSubtitles()
        self.assertEqual(len(subtitles.keys()), 13)

    def test_youtube_subtitles_sbv_format(self):
        self.DL.params['writesubtitles'] = True
        self.DL.params['subtitlesformat'] = 'sbv'
        subtitles = self.getSubtitles()
        self.assertEqual(md5(subtitles['en']), '13aeaa0c245a8bed9a451cb643e3ad8b')

    def test_youtube_subtitles_vtt_format(self):
        self.DL.params['writesubtitles'] = True
        self.DL.params['subtitlesformat'] = 'vtt'
        subtitles = self.getSubtitles()
        self.assertEqual(md5(subtitles['en']), '356cdc577fde0c6783b9b822e7206ff7')

    def test_youtube_list_subtitles(self):
        self.DL.expect_warning(u'Video doesn\'t have automatic captions')
        self.DL.params['listsubtitles'] = True
        info_dict = self.getInfoDict()
        self.assertEqual(info_dict, None)

    def test_youtube_automatic_captions(self):
        self.url = '8YoUxe5ncPo'
        self.DL.params['writeautomaticsub'] = True
        self.DL.params['subtitleslangs'] = ['it']
        subtitles = self.getSubtitles()
        self.assertTrue(subtitles['it'] is not None)

    def test_youtube_nosubtitles(self):
        self.DL.expect_warning(u'video doesn\'t have subtitles')
        self.url = 'sAjKT8FhjI8'
        self.DL.params['writesubtitles'] = True
        self.DL.params['allsubtitles'] = True
        subtitles = self.getSubtitles()
        self.assertEqual(len(subtitles), 0)

    def test_youtube_multiple_langs(self):
        self.url = 'QRS8MkLhQmM'
        self.DL.params['writesubtitles'] = True
        langs = ['it', 'fr', 'de']
        self.DL.params['subtitleslangs'] = langs
        subtitles = self.getSubtitles()
        for lang in langs:
            self.assertTrue(subtitles.get(lang) is not None, u'Subtitles for \'%s\' not extracted' % lang)
コード例 #36
0
 def setUp(self):
     self.DL = FakeYDL()
     self.url = 'QRS8MkLhQmM'
コード例 #37
0
 def test_issue_673(self):
     dl = FakeYDL()
     ie = YoutubePlaylistIE(dl)
     result = ie.extract('PLBB231211A4F62143')
     self.assertTrue(len(result['entries']) > 25)
コード例 #38
0
def n_sig(jscode, sig_input):
    funcname = YoutubeIE(FakeYDL())._extract_n_function_name(jscode)
    return JSInterpreter(jscode).call_function(funcname, sig_input)
コード例 #39
0
 def test_youtube_safe_search(self):
     dl = FakeYDL()
     ie = YoutubePlaylistIE(dl)
     result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')
     self.assertEqual(len(result['entries']), 2)
コード例 #40
0
class testSubtitles(unittest.TestCase):
    url = None
    IE = None

    #set up the youtube download download the video
    def setUp(self):
        self.DL = FakeYDL()
        self.ie = self.IE()
        self.DL.add_info_extractor(self.ie)

    #extract the info from the download
    def getInfoDict(self):
        info_dict = self.DL.extract_info(self.url, download=False)
        return info_dict

    #finally get the subtitles from the video 
    def getSubtitles(self):
        info_dict = self.getInfoDict()
        subtitles = info_dict['requested_subtitles']
        if not subtitles:
            return subtitles
        for sub_info in subtitles.values():
            if sub_info.get('data') is None:
                uf = self.DL.urlopen(sub_info['url'])
                sub_info['data'] = uf.read().decode('utf-8')
        return dict((l, sub_info['data']) for l, sub_info in subtitles.items())



    #--------------------------- test cases ----------------------------------

    #final configuration of youtube page
    url = 'QRS8MkLhQmM'
    IE = YoutubeIE


    #-------test1: test that the subtitles have been extracted--------
    def test_extraction(self):

        #get all the subtites in a variable
        self.DL.params['writesubtitles'] = True
        self.DL.params['allsubtitles'] = True
        subtitles = self.getSubtitles()

        #test that the subtitles are in english and proper format
        self.assertEqual(md5(subtitles['en']), 'ae1bd34126571a77aabd4d276b28044d')
        self.assertEqual(md5(subtitles['it']), '0e0b667ba68411d88fd1c5f4f4eab2f9')



    #-------test2: test that the subtitles are correct language--------
    def test_language(self):

        #get all the subtites in a variable
        self.DL.params['writesubtitles'] = True
        self.DL.params['allsubtitles'] = True
        subtitles = self.getSubtitles()

        #test that the subtitles are not in any other language
        for lang in ['fr', 'de']:
            self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)


    #-------test3: test the auto captions--------
    def test_auto_captions(self):

        #get all the subtitiles inthe variable
        self.DL.params['writeautomaticsub'] = True
        self.DL.params['subtitleslangs'] = ['it']
        subtitles = self.getSubtitles()

        #test the automic capitions
        #self.assertTrue(subtitles['it'] is not None)



    #-------test4: test that chaning the format works properly--------
    def test_format(self):

        #get all the subtitles in a variable
        self.DL.params['writesubtitles'] = True
        self.DL.params['subtitlesformat'] = 'ttml'
        subtitles = self.getSubtitles()

        #assert that the format is still correct 
        self.assertEqual(md5(subtitles['en']), 'c97ddf1217390906fa9fbd34901f3da2')

        #get all the subtitles in a variable
        self.DL.params['writesubtitles'] = True
        self.DL.params['subtitlesformat'] = 'vtt'
        subtitles = self.getSubtitles()

        #assert that the format is still correct for vtt
        self.assertEqual(md5(subtitles['en']), 'c97dadgadf1217390906fa9fbd34901f3da2')
コード例 #41
0
 def test_youtube_user(self):
     dl = FakeYDL()
     ie = YoutubeUserIE(dl)
     result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')
     self.assertTrue(len(result['entries']) >= 320)
コード例 #42
0
 def setUp(self):
     self.ie = TestIE(FakeYDL())
コード例 #43
0
import sys
import os
import re

sys.path[:0] = ['.']

from youtube_dl.utils import ExtractorError
from youtube_dl.extractor.common import InfoExtractor
from test.helper import FakeYDL


class TestIE(InfoExtractor):
    pass


ie = TestIE(FakeYDL({'verbose': False}))
script_id = 'mastodon'
results = set()


def sanitize_hostname(hostname):
    # trim trailing slashes
    hostname = re.sub(r'[/\\]+$', '', hostname)
    # trim port number
    hostname = re.sub(r':\d+$', '', hostname)
    return hostname


instance_social_api_key = os.environ['INSTANCE_SOCIAL_API_SECRET']
if not instance_social_api_key:
    raise ExtractorError('You must set INSTANCE_SOCIAL_API_SECRET to work')
コード例 #44
0
 def setUp(self):
     self.DL = FakeYDL()
     self.ie = self.IE()
     self.DL.add_info_extractor(self.ie)
コード例 #45
0
 def test_youtube_toplist(self):
     dl = FakeYDL()
     ie = YoutubeTopListIE(dl)
     result = ie.extract('yttoplist:music:Trending')
     entries = result['entries']
     self.assertTrue(len(entries) >= 5)