]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_youtube_lists.py
53e65816dfb9268c40831a57c781a169fbb050b7
7 # Allow direct execution
9 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
11 from youtube_dl
.extractor
import YoutubeUserIE
, YoutubePlaylistIE
, YoutubeIE
, YoutubeChannelIE
, YoutubeShowIE
12 from youtube_dl
.utils
import *
14 from helper
import FakeYDL
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')
21 def test_youtube_playlist(self
):
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'])
30 def test_youtube_playlist_noplaylist(self
):
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 self
.assertEqual(YoutubeIE()._extract
_id
(result
['url']), 'FXxLjLQi3Fg')
38 def test_issue_673(self
):
40 ie
= YoutubePlaylistIE(dl
)
41 result
= ie
.extract('PLBB231211A4F62143')[0]
42 self
.assertTrue(len(result
['entries']) > 25)
44 def test_youtube_playlist_long(self
):
46 ie
= YoutubePlaylistIE(dl
)
47 result
= ie
.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')[0]
48 self
.assertIsPlaylist(result
)
49 self
.assertTrue(len(result
['entries']) >= 799)
51 def test_youtube_playlist_with_deleted(self
):
54 ie
= YoutubePlaylistIE(dl
)
55 result
= ie
.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')[0]
56 ytie_results
= [YoutubeIE()._extract
_id
(url
['url']) for url
in result
['entries']]
57 self
.assertFalse('pElCt5oNDuI' in ytie_results
)
58 self
.assertFalse('KdPEApIVdWM' in ytie_results
)
60 def test_youtube_playlist_empty(self
):
62 ie
= YoutubePlaylistIE(dl
)
63 result
= ie
.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')[0]
64 self
.assertIsPlaylist(result
)
65 self
.assertEqual(len(result
['entries']), 0)
67 def test_youtube_course(self
):
69 ie
= YoutubePlaylistIE(dl
)
70 # TODO find a > 100 (paginating?) videos course
71 result
= ie
.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')[0]
72 entries
= result
['entries']
73 self
.assertEqual(YoutubeIE()._extract
_id
(entries
[0]['url']), 'j9WZyLZCBzs')
74 self
.assertEqual(len(entries
), 25)
75 self
.assertEqual(YoutubeIE()._extract
_id
(entries
[-1]['url']), 'rYefUsYuEp0')
77 def test_youtube_channel(self
):
79 ie
= YoutubeChannelIE(dl
)
80 #test paginated channel
81 result
= ie
.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')[0]
82 self
.assertTrue(len(result
['entries']) > 90)
83 #test autogenerated channel
84 result
= ie
.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')[0]
85 self
.assertTrue(len(result
['entries']) >= 18)
87 def test_youtube_user(self
):
89 ie
= YoutubeUserIE(dl
)
90 result
= ie
.extract('https://www.youtube.com/user/TheLinuxFoundation')[0]
91 self
.assertTrue(len(result
['entries']) >= 320)
93 def test_youtube_safe_search(self
):
95 ie
= YoutubePlaylistIE(dl
)
96 result
= ie
.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')[0]
97 self
.assertEqual(len(result
['entries']), 2)
99 def test_youtube_show(self
):
101 ie
= YoutubeShowIE(dl
)
102 result
= ie
.extract('http://www.youtube.com/show/airdisasters')
103 self
.assertTrue(len(result
) >= 4)
105 if __name__
== '__main__':