]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_youtube_lists.py
Prepare for upload.
[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, global_setup
10 global_setup()
11
12
13 from youtube_dl.extractor import (
14 YoutubeUserIE,
15 YoutubePlaylistIE,
16 YoutubeIE,
17 YoutubeChannelIE,
18 YoutubeShowIE,
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')[0]
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')[0]
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')[0]
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')[0]
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')[0]
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')[0]
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')[0]
88 self.assertTrue(len(result['entries']) > 90)
89 #test autogenerated channel
90 result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')[0]
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')[0]
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')[0]
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 if __name__ == '__main__':
112 unittest.main()