]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_youtube_lists.py
Start new release.
[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 YoutubeSearchURLIE,
20 )
21
22
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')
27
28 def test_youtube_playlist(self):
29 dl = FakeYDL()
30 ie = YoutubePlaylistIE(dl)
31 result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
32 self.assertIsPlaylist(result)
33 self.assertEqual(result['title'], 'ytdl test PL')
34 ytie_results = [YoutubeIE().extract_id(url['url']) for url in result['entries']]
35 self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
36
37 def test_youtube_playlist_noplaylist(self):
38 dl = FakeYDL()
39 dl.params['noplaylist'] = True
40 ie = YoutubePlaylistIE(dl)
41 result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
42 self.assertEqual(result['_type'], 'url')
43 self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg')
44
45 def test_issue_673(self):
46 dl = FakeYDL()
47 ie = YoutubePlaylistIE(dl)
48 result = ie.extract('PLBB231211A4F62143')
49 self.assertTrue(len(result['entries']) > 25)
50
51 def test_youtube_playlist_long(self):
52 dl = FakeYDL()
53 ie = YoutubePlaylistIE(dl)
54 result = ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
55 self.assertIsPlaylist(result)
56 self.assertTrue(len(result['entries']) >= 799)
57
58 def test_youtube_playlist_with_deleted(self):
59 #651
60 dl = FakeYDL()
61 ie = YoutubePlaylistIE(dl)
62 result = ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
63 ytie_results = [YoutubeIE().extract_id(url['url']) for url in result['entries']]
64 self.assertFalse('pElCt5oNDuI' in ytie_results)
65 self.assertFalse('KdPEApIVdWM' in ytie_results)
66
67 def test_youtube_playlist_empty(self):
68 dl = FakeYDL()
69 ie = YoutubePlaylistIE(dl)
70 result = ie.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')
71 self.assertIsPlaylist(result)
72 self.assertEqual(len(result['entries']), 0)
73
74 def test_youtube_course(self):
75 dl = FakeYDL()
76 ie = YoutubePlaylistIE(dl)
77 # TODO find a > 100 (paginating?) videos course
78 result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
79 entries = result['entries']
80 self.assertEqual(YoutubeIE().extract_id(entries[0]['url']), 'j9WZyLZCBzs')
81 self.assertEqual(len(entries), 25)
82 self.assertEqual(YoutubeIE().extract_id(entries[-1]['url']), 'rYefUsYuEp0')
83
84 def test_youtube_channel(self):
85 dl = FakeYDL()
86 ie = YoutubeChannelIE(dl)
87 #test paginated channel
88 result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')
89 self.assertTrue(len(result['entries']) > 90)
90 #test autogenerated channel
91 result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
92 self.assertTrue(len(result['entries']) >= 18)
93
94 def test_youtube_user(self):
95 dl = FakeYDL()
96 ie = YoutubeUserIE(dl)
97 result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')
98 self.assertTrue(len(result['entries']) >= 320)
99
100 def test_youtube_safe_search(self):
101 dl = FakeYDL()
102 ie = YoutubePlaylistIE(dl)
103 result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')
104 self.assertEqual(len(result['entries']), 2)
105
106 def test_youtube_show(self):
107 dl = FakeYDL()
108 ie = YoutubeShowIE(dl)
109 result = ie.extract('http://www.youtube.com/show/airdisasters')
110 self.assertTrue(len(result) >= 3)
111
112 def test_youtube_mix(self):
113 dl = FakeYDL()
114 ie = YoutubePlaylistIE(dl)
115 result = ie.extract('https://www.youtube.com/watch?v=W01L70IGBgE&index=2&list=RDOQpdSVF_k_w')
116 entries = result['entries']
117 self.assertTrue(len(entries) >= 20)
118 original_video = entries[0]
119 self.assertEqual(original_video['id'], 'OQpdSVF_k_w')
120
121 def test_youtube_toptracks(self):
122 print('Skipping: The playlist page gives error 500')
123 return
124 dl = FakeYDL()
125 ie = YoutubePlaylistIE(dl)
126 result = ie.extract('https://www.youtube.com/playlist?list=MCUS')
127 entries = result['entries']
128 self.assertEqual(len(entries), 100)
129
130 def test_youtube_toplist(self):
131 dl = FakeYDL()
132 ie = YoutubeTopListIE(dl)
133 result = ie.extract('yttoplist:music:Trending')
134 entries = result['entries']
135 self.assertTrue(len(entries) >= 5)
136
137 def test_youtube_search_url(self):
138 dl = FakeYDL()
139 ie = YoutubeSearchURLIE(dl)
140 result = ie.extract('https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video')
141 entries = result['entries']
142 self.assertIsPlaylist(result)
143 self.assertEqual(result['title'], 'youtube-dl test video')
144 self.assertTrue(len(entries) >= 5)
145
146 if __name__ == '__main__':
147 unittest.main()