]>
Commit | Line | Data |
---|---|---|
9789a05c FV |
1 | #!/usr/bin/env python |
2 | ||
44a5f171 PH |
3 | # Allow direct execution |
4 | import os | |
9789a05c FV |
5 | import sys |
6 | import unittest | |
44a5f171 PH |
7 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
8 | ||
d0efb9ec | 9 | from test.helper import FakeYDL |
9789a05c | 10 | |
9789a05c | 11 | |
44a5f171 PH |
12 | from youtube_dl.extractor import ( |
13 | YoutubeUserIE, | |
14 | YoutubePlaylistIE, | |
15 | YoutubeIE, | |
16 | YoutubeChannelIE, | |
17 | YoutubeShowIE, | |
0a688bc0 | 18 | YoutubeTopListIE, |
c9ae7b95 | 19 | YoutubeSearchURLIE, |
44a5f171 | 20 | ) |
9789a05c | 21 | |
9789a05c FV |
22 | |
23 | class TestYoutubeLists(unittest.TestCase): | |
44a5f171 | 24 | def assertIsPlaylist(self, info): |
8a38a194 JMF |
25 | """Make sure the info has '_type' set to 'playlist'""" |
26 | self.assertEqual(info['_type'], 'playlist') | |
27 | ||
d4d9920a FV |
28 | def test_youtube_playlist_noplaylist(self): |
29 | dl = FakeYDL() | |
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') | |
97665381 | 34 | self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg') |
9291475f | 35 | |
9789a05c | 36 | def test_youtube_course(self): |
8bf8b5a5 | 37 | dl = FakeYDL() |
679790ee | 38 | ie = YoutubePlaylistIE(dl) |
9789a05c | 39 | # TODO find a > 100 (paginating?) videos course |
dcbb4580 | 40 | result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8') |
8a38a194 | 41 | entries = result['entries'] |
97665381 | 42 | self.assertEqual(YoutubeIE().extract_id(entries[0]['url']), 'j9WZyLZCBzs') |
8a38a194 | 43 | self.assertEqual(len(entries), 25) |
97665381 | 44 | self.assertEqual(YoutubeIE().extract_id(entries[-1]['url']), 'rYefUsYuEp0') |
9789a05c FV |
45 | |
46 | def test_youtube_channel(self): | |
8bf8b5a5 | 47 | dl = FakeYDL() |
fb6c3199 | 48 | ie = YoutubeChannelIE(dl) |
49 | #test paginated channel | |
7012b23c | 50 | result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w') |
fb6c3199 | 51 | self.assertTrue(len(result['entries']) > 90) |
52 | #test autogenerated channel | |
7012b23c | 53 | result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos') |
96655778 | 54 | self.assertTrue(len(result['entries']) >= 18) |
9789a05c FV |
55 | |
56 | def test_youtube_user(self): | |
8bf8b5a5 | 57 | dl = FakeYDL() |
679790ee | 58 | ie = YoutubeUserIE(dl) |
7012b23c | 59 | result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation') |
8a38a194 | 60 | self.assertTrue(len(result['entries']) >= 320) |
9789a05c | 61 | |
75dff0ee JMF |
62 | def test_youtube_show(self): |
63 | dl = FakeYDL() | |
64 | ie = YoutubeShowIE(dl) | |
65 | result = ie.extract('http://www.youtube.com/show/airdisasters') | |
e772692f | 66 | self.assertTrue(len(result) >= 3) |
75dff0ee | 67 | |
652cdaa2 JMF |
68 | def test_youtube_mix(self): |
69 | dl = FakeYDL() | |
70 | ie = YoutubePlaylistIE(dl) | |
24577db2 | 71 | result = ie.extract('https://www.youtube.com/watch?v=W01L70IGBgE&index=2&list=RDOQpdSVF_k_w') |
652cdaa2 JMF |
72 | entries = result['entries'] |
73 | self.assertTrue(len(entries) >= 20) | |
74 | original_video = entries[0] | |
24577db2 | 75 | self.assertEqual(original_video['id'], 'OQpdSVF_k_w') |
652cdaa2 | 76 | |
d67cc9fa | 77 | def test_youtube_toptracks(self): |
ea5a0be8 JMF |
78 | print('Skipping: The playlist page gives error 500') |
79 | return | |
d67cc9fa JMF |
80 | dl = FakeYDL() |
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) | |
85 | ||
0a688bc0 JMF |
86 | def test_youtube_toplist(self): |
87 | dl = FakeYDL() | |
88 | ie = YoutubeTopListIE(dl) | |
48f9678a | 89 | result = ie.extract('yttoplist:music:Trending') |
0a688bc0 | 90 | entries = result['entries'] |
97788746 | 91 | self.assertTrue(len(entries) >= 5) |
0a688bc0 | 92 | |
c9ae7b95 PH |
93 | def test_youtube_search_url(self): |
94 | dl = FakeYDL() | |
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) | |
101 | ||
9789a05c FV |
102 | if __name__ == '__main__': |
103 | unittest.main() |