]>
jfr.im git - yt-dlp.git/blob - test/test_youtube_lists.py
3 # Allow direct execution
7 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
9 from test
.helper
import FakeYDL
12 from youtube_dl
.extractor
import (
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')
26 def test_youtube_playlist(self
):
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'])
35 def test_youtube_playlist_noplaylist(self
):
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')
43 def test_issue_673(self
):
45 ie
= YoutubePlaylistIE(dl
)
46 result
= ie
.extract('PLBB231211A4F62143')
47 self
.assertTrue(len(result
['entries']) > 25)
49 def test_youtube_playlist_long(self
):
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)
56 def test_youtube_playlist_with_deleted(self
):
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
)
65 def test_youtube_playlist_empty(self
):
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)
72 def test_youtube_course(self
):
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')
82 def test_youtube_channel(self
):
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)
92 def test_youtube_user(self
):
94 ie
= YoutubeUserIE(dl
)
95 result
= ie
.extract('https://www.youtube.com/user/TheLinuxFoundation')
96 self
.assertTrue(len(result
['entries']) >= 320)
98 def test_youtube_safe_search(self
):
100 ie
= YoutubePlaylistIE(dl
)
101 result
= ie
.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')
102 self
.assertEqual(len(result
['entries']), 2)
104 def test_youtube_show(self
):
106 ie
= YoutubeShowIE(dl
)
107 result
= ie
.extract('http://www.youtube.com/show/airdisasters')
108 self
.assertTrue(len(result
) >= 3)
110 if __name__
== '__main__':