]> jfr.im git - yt-dlp.git/blame - test/test_youtube_lists.py
Use the new '_download_xml' helper in more extractors
[yt-dlp.git] / test / test_youtube_lists.py
CommitLineData
9789a05c
FV
1#!/usr/bin/env python
2
44a5f171
PH
3# Allow direct execution
4import os
9789a05c
FV
5import sys
6import unittest
44a5f171
PH
7sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8
d0efb9ec 9from test.helper import FakeYDL
9789a05c 10
9789a05c 11
44a5f171
PH
12from youtube_dl.extractor import (
13 YoutubeUserIE,
14 YoutubePlaylistIE,
15 YoutubeIE,
16 YoutubeChannelIE,
17 YoutubeShowIE,
18)
9789a05c 19
9789a05c
FV
20
21class TestYoutubeLists(unittest.TestCase):
44a5f171 22 def assertIsPlaylist(self, info):
8a38a194
JMF
23 """Make sure the info has '_type' set to 'playlist'"""
24 self.assertEqual(info['_type'], 'playlist')
25
9789a05c 26 def test_youtube_playlist(self):
8bf8b5a5 27 dl = FakeYDL()
679790ee 28 ie = YoutubePlaylistIE(dl)
dcbb4580 29 result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
8a38a194 30 self.assertIsPlaylist(result)
c7293824 31 self.assertEqual(result['title'], 'ytdl test PL')
8a38a194 32 ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']]
acb8752f 33 self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
9789a05c 34
d4d9920a
FV
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')
7c61bd36 41 self.assertEqual(YoutubeIE()._extract_id(result['url']), 'FXxLjLQi3Fg')
d4d9920a 42
acb8752f 43 def test_issue_673(self):
8bf8b5a5 44 dl = FakeYDL()
679790ee 45 ie = YoutubePlaylistIE(dl)
dcbb4580 46 result = ie.extract('PLBB231211A4F62143')
31513ea6 47 self.assertTrue(len(result['entries']) > 25)
89de9eb1 48
9789a05c 49 def test_youtube_playlist_long(self):
8bf8b5a5 50 dl = FakeYDL()
679790ee 51 ie = YoutubePlaylistIE(dl)
dcbb4580 52 result = ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
8a38a194
JMF
53 self.assertIsPlaylist(result)
54 self.assertTrue(len(result['entries']) >= 799)
9789a05c 55
6324fd1d 56 def test_youtube_playlist_with_deleted(self):
89de9eb1 57 #651
8bf8b5a5 58 dl = FakeYDL()
679790ee 59 ie = YoutubePlaylistIE(dl)
dcbb4580 60 result = ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
8a38a194 61 ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']]
acb8752f
PH
62 self.assertFalse('pElCt5oNDuI' in ytie_results)
63 self.assertFalse('KdPEApIVdWM' in ytie_results)
aba8df23
JMF
64
65 def test_youtube_playlist_empty(self):
8bf8b5a5 66 dl = FakeYDL()
aba8df23 67 ie = YoutubePlaylistIE(dl)
dcbb4580 68 result = ie.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')
aba8df23
JMF
69 self.assertIsPlaylist(result)
70 self.assertEqual(len(result['entries']), 0)
6324fd1d 71
9789a05c 72 def test_youtube_course(self):
8bf8b5a5 73 dl = FakeYDL()
679790ee 74 ie = YoutubePlaylistIE(dl)
9789a05c 75 # TODO find a > 100 (paginating?) videos course
dcbb4580 76 result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
8a38a194
JMF
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')
9789a05c
FV
81
82 def test_youtube_channel(self):
8bf8b5a5 83 dl = FakeYDL()
fb6c3199 84 ie = YoutubeChannelIE(dl)
85 #test paginated channel
7012b23c 86 result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')
fb6c3199 87 self.assertTrue(len(result['entries']) > 90)
88 #test autogenerated channel
7012b23c 89 result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
96655778 90 self.assertTrue(len(result['entries']) >= 18)
9789a05c
FV
91
92 def test_youtube_user(self):
8bf8b5a5 93 dl = FakeYDL()
679790ee 94 ie = YoutubeUserIE(dl)
7012b23c 95 result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')
8a38a194 96 self.assertTrue(len(result['entries']) >= 320)
9789a05c 97
213b7158 98 def test_youtube_safe_search(self):
8bf8b5a5 99 dl = FakeYDL()
213b7158 100 ie = YoutubePlaylistIE(dl)
dcbb4580 101 result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')
213b7158
JMF
102 self.assertEqual(len(result['entries']), 2)
103
75dff0ee
JMF
104 def test_youtube_show(self):
105 dl = FakeYDL()
106 ie = YoutubeShowIE(dl)
107 result = ie.extract('http://www.youtube.com/show/airdisasters')
e772692f 108 self.assertTrue(len(result) >= 3)
75dff0ee 109
9789a05c
FV
110if __name__ == '__main__':
111 unittest.main()