]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_youtube_lists.py
Update changelog.
[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 )
19
20
21 class TestYoutubeLists(unittest.TestCase):
22 def assertIsPlaylist(self, info):
23 """Make sure the info has '_type' set to 'playlist'"""
24 self.assertEqual(info['_type'], 'playlist')
25
26 def test_youtube_playlist(self):
27 dl = FakeYDL()
28 ie = YoutubePlaylistIE(dl)
29 result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
30 self.assertIsPlaylist(result)
31 self.assertEqual(result['title'], 'ytdl test PL')
32 ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']]
33 self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
34
35 def test_youtube_playlist_noplaylist(self):
36 dl = FakeYDL()
37 dl.params['noplaylist'] = True
38 ie = YoutubePlaylistIE(dl)
39 result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
40 self.assertEqual(result['_type'], 'url')
41 self.assertEqual(YoutubeIE()._extract_id(result['url']), 'FXxLjLQi3Fg')
42
43 def test_issue_673(self):
44 dl = FakeYDL()
45 ie = YoutubePlaylistIE(dl)
46 result = ie.extract('PLBB231211A4F62143')
47 self.assertTrue(len(result['entries']) > 25)
48
49 def test_youtube_playlist_long(self):
50 dl = FakeYDL()
51 ie = YoutubePlaylistIE(dl)
52 result = ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
53 self.assertIsPlaylist(result)
54 self.assertTrue(len(result['entries']) >= 799)
55
56 def test_youtube_playlist_with_deleted(self):
57 #651
58 dl = FakeYDL()
59 ie = YoutubePlaylistIE(dl)
60 result = ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
61 ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']]
62 self.assertFalse('pElCt5oNDuI' in ytie_results)
63 self.assertFalse('KdPEApIVdWM' in ytie_results)
64
65 def test_youtube_playlist_empty(self):
66 dl = FakeYDL()
67 ie = YoutubePlaylistIE(dl)
68 result = ie.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')
69 self.assertIsPlaylist(result)
70 self.assertEqual(len(result['entries']), 0)
71
72 def test_youtube_course(self):
73 dl = FakeYDL()
74 ie = YoutubePlaylistIE(dl)
75 # TODO find a > 100 (paginating?) videos course
76 result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
77 entries = result['entries']
78 self.assertEqual(YoutubeIE()._extract_id(entries[0]['url']), 'j9WZyLZCBzs')
79 self.assertEqual(len(entries), 25)
80 self.assertEqual(YoutubeIE()._extract_id(entries[-1]['url']), 'rYefUsYuEp0')
81
82 def test_youtube_channel(self):
83 dl = FakeYDL()
84 ie = YoutubeChannelIE(dl)
85 #test paginated channel
86 result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')
87 self.assertTrue(len(result['entries']) > 90)
88 #test autogenerated channel
89 result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
90 self.assertTrue(len(result['entries']) >= 18)
91
92 def test_youtube_user(self):
93 dl = FakeYDL()
94 ie = YoutubeUserIE(dl)
95 result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')
96 self.assertTrue(len(result['entries']) >= 320)
97
98 def test_youtube_safe_search(self):
99 dl = FakeYDL()
100 ie = YoutubePlaylistIE(dl)
101 result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')
102 self.assertEqual(len(result['entries']), 2)
103
104 def test_youtube_show(self):
105 dl = FakeYDL()
106 ie = YoutubeShowIE(dl)
107 result = ie.extract('http://www.youtube.com/show/airdisasters')
108 self.assertTrue(len(result) >= 3)
109
110 def test_youtube_mix(self):
111 dl = FakeYDL()
112 ie = YoutubePlaylistIE(dl)
113 result = ie.extract('http://www.youtube.com/watch?v=lLJf9qJHR3E&list=RDrjFaenf1T-Y')
114 entries = result['entries']
115 self.assertTrue(len(entries) >= 20)
116 original_video = entries[0]
117 self.assertEqual(original_video['id'], 'rjFaenf1T-Y')
118
119 if __name__ == '__main__':
120 unittest.main()