]>
jfr.im git - yt-dlp.git/blob - test/test_all_urls.py
6 # Allow direct execution
8 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
10 from youtube_dl
.extractor
import YoutubeIE
, YoutubePlaylistIE
, YoutubeChannelIE
, JustinTVIE
, gen_extractors
11 from helper
import get_testcases
13 class TestAllURLsMatching(unittest
.TestCase
):
15 self
.ies
= gen_extractors()
17 def matching_ies(self
, url
):
18 return [ie
.IE_NAME
for ie
in self
.ies
if ie
.suitable(url
) and ie
.IE_NAME
!= 'generic']
20 def assertMatch(self
, url
, ie_list
):
21 self
.assertEqual(self
.matching_ies(url
), ie_list
)
23 def test_youtube_playlist_matching(self
):
24 self
.assertTrue(YoutubePlaylistIE
.suitable(u
'ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8'))
25 self
.assertTrue(YoutubePlaylistIE
.suitable(u
'UUBABnxM4Ar9ten8Mdjj1j0Q')) #585
26 self
.assertTrue(YoutubePlaylistIE
.suitable(u
'PL63F0C78739B09958'))
27 self
.assertTrue(YoutubePlaylistIE
.suitable(u
'https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q'))
28 self
.assertTrue(YoutubePlaylistIE
.suitable(u
'https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8'))
29 self
.assertTrue(YoutubePlaylistIE
.suitable(u
'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC'))
30 self
.assertTrue(YoutubePlaylistIE
.suitable(u
'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
31 self
.assertFalse(YoutubePlaylistIE
.suitable(u
'PLtS2H6bU1M'))
33 def test_youtube_matching(self
):
34 self
.assertTrue(YoutubeIE
.suitable(u
'PLtS2H6bU1M'))
35 self
.assertFalse(YoutubeIE
.suitable(u
'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
36 self
.assertMatch('http://youtu.be/BaW_jenozKc', ['youtube'])
37 self
.assertMatch('http://www.youtube.com/v/BaW_jenozKc', ['youtube'])
39 def test_youtube_channel_matching(self
):
40 self
.assertTrue(YoutubeChannelIE
.suitable('https://www.youtube.com/channel/HCtnHdj3df7iM'))
41 self
.assertTrue(YoutubeChannelIE
.suitable('https://www.youtube.com/channel/HCtnHdj3df7iM?feature=gb_ch_rec'))
42 self
.assertTrue(YoutubeChannelIE
.suitable('https://www.youtube.com/channel/HCtnHdj3df7iM/videos'))
44 def test_youtube_user_matching(self
):
45 self
.assertMatch('www.youtube.com/NASAgovVideo/videos', ['youtube:user'])
47 def test_youtube_feeds(self
):
48 self
.assertMatch('https://www.youtube.com/feed/watch_later', ['youtube:watch_later'])
49 self
.assertMatch('https://www.youtube.com/feed/subscriptions', ['youtube:subscriptions'])
50 self
.assertMatch('https://www.youtube.com/feed/recommended', ['youtube:recommended'])
51 self
.assertMatch('https://www.youtube.com/my_favorites', ['youtube:favorites'])
53 def test_justin_tv_channelid_matching(self
):
54 self
.assertTrue(JustinTVIE
.suitable(u
"justin.tv/vanillatv"))
55 self
.assertTrue(JustinTVIE
.suitable(u
"twitch.tv/vanillatv"))
56 self
.assertTrue(JustinTVIE
.suitable(u
"www.justin.tv/vanillatv"))
57 self
.assertTrue(JustinTVIE
.suitable(u
"www.twitch.tv/vanillatv"))
58 self
.assertTrue(JustinTVIE
.suitable(u
"http://www.justin.tv/vanillatv"))
59 self
.assertTrue(JustinTVIE
.suitable(u
"http://www.twitch.tv/vanillatv"))
60 self
.assertTrue(JustinTVIE
.suitable(u
"http://www.justin.tv/vanillatv/"))
61 self
.assertTrue(JustinTVIE
.suitable(u
"http://www.twitch.tv/vanillatv/"))
63 def test_justintv_videoid_matching(self
):
64 self
.assertTrue(JustinTVIE
.suitable(u
"http://www.twitch.tv/vanillatv/b/328087483"))
66 def test_justin_tv_chapterid_matching(self
):
67 self
.assertTrue(JustinTVIE
.suitable(u
"http://www.twitch.tv/tsm_theoddone/c/2349361"))
69 def test_youtube_extract(self
):
70 self
.assertEqual(YoutubeIE()._extract
_id
('http://www.youtube.com/watch?&v=BaW_jenozKc'), 'BaW_jenozKc')
71 self
.assertEqual(YoutubeIE()._extract
_id
('https://www.youtube.com/watch?&v=BaW_jenozKc'), 'BaW_jenozKc')
72 self
.assertEqual(YoutubeIE()._extract
_id
('https://www.youtube.com/watch?feature=player_embedded&v=BaW_jenozKc'), 'BaW_jenozKc')
73 self
.assertEqual(YoutubeIE()._extract
_id
('https://www.youtube.com/watch_popup?v=BaW_jenozKc'), 'BaW_jenozKc')
75 def test_no_duplicates(self
):
76 ies
= gen_extractors()
77 for tc
in get_testcases():
80 if type(ie
).__name
__ in ['GenericIE', tc
['name'] + 'IE']:
81 self
.assertTrue(ie
.suitable(url
), '%s should match URL %r' % (type(ie
).__name
__, url
))
83 self
.assertFalse(ie
.suitable(url
), '%s should not match URL %r' % (type(ie
).__name
__, url
))
85 def test_keywords(self
):
86 self
.assertMatch(':ytsubs', ['youtube:subscriptions'])
87 self
.assertMatch(':ytsubscriptions', ['youtube:subscriptions'])
88 self
.assertMatch(':thedailyshow', ['ComedyCentral'])
89 self
.assertMatch(':tds', ['ComedyCentral'])
90 self
.assertMatch(':colbertreport', ['ComedyCentral'])
91 self
.assertMatch(':cr', ['ComedyCentral'])
94 if __name__
== '__main__':