]>
Raphaƫl G. Git Repositories - youtubedl/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 (
23 class TestYoutubeLists(unittest
.TestCase
):
24 def assertIsPlaylist(self
, info
):
25 """Make sure the info has '_type' set to 'playlist'"""
26 self
.assertEqual(info
['_type'], 'playlist')
28 def test_youtube_playlist(self
):
30 ie
= YoutubePlaylistIE(dl
)
31 result
= ie
.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
32 self
.assertIsPlaylist(result
)
33 self
.assertEqual(result
['title'], 'ytdl test PL')
34 ytie_results
= [YoutubeIE().extract_id(url
['url']) for url
in result
['entries']]
35 self
.assertEqual(ytie_results
, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
37 def test_youtube_playlist_noplaylist(self
):
39 dl
.params
['noplaylist'] = True
40 ie
= YoutubePlaylistIE(dl
)
41 result
= ie
.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
42 self
.assertEqual(result
['_type'], 'url')
43 self
.assertEqual(YoutubeIE().extract_id(result
['url']), 'FXxLjLQi3Fg')
45 def test_issue_673(self
):
47 ie
= YoutubePlaylistIE(dl
)
48 result
= ie
.extract('PLBB231211A4F62143')
49 self
.assertTrue(len(result
['entries']) > 25)
51 def test_youtube_playlist_long(self
):
53 ie
= YoutubePlaylistIE(dl
)
54 result
= ie
.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
55 self
.assertIsPlaylist(result
)
56 self
.assertTrue(len(result
['entries']) >= 799)
58 def test_youtube_playlist_with_deleted(self
):
61 ie
= YoutubePlaylistIE(dl
)
62 result
= ie
.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
63 ytie_results
= [YoutubeIE().extract_id(url
['url']) for url
in result
['entries']]
64 self
.assertFalse('pElCt5oNDuI' in ytie_results
)
65 self
.assertFalse('KdPEApIVdWM' in ytie_results
)
67 def test_youtube_playlist_empty(self
):
69 ie
= YoutubePlaylistIE(dl
)
70 result
= ie
.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')
71 self
.assertIsPlaylist(result
)
72 self
.assertEqual(len(result
['entries']), 0)
74 def test_youtube_course(self
):
76 ie
= YoutubePlaylistIE(dl
)
77 # TODO find a > 100 (paginating?) videos course
78 result
= ie
.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
79 entries
= result
['entries']
80 self
.assertEqual(YoutubeIE().extract_id(entries
[0]['url']), 'j9WZyLZCBzs')
81 self
.assertEqual(len(entries
), 25)
82 self
.assertEqual(YoutubeIE().extract_id(entries
[-1]['url']), 'rYefUsYuEp0')
84 def test_youtube_channel(self
):
86 ie
= YoutubeChannelIE(dl
)
87 #test paginated channel
88 result
= ie
.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')
89 self
.assertTrue(len(result
['entries']) > 90)
90 #test autogenerated channel
91 result
= ie
.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
92 self
.assertTrue(len(result
['entries']) >= 18)
94 def test_youtube_user(self
):
96 ie
= YoutubeUserIE(dl
)
97 result
= ie
.extract('https://www.youtube.com/user/TheLinuxFoundation')
98 self
.assertTrue(len(result
['entries']) >= 320)
100 def test_youtube_safe_search(self
):
102 ie
= YoutubePlaylistIE(dl
)
103 result
= ie
.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')
104 self
.assertEqual(len(result
['entries']), 2)
106 def test_youtube_show(self
):
108 ie
= YoutubeShowIE(dl
)
109 result
= ie
.extract('http://www.youtube.com/show/airdisasters')
110 self
.assertTrue(len(result
) >= 3)
112 def test_youtube_mix(self
):
114 ie
= YoutubePlaylistIE(dl
)
115 result
= ie
.extract('https://www.youtube.com/watch?v=W01L70IGBgE&index=2&list=RDOQpdSVF_k_w')
116 entries
= result
['entries']
117 self
.assertTrue(len(entries
) >= 20)
118 original_video
= entries
[0]
119 self
.assertEqual(original_video
['id'], 'OQpdSVF_k_w')
121 def test_youtube_toptracks(self
):
122 print('Skipping: The playlist page gives error 500')
125 ie
= YoutubePlaylistIE(dl
)
126 result
= ie
.extract('https://www.youtube.com/playlist?list=MCUS')
127 entries
= result
['entries']
128 self
.assertEqual(len(entries
), 100)
130 def test_youtube_toplist(self
):
132 ie
= YoutubeTopListIE(dl
)
133 result
= ie
.extract('yttoplist:music:Trending')
134 entries
= result
['entries']
135 self
.assertTrue(len(entries
) >= 5)
137 def test_youtube_search_url(self
):
139 ie
= YoutubeSearchURLIE(dl
)
140 result
= ie
.extract('https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video')
141 entries
= result
['entries']
142 self
.assertIsPlaylist(result
)
143 self
.assertEqual(result
['title'], 'youtube-dl test video')
144 self
.assertTrue(len(entries
) >= 5)
146 if __name__
== '__main__':