3 # Allow direct execution
7 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9 from test.helper import FakeYDL
12 from youtube_dl.extractor import (
23 class TestYoutubeLists(unittest.TestCase):
24 def assertIsPlaylist(self, info):
25 """Make sure the info has '_type' set to 'playlist'"""
26 self.assertEqual(info['_type'], 'playlist')
28 def test_youtube_playlist_noplaylist(self):
30 dl.params['noplaylist'] = True
31 ie = YoutubePlaylistIE(dl)
32 result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
33 self.assertEqual(result['_type'], 'url')
34 self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg')
36 def test_youtube_course(self):
38 ie = YoutubePlaylistIE(dl)
39 # TODO find a > 100 (paginating?) videos course
40 result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
41 entries = result['entries']
42 self.assertEqual(YoutubeIE().extract_id(entries[0]['url']), 'j9WZyLZCBzs')
43 self.assertEqual(len(entries), 25)
44 self.assertEqual(YoutubeIE().extract_id(entries[-1]['url']), 'rYefUsYuEp0')
46 def test_youtube_channel(self):
48 ie = YoutubeChannelIE(dl)
49 #test paginated channel
50 result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')
51 self.assertTrue(len(result['entries']) > 90)
52 #test autogenerated channel
53 result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
54 self.assertTrue(len(result['entries']) >= 18)
56 def test_youtube_user(self):
58 ie = YoutubeUserIE(dl)
59 result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')
60 self.assertTrue(len(result['entries']) >= 320)
62 def test_youtube_show(self):
64 ie = YoutubeShowIE(dl)
65 result = ie.extract('http://www.youtube.com/show/airdisasters')
66 self.assertTrue(len(result) >= 3)
68 def test_youtube_mix(self):
70 ie = YoutubePlaylistIE(dl)
71 result = ie.extract('https://www.youtube.com/watch?v=W01L70IGBgE&index=2&list=RDOQpdSVF_k_w')
72 entries = result['entries']
73 self.assertTrue(len(entries) >= 20)
74 original_video = entries[0]
75 self.assertEqual(original_video['id'], 'OQpdSVF_k_w')
77 def test_youtube_toptracks(self):
78 print('Skipping: The playlist page gives error 500')
81 ie = YoutubePlaylistIE(dl)
82 result = ie.extract('https://www.youtube.com/playlist?list=MCUS')
83 entries = result['entries']
84 self.assertEqual(len(entries), 100)
86 def test_youtube_toplist(self):
88 ie = YoutubeTopListIE(dl)
89 result = ie.extract('yttoplist:music:Trending')
90 entries = result['entries']
91 self.assertTrue(len(entries) >= 5)
93 def test_youtube_search_url(self):
95 ie = YoutubeSearchURLIE(dl)
96 result = ie.extract('https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video')
97 entries = result['entries']
98 self.assertIsPlaylist(result)
99 self.assertEqual(result['title'], 'youtube-dl test video')
100 self.assertTrue(len(entries) >= 5)
102 if __name__ == '__main__':