]>
Commit | Line | Data |
---|---|---|
e387eb5a PH |
1 | #!/usr/bin/env python |
2 | ||
44a5f171 PH |
3 | # Allow direct execution |
4 | import os | |
e387eb5a PH |
5 | import sys |
6 | import unittest | |
44a5f171 | 7 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
e387eb5a | 8 | |
e387eb5a | 9 | |
44a5f171 PH |
10 | from test.helper import get_testcases |
11 | ||
12 | from youtube_dl.extractor import ( | |
13 | gen_extractors, | |
14 | JustinTVIE, | |
15 | YoutubeIE, | |
16 | ) | |
17 | ||
e387eb5a | 18 | |
3bb61659 | 19 | class TestAllURLsMatching(unittest.TestCase): |
f4b05232 JMF |
20 | def setUp(self): |
21 | self.ies = gen_extractors() | |
22 | ||
23 | def matching_ies(self, url): | |
24 | return [ie.IE_NAME for ie in self.ies if ie.suitable(url) and ie.IE_NAME != 'generic'] | |
25 | ||
26 | def assertMatch(self, url, ie_list): | |
27 | self.assertEqual(self.matching_ies(url), ie_list) | |
28 | ||
3bb61659 | 29 | def test_youtube_playlist_matching(self): |
e3ea4790 JMF |
30 | assertPlaylist = lambda url: self.assertMatch(url, ['youtube:playlist']) |
31 | assertPlaylist(u'ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8') | |
32 | assertPlaylist(u'UUBABnxM4Ar9ten8Mdjj1j0Q') #585 | |
33 | assertPlaylist(u'PL63F0C78739B09958') | |
34 | assertPlaylist(u'https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q') | |
35 | assertPlaylist(u'https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8') | |
36 | assertPlaylist(u'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC') | |
37 | assertPlaylist(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012') #668 | |
38 | self.assertFalse('youtube:playlist' in self.matching_ies(u'PLtS2H6bU1M')) | |
e387eb5a PH |
39 | |
40 | def test_youtube_matching(self): | |
89de9eb1 FV |
41 | self.assertTrue(YoutubeIE.suitable(u'PLtS2H6bU1M')) |
42 | self.assertFalse(YoutubeIE.suitable(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668 | |
f4b05232 JMF |
43 | self.assertMatch('http://youtu.be/BaW_jenozKc', ['youtube']) |
44 | self.assertMatch('http://www.youtube.com/v/BaW_jenozKc', ['youtube']) | |
e69ae5b9 | 45 | self.assertMatch('https://youtube.googleapis.com/v/BaW_jenozKc', ['youtube']) |
e387eb5a | 46 | |
fb6c3199 | 47 | def test_youtube_channel_matching(self): |
e3ea4790 JMF |
48 | assertChannel = lambda url: self.assertMatch(url, ['youtube:channel']) |
49 | assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM') | |
50 | assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM?feature=gb_ch_rec') | |
51 | assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM/videos') | |
fb6c3199 | 52 | |
f4b05232 JMF |
53 | def test_youtube_user_matching(self): |
54 | self.assertMatch('www.youtube.com/NASAgovVideo/videos', ['youtube:user']) | |
55 | ||
faab1d38 JMF |
56 | def test_youtube_feeds(self): |
57 | self.assertMatch('https://www.youtube.com/feed/watch_later', ['youtube:watch_later']) | |
58 | self.assertMatch('https://www.youtube.com/feed/subscriptions', ['youtube:subscriptions']) | |
59 | self.assertMatch('https://www.youtube.com/feed/recommended', ['youtube:recommended']) | |
60 | self.assertMatch('https://www.youtube.com/my_favorites', ['youtube:favorites']) | |
61 | ||
e3ea4790 JMF |
62 | def test_youtube_show_matching(self): |
63 | self.assertMatch('http://www.youtube.com/show/airdisasters', ['youtube:show']) | |
64 | ||
50b4d259 CD |
65 | def test_justin_tv_channelid_matching(self): |
66 | self.assertTrue(JustinTVIE.suitable(u"justin.tv/vanillatv")) | |
67 | self.assertTrue(JustinTVIE.suitable(u"twitch.tv/vanillatv")) | |
68 | self.assertTrue(JustinTVIE.suitable(u"www.justin.tv/vanillatv")) | |
69 | self.assertTrue(JustinTVIE.suitable(u"www.twitch.tv/vanillatv")) | |
70 | self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv")) | |
71 | self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv")) | |
72 | self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv/")) | |
73 | self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/")) | |
74 | ||
75 | def test_justintv_videoid_matching(self): | |
76 | self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/b/328087483")) | |
77 | ||
78 | def test_justin_tv_chapterid_matching(self): | |
79 | self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/tsm_theoddone/c/2349361")) | |
80 | ||
3bb61659 | 81 | def test_youtube_extract(self): |
8963d9c2 JMF |
82 | assertExtractId = lambda url, id: self.assertEqual(YoutubeIE()._extract_id(url), id) |
83 | assertExtractId('http://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc') | |
84 | assertExtractId('https://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc') | |
85 | assertExtractId('https://www.youtube.com/watch?feature=player_embedded&v=BaW_jenozKc', 'BaW_jenozKc') | |
86 | assertExtractId('https://www.youtube.com/watch_popup?v=BaW_jenozKc', 'BaW_jenozKc') | |
87 | assertExtractId('http://www.youtube.com/watch?v=BaW_jenozKcsharePLED17F32AD9753930', 'BaW_jenozKc') | |
88 | assertExtractId('BaW_jenozKc', 'BaW_jenozKc') | |
3bb61659 | 89 | |
a924876f PH |
90 | def test_no_duplicates(self): |
91 | ies = gen_extractors() | |
92 | for tc in get_testcases(): | |
93 | url = tc['url'] | |
94 | for ie in ies: | |
95 | if type(ie).__name__ in ['GenericIE', tc['name'] + 'IE']: | |
96 | self.assertTrue(ie.suitable(url), '%s should match URL %r' % (type(ie).__name__, url)) | |
97 | else: | |
98 | self.assertFalse(ie.suitable(url), '%s should not match URL %r' % (type(ie).__name__, url)) | |
99 | ||
897f36d1 | 100 | def test_keywords(self): |
f4b05232 JMF |
101 | self.assertMatch(':ytsubs', ['youtube:subscriptions']) |
102 | self.assertMatch(':ytsubscriptions', ['youtube:subscriptions']) | |
f459d170 | 103 | self.assertMatch(':ythistory', ['youtube:history']) |
16e05584 JMF |
104 | self.assertMatch(':thedailyshow', ['ComedyCentralShows']) |
105 | self.assertMatch(':tds', ['ComedyCentralShows']) | |
106 | self.assertMatch(':colbertreport', ['ComedyCentralShows']) | |
107 | self.assertMatch(':cr', ['ComedyCentralShows']) | |
897f36d1 | 108 | |
55a10eab JMF |
109 | def test_vimeo_matching(self): |
110 | self.assertMatch('http://vimeo.com/channels/tributes', ['vimeo:channel']) | |
111 | self.assertMatch('http://vimeo.com/user7108434', ['vimeo:user']) | |
112 | ||
4ff50ef8 PH |
113 | # https://github.com/rg3/youtube-dl/issues/1930 |
114 | def test_soundcloud_not_matching_sets(self): | |
115 | self.assertMatch('http://soundcloud.com/floex/sets/gone-ep', ['soundcloud:set']) | |
a924876f | 116 | |
e387eb5a PH |
117 | if __name__ == '__main__': |
118 | unittest.main() |