Merge pull request #2681 from phihag/readme-dev-instructions
[youtube-dl] / test / test_all_urls.py
1 #!/usr/bin/env python
2
3 from __future__ import unicode_literals
4
5 # Allow direct execution
6 import os
7 import sys
8 import unittest
9 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10
11
12 from test.helper import gettestcases
13
14 from youtube_dl.extractor import (
15     FacebookIE,
16     gen_extractors,
17     JustinTVIE,
18     PBSIE,
19     YoutubeIE,
20 )
21
22
23 class TestAllURLsMatching(unittest.TestCase):
24     def setUp(self):
25         self.ies = gen_extractors()
26
27     def matching_ies(self, url):
28         return [ie.IE_NAME for ie in self.ies if ie.suitable(url) and ie.IE_NAME != 'generic']
29
30     def assertMatch(self, url, ie_list):
31         self.assertEqual(self.matching_ies(url), ie_list)
32
33     def test_youtube_playlist_matching(self):
34         assertPlaylist = lambda url: self.assertMatch(url, ['youtube:playlist'])
35         assertPlaylist('ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
36         assertPlaylist('UUBABnxM4Ar9ten8Mdjj1j0Q') #585
37         assertPlaylist('PL63F0C78739B09958')
38         assertPlaylist('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
39         assertPlaylist('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
40         assertPlaylist('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
41         assertPlaylist('https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012') #668
42         self.assertFalse('youtube:playlist' in self.matching_ies('PLtS2H6bU1M'))
43         # Top tracks
44         assertPlaylist('https://www.youtube.com/playlist?list=MCUS.20142101')
45
46     def test_youtube_matching(self):
47         self.assertTrue(YoutubeIE.suitable('PLtS2H6bU1M'))
48         self.assertFalse(YoutubeIE.suitable('https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
49         self.assertMatch('http://youtu.be/BaW_jenozKc', ['youtube'])
50         self.assertMatch('http://www.youtube.com/v/BaW_jenozKc', ['youtube'])
51         self.assertMatch('https://youtube.googleapis.com/v/BaW_jenozKc', ['youtube'])
52
53     def test_youtube_channel_matching(self):
54         assertChannel = lambda url: self.assertMatch(url, ['youtube:channel'])
55         assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM')
56         assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM?feature=gb_ch_rec')
57         assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
58
59     def test_youtube_user_matching(self):
60         self.assertMatch('www.youtube.com/NASAgovVideo/videos', ['youtube:user'])
61
62     def test_youtube_feeds(self):
63         self.assertMatch('https://www.youtube.com/feed/watch_later', ['youtube:watch_later'])
64         self.assertMatch('https://www.youtube.com/feed/subscriptions', ['youtube:subscriptions'])
65         self.assertMatch('https://www.youtube.com/feed/recommended', ['youtube:recommended'])
66         self.assertMatch('https://www.youtube.com/my_favorites', ['youtube:favorites'])
67
68     def test_youtube_show_matching(self):
69         self.assertMatch('http://www.youtube.com/show/airdisasters', ['youtube:show'])
70
71     def test_youtube_truncated(self):
72         self.assertMatch('http://www.youtube.com/watch?', ['youtube:truncated_url'])
73
74     def test_youtube_search_matching(self):
75         self.assertMatch('http://www.youtube.com/results?search_query=making+mustard', ['youtube:search_url'])
76         self.assertMatch('https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video', ['youtube:search_url'])
77
78     def test_justin_tv_channelid_matching(self):
79         self.assertTrue(JustinTVIE.suitable(u"justin.tv/vanillatv"))
80         self.assertTrue(JustinTVIE.suitable(u"twitch.tv/vanillatv"))
81         self.assertTrue(JustinTVIE.suitable(u"www.justin.tv/vanillatv"))
82         self.assertTrue(JustinTVIE.suitable(u"www.twitch.tv/vanillatv"))
83         self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv"))
84         self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv"))
85         self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv/"))
86         self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/"))
87
88     def test_justintv_videoid_matching(self):
89         self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/b/328087483"))
90
91     def test_justin_tv_chapterid_matching(self):
92         self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/tsm_theoddone/c/2349361"))
93
94     def test_youtube_extract(self):
95         assertExtractId = lambda url, id: self.assertEqual(YoutubeIE.extract_id(url), id)
96         assertExtractId('http://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc')
97         assertExtractId('https://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc')
98         assertExtractId('https://www.youtube.com/watch?feature=player_embedded&v=BaW_jenozKc', 'BaW_jenozKc')
99         assertExtractId('https://www.youtube.com/watch_popup?v=BaW_jenozKc', 'BaW_jenozKc')
100         assertExtractId('http://www.youtube.com/watch?v=BaW_jenozKcsharePLED17F32AD9753930', 'BaW_jenozKc')
101         assertExtractId('BaW_jenozKc', 'BaW_jenozKc')
102
103     def test_facebook_matching(self):
104         self.assertTrue(FacebookIE.suitable('https://www.facebook.com/Shiniknoh#!/photo.php?v=10153317450565268'))
105
106     def test_no_duplicates(self):
107         ies = gen_extractors()
108         for tc in gettestcases():
109             url = tc['url']
110             for ie in ies:
111                 if type(ie).__name__ in ('GenericIE', tc['name'] + 'IE'):
112                     self.assertTrue(ie.suitable(url), '%s should match URL %r' % (type(ie).__name__, url))
113                 else:
114                     self.assertFalse(ie.suitable(url), '%s should not match URL %r' % (type(ie).__name__, url))
115
116     def test_keywords(self):
117         self.assertMatch(':ytsubs', ['youtube:subscriptions'])
118         self.assertMatch(':ytsubscriptions', ['youtube:subscriptions'])
119         self.assertMatch(':ythistory', ['youtube:history'])
120         self.assertMatch(':thedailyshow', ['ComedyCentralShows'])
121         self.assertMatch(':tds', ['ComedyCentralShows'])
122         self.assertMatch(':colbertreport', ['ComedyCentralShows'])
123         self.assertMatch(':cr', ['ComedyCentralShows'])
124
125     def test_vimeo_matching(self):
126         self.assertMatch('http://vimeo.com/channels/tributes', ['vimeo:channel'])
127         self.assertMatch('http://vimeo.com/channels/31259', ['vimeo:channel'])
128         self.assertMatch('http://vimeo.com/channels/31259/53576664', ['vimeo'])
129         self.assertMatch('http://vimeo.com/user7108434', ['vimeo:user'])
130         self.assertMatch('http://vimeo.com/user7108434/videos', ['vimeo:user'])
131         self.assertMatch('https://vimeo.com/user21297594/review/75524534/3c257a1b5d', ['vimeo:review'])
132
133     # https://github.com/rg3/youtube-dl/issues/1930
134     def test_soundcloud_not_matching_sets(self):
135         self.assertMatch('http://soundcloud.com/floex/sets/gone-ep', ['soundcloud:set'])
136
137     def test_tumblr(self):
138         self.assertMatch('http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes', ['Tumblr'])
139         self.assertMatch('http://tatianamaslanydaily.tumblr.com/post/54196191430', ['Tumblr'])
140
141     def test_pbs(self):
142         # https://github.com/rg3/youtube-dl/issues/2350
143         self.assertMatch('http://video.pbs.org/viralplayer/2365173446/', ['PBS'])
144         self.assertMatch('http://video.pbs.org/widget/partnerplayer/980042464/', ['PBS'])
145
146     def test_ComedyCentralShows(self):
147         self.assertMatch(
148             'http://thedailyshow.cc.com/extended-interviews/xm3fnq/andrew-napolitano-extended-interview',
149             ['ComedyCentralShows'])
150         self.assertMatch(
151             'http://thecolbertreport.cc.com/videos/29w6fx/-realhumanpraise-for-fox-news',
152             ['ComedyCentralShows'])
153         self.assertMatch(
154             'http://thecolbertreport.cc.com/videos/gh6urb/neil-degrasse-tyson-pt--1?xrs=eml_col_031114',
155             ['ComedyCentralShows'])
156         self.assertMatch(
157             'http://thedailyshow.cc.com/guests/michael-lewis/3efna8/exclusive---michael-lewis-extended-interview-pt--3',
158             ['ComedyCentralShows'])
159
160 if __name__ == '__main__':
161     unittest.main()