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