]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_all_urls.py
ff1c86efebe31f2d6477cbfe6246baa50607d6a7
[youtubedl] / test / test_all_urls.py
1 #!/usr/bin/env python
2
3 import sys
4 import unittest
5
6 # Allow direct execution
7 import os
8 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
10 from youtube_dl.extractor import YoutubeIE, YoutubePlaylistIE, YoutubeChannelIE, JustinTVIE, gen_extractors
11 from helper import get_testcases
12
13 class TestAllURLsMatching(unittest.TestCase):
14 def setUp(self):
15 self.ies = gen_extractors()
16
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']
19
20 def assertMatch(self, url, ie_list):
21 self.assertEqual(self.matching_ies(url), ie_list)
22
23 def test_youtube_playlist_matching(self):
24 assertPlaylist = lambda url: self.assertMatch(url, ['youtube:playlist'])
25 assertPlaylist(u'ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
26 assertPlaylist(u'UUBABnxM4Ar9ten8Mdjj1j0Q') #585
27 assertPlaylist(u'PL63F0C78739B09958')
28 assertPlaylist(u'https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
29 assertPlaylist(u'https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
30 assertPlaylist(u'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
31 assertPlaylist(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012') #668
32 self.assertFalse('youtube:playlist' in self.matching_ies(u'PLtS2H6bU1M'))
33
34 def test_youtube_matching(self):
35 self.assertTrue(YoutubeIE.suitable(u'PLtS2H6bU1M'))
36 self.assertFalse(YoutubeIE.suitable(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
37 self.assertMatch('http://youtu.be/BaW_jenozKc', ['youtube'])
38 self.assertMatch('http://www.youtube.com/v/BaW_jenozKc', ['youtube'])
39 self.assertMatch('https://youtube.googleapis.com/v/BaW_jenozKc', ['youtube'])
40
41 def test_youtube_channel_matching(self):
42 assertChannel = lambda url: self.assertMatch(url, ['youtube:channel'])
43 assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM')
44 assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM?feature=gb_ch_rec')
45 assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
46
47 def test_youtube_user_matching(self):
48 self.assertMatch('www.youtube.com/NASAgovVideo/videos', ['youtube:user'])
49
50 def test_youtube_feeds(self):
51 self.assertMatch('https://www.youtube.com/feed/watch_later', ['youtube:watch_later'])
52 self.assertMatch('https://www.youtube.com/feed/subscriptions', ['youtube:subscriptions'])
53 self.assertMatch('https://www.youtube.com/feed/recommended', ['youtube:recommended'])
54 self.assertMatch('https://www.youtube.com/my_favorites', ['youtube:favorites'])
55
56 def test_youtube_show_matching(self):
57 self.assertMatch('http://www.youtube.com/show/airdisasters', ['youtube:show'])
58
59 def test_justin_tv_channelid_matching(self):
60 self.assertTrue(JustinTVIE.suitable(u"justin.tv/vanillatv"))
61 self.assertTrue(JustinTVIE.suitable(u"twitch.tv/vanillatv"))
62 self.assertTrue(JustinTVIE.suitable(u"www.justin.tv/vanillatv"))
63 self.assertTrue(JustinTVIE.suitable(u"www.twitch.tv/vanillatv"))
64 self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv"))
65 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv"))
66 self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv/"))
67 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/"))
68
69 def test_justintv_videoid_matching(self):
70 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/b/328087483"))
71
72 def test_justin_tv_chapterid_matching(self):
73 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/tsm_theoddone/c/2349361"))
74
75 def test_youtube_extract(self):
76 assertExtractId = lambda url, id: self.assertEqual(YoutubeIE()._extract_id(url), id)
77 assertExtractId('http://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc')
78 assertExtractId('https://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc')
79 assertExtractId('https://www.youtube.com/watch?feature=player_embedded&v=BaW_jenozKc', 'BaW_jenozKc')
80 assertExtractId('https://www.youtube.com/watch_popup?v=BaW_jenozKc', 'BaW_jenozKc')
81 assertExtractId('http://www.youtube.com/watch?v=BaW_jenozKcsharePLED17F32AD9753930', 'BaW_jenozKc')
82 assertExtractId('BaW_jenozKc', 'BaW_jenozKc')
83
84 def test_no_duplicates(self):
85 ies = gen_extractors()
86 for tc in get_testcases():
87 url = tc['url']
88 for ie in ies:
89 if type(ie).__name__ in ['GenericIE', tc['name'] + 'IE']:
90 self.assertTrue(ie.suitable(url), '%s should match URL %r' % (type(ie).__name__, url))
91 else:
92 self.assertFalse(ie.suitable(url), '%s should not match URL %r' % (type(ie).__name__, url))
93
94 def test_keywords(self):
95 self.assertMatch(':ytsubs', ['youtube:subscriptions'])
96 self.assertMatch(':ytsubscriptions', ['youtube:subscriptions'])
97 self.assertMatch(':thedailyshow', ['ComedyCentral'])
98 self.assertMatch(':tds', ['ComedyCentral'])
99 self.assertMatch(':colbertreport', ['ComedyCentral'])
100 self.assertMatch(':cr', ['ComedyCentral'])
101
102
103 if __name__ == '__main__':
104 unittest.main()