]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_youtube_lists.py
38ac989ce706a347e575f62a9dd6b60b8fece8c9
[youtubedl] / test / test_youtube_lists.py
1 #!/usr/bin/env python
2
3 # Allow direct execution
4 import os
5 import sys
6 import unittest
7 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8
9 from test.helper import FakeYDL
10
11
12 from youtube_dl.extractor import (
13 YoutubeUserIE,
14 YoutubePlaylistIE,
15 YoutubeIE,
16 YoutubeChannelIE,
17 YoutubeShowIE,
18 YoutubeTopListIE,
19 )
20
21
22 class TestYoutubeLists(unittest.TestCase):
23 def assertIsPlaylist(self, info):
24 """Make sure the info has '_type' set to 'playlist'"""
25 self.assertEqual(info['_type'], 'playlist')
26
27 def test_youtube_playlist(self):
28 dl = FakeYDL()
29 ie = YoutubePlaylistIE(dl)
30 result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
31 self.assertIsPlaylist(result)
32 self.assertEqual(result['title'], 'ytdl test PL')
33 ytie_results = [YoutubeIE().extract_id(url['url']) for url in result['entries']]
34 self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
35
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')
42 self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg')
43
44 def test_issue_673(self):
45 dl = FakeYDL()
46 ie = YoutubePlaylistIE(dl)
47 result = ie.extract('PLBB231211A4F62143')
48 self.assertTrue(len(result['entries']) > 25)
49
50 def test_youtube_playlist_long(self):
51 dl = FakeYDL()
52 ie = YoutubePlaylistIE(dl)
53 result = ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
54 self.assertIsPlaylist(result)
55 self.assertTrue(len(result['entries']) >= 799)
56
57 def test_youtube_playlist_with_deleted(self):
58 #651
59 dl = FakeYDL()
60 ie = YoutubePlaylistIE(dl)
61 result = ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
62 ytie_results = [YoutubeIE().extract_id(url['url']) for url in result['entries']]
63 self.assertFalse('pElCt5oNDuI' in ytie_results)
64 self.assertFalse('KdPEApIVdWM' in ytie_results)
65
66 def test_youtube_playlist_empty(self):
67 dl = FakeYDL()
68 ie = YoutubePlaylistIE(dl)
69 result = ie.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')
70 self.assertIsPlaylist(result)
71 self.assertEqual(len(result['entries']), 0)
72
73 def test_youtube_course(self):
74 dl = FakeYDL()
75 ie = YoutubePlaylistIE(dl)
76 # TODO find a > 100 (paginating?) videos course
77 result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
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')
82
83 def test_youtube_channel(self):
84 dl = FakeYDL()
85 ie = YoutubeChannelIE(dl)
86 #test paginated channel
87 result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')
88 self.assertTrue(len(result['entries']) > 90)
89 #test autogenerated channel
90 result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
91 self.assertTrue(len(result['entries']) >= 18)
92
93 def test_youtube_user(self):
94 dl = FakeYDL()
95 ie = YoutubeUserIE(dl)
96 result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')
97 self.assertTrue(len(result['entries']) >= 320)
98
99 def test_youtube_safe_search(self):
100 dl = FakeYDL()
101 ie = YoutubePlaylistIE(dl)
102 result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')
103 self.assertEqual(len(result['entries']), 2)
104
105 def test_youtube_show(self):
106 dl = FakeYDL()
107 ie = YoutubeShowIE(dl)
108 result = ie.extract('http://www.youtube.com/show/airdisasters')
109 self.assertTrue(len(result) >= 3)
110
111 def test_youtube_mix(self):
112 dl = FakeYDL()
113 ie = YoutubePlaylistIE(dl)
114 result = ie.extract('http://www.youtube.com/watch?v=lLJf9qJHR3E&list=RDrjFaenf1T-Y')
115 entries = result['entries']
116 self.assertTrue(len(entries) >= 20)
117 original_video = entries[0]
118 self.assertEqual(original_video['id'], 'rjFaenf1T-Y')
119
120 def test_youtube_toptracks(self):
121 dl = FakeYDL()
122 ie = YoutubePlaylistIE(dl)
123 result = ie.extract('https://www.youtube.com/playlist?list=MCUS')
124 entries = result['entries']
125 self.assertEqual(len(entries), 100)
126
127 def test_youtube_toplist(self):
128 dl = FakeYDL()
129 ie = YoutubeTopListIE(dl)
130 result = ie.extract('yttoplist:music:Trending')
131 entries = result['entries']
132 self.assertTrue(len(entries) >= 5)
133
134 if __name__ == '__main__':
135 unittest.main()