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