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