]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_youtube_lists.py
d9fe5af4eec5fe791fce6d7fc06a6efb262213e4
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 (
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')
27 def test_youtube_playlist(self
):
29 ie
= YoutubePlaylistIE(dl
)
30 result
= ie
.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
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'])
36 def test_youtube_playlist_noplaylist(self
):
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')
44 def test_issue_673(self
):
46 ie
= YoutubePlaylistIE(dl
)
47 result
= ie
.extract('PLBB231211A4F62143')
48 self
.assertTrue(len(result
['entries']) > 25)
50 def test_youtube_playlist_long(self
):
52 ie
= YoutubePlaylistIE(dl
)
53 result
= ie
.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
54 self
.assertIsPlaylist(result
)
55 self
.assertTrue(len(result
['entries']) >= 799)
57 def test_youtube_playlist_with_deleted(self
):
60 ie
= YoutubePlaylistIE(dl
)
61 result
= ie
.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
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
)
66 def test_youtube_playlist_empty(self
):
68 ie
= YoutubePlaylistIE(dl
)
69 result
= ie
.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')
70 self
.assertIsPlaylist(result
)
71 self
.assertEqual(len(result
['entries']), 0)
73 def test_youtube_course(self
):
75 ie
= YoutubePlaylistIE(dl
)
76 # TODO find a > 100 (paginating?) videos course
77 result
= ie
.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
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')
83 def test_youtube_channel(self
):
85 ie
= YoutubeChannelIE(dl
)
86 #test paginated channel
87 result
= ie
.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')
88 self
.assertTrue(len(result
['entries']) > 90)
89 #test autogenerated channel
90 result
= ie
.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
91 self
.assertTrue(len(result
['entries']) >= 18)
93 def test_youtube_user(self
):
95 ie
= YoutubeUserIE(dl
)
96 result
= ie
.extract('https://www.youtube.com/user/TheLinuxFoundation')
97 self
.assertTrue(len(result
['entries']) >= 320)
99 def test_youtube_safe_search(self
):
101 ie
= YoutubePlaylistIE(dl
)
102 result
= ie
.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')
103 self
.assertEqual(len(result
['entries']), 2)
105 def test_youtube_show(self
):
107 ie
= YoutubeShowIE(dl
)
108 result
= ie
.extract('http://www.youtube.com/show/airdisasters')
109 self
.assertTrue(len(result
) >= 3)
111 def test_youtube_mix(self
):
113 ie
= YoutubePlaylistIE(dl
)
114 result
= ie
.extract('http://www.youtube.com/watch?v=lLJf9qJHR3E&list=RDrjFaenf1T-Y')
115 entries
= result
['entries']
116 self
.assertTrue(len(entries
) >= 20)
117 original_video
= entries
[0]
118 self
.assertEqual(original_video
['id'], 'rjFaenf1T-Y')
120 def test_youtube_toplist(self
):
122 ie
= YoutubeTopListIE(dl
)
123 result
= ie
.extract('yttoplist:music:Top Tracks')
124 entries
= result
['entries']
125 self
.assertTrue(len(entries
) >= 5)
127 if __name__
== '__main__':