]>
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 | ||
9 | from test.helper import FakeYDL, global_setup | |
10 | global_setup() | |
9789a05c | 11 | |
9789a05c | 12 | |
44a5f171 PH |
13 | from youtube_dl.extractor import ( |
14 | YoutubeUserIE, | |
15 | YoutubePlaylistIE, | |
16 | YoutubeIE, | |
17 | YoutubeChannelIE, | |
18 | YoutubeShowIE, | |
19 | ) | |
9789a05c | 20 | |
9789a05c FV |
21 | |
22 | class TestYoutubeLists(unittest.TestCase): | |
44a5f171 | 23 | def assertIsPlaylist(self, info): |
8a38a194 JMF |
24 | """Make sure the info has '_type' set to 'playlist'""" |
25 | self.assertEqual(info['_type'], 'playlist') | |
26 | ||
9789a05c | 27 | def test_youtube_playlist(self): |
8bf8b5a5 | 28 | dl = FakeYDL() |
679790ee | 29 | ie = YoutubePlaylistIE(dl) |
dcbb4580 | 30 | result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re') |
8a38a194 | 31 | self.assertIsPlaylist(result) |
c7293824 | 32 | self.assertEqual(result['title'], 'ytdl test PL') |
8a38a194 | 33 | ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']] |
acb8752f | 34 | self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE']) |
9789a05c | 35 | |
d4d9920a FV |
36 | def test_youtube_playlist_noplaylist(self): |
37 | dl = FakeYDL() | |
38 | dl.params['noplaylist'] = True | |
39 | ie = YoutubePlaylistIE(dl) | |
40 | result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re') | |
41 | self.assertEqual(result['_type'], 'url') | |
7c61bd36 | 42 | self.assertEqual(YoutubeIE()._extract_id(result['url']), 'FXxLjLQi3Fg') |
d4d9920a | 43 | |
acb8752f | 44 | def test_issue_673(self): |
8bf8b5a5 | 45 | dl = FakeYDL() |
679790ee | 46 | ie = YoutubePlaylistIE(dl) |
dcbb4580 | 47 | result = ie.extract('PLBB231211A4F62143') |
31513ea6 | 48 | self.assertTrue(len(result['entries']) > 25) |
89de9eb1 | 49 | |
9789a05c | 50 | def test_youtube_playlist_long(self): |
8bf8b5a5 | 51 | dl = FakeYDL() |
679790ee | 52 | ie = YoutubePlaylistIE(dl) |
dcbb4580 | 53 | result = ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q') |
8a38a194 JMF |
54 | self.assertIsPlaylist(result) |
55 | self.assertTrue(len(result['entries']) >= 799) | |
9789a05c | 56 | |
6324fd1d | 57 | def test_youtube_playlist_with_deleted(self): |
89de9eb1 | 58 | #651 |
8bf8b5a5 | 59 | dl = FakeYDL() |
679790ee | 60 | ie = YoutubePlaylistIE(dl) |
dcbb4580 | 61 | result = ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC') |
8a38a194 | 62 | ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']] |
acb8752f PH |
63 | self.assertFalse('pElCt5oNDuI' in ytie_results) |
64 | self.assertFalse('KdPEApIVdWM' in ytie_results) | |
aba8df23 JMF |
65 | |
66 | def test_youtube_playlist_empty(self): | |
8bf8b5a5 | 67 | dl = FakeYDL() |
aba8df23 | 68 | ie = YoutubePlaylistIE(dl) |
dcbb4580 | 69 | result = ie.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx') |
aba8df23 JMF |
70 | self.assertIsPlaylist(result) |
71 | self.assertEqual(len(result['entries']), 0) | |
6324fd1d | 72 | |
9789a05c | 73 | def test_youtube_course(self): |
8bf8b5a5 | 74 | dl = FakeYDL() |
679790ee | 75 | ie = YoutubePlaylistIE(dl) |
9789a05c | 76 | # TODO find a > 100 (paginating?) videos course |
dcbb4580 | 77 | result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8') |
8a38a194 JMF |
78 | entries = result['entries'] |
79 | self.assertEqual(YoutubeIE()._extract_id(entries[0]['url']), 'j9WZyLZCBzs') | |
80 | self.assertEqual(len(entries), 25) | |
81 | self.assertEqual(YoutubeIE()._extract_id(entries[-1]['url']), 'rYefUsYuEp0') | |
9789a05c FV |
82 | |
83 | def test_youtube_channel(self): | |
8bf8b5a5 | 84 | dl = FakeYDL() |
fb6c3199 | 85 | ie = YoutubeChannelIE(dl) |
86 | #test paginated channel | |
87 | result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')[0] | |
88 | self.assertTrue(len(result['entries']) > 90) | |
89 | #test autogenerated channel | |
90 | result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')[0] | |
96655778 | 91 | self.assertTrue(len(result['entries']) >= 18) |
9789a05c FV |
92 | |
93 | def test_youtube_user(self): | |
8bf8b5a5 | 94 | dl = FakeYDL() |
679790ee | 95 | ie = YoutubeUserIE(dl) |
8a38a194 JMF |
96 | result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')[0] |
97 | self.assertTrue(len(result['entries']) >= 320) | |
9789a05c | 98 | |
213b7158 | 99 | def test_youtube_safe_search(self): |
8bf8b5a5 | 100 | dl = FakeYDL() |
213b7158 | 101 | ie = YoutubePlaylistIE(dl) |
dcbb4580 | 102 | result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl') |
213b7158 JMF |
103 | self.assertEqual(len(result['entries']), 2) |
104 | ||
75dff0ee JMF |
105 | def test_youtube_show(self): |
106 | dl = FakeYDL() | |
107 | ie = YoutubeShowIE(dl) | |
108 | result = ie.extract('http://www.youtube.com/show/airdisasters') | |
e772692f | 109 | self.assertTrue(len(result) >= 3) |
75dff0ee | 110 | |
9789a05c FV |
111 | if __name__ == '__main__': |
112 | unittest.main() |