]> jfr.im git - yt-dlp.git/blame - test/test_all_urls.py
release 2014.02.08
[yt-dlp.git] / test / test_all_urls.py
CommitLineData
e387eb5a
PH
1#!/usr/bin/env python
2
44a5f171
PH
3# Allow direct execution
4import os
e387eb5a
PH
5import sys
6import unittest
44a5f171 7sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
e387eb5a 8
e387eb5a 9
44a5f171
PH
10from test.helper import get_testcases
11
12from youtube_dl.extractor import (
8c8e3eec 13 FacebookIE,
44a5f171
PH
14 gen_extractors,
15 JustinTVIE,
16 YoutubeIE,
17)
18
e387eb5a 19
3bb61659 20class TestAllURLsMatching(unittest.TestCase):
f4b05232
JMF
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
3bb61659 30 def test_youtube_playlist_matching(self):
e3ea4790
JMF
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'))
d67cc9fa
JMF
40 # Top tracks
41 assertPlaylist('https://www.youtube.com/playlist?list=MCUS.20142101')
e387eb5a
PH
42
43 def test_youtube_matching(self):
89de9eb1
FV
44 self.assertTrue(YoutubeIE.suitable(u'PLtS2H6bU1M'))
45 self.assertFalse(YoutubeIE.suitable(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
f4b05232
JMF
46 self.assertMatch('http://youtu.be/BaW_jenozKc', ['youtube'])
47 self.assertMatch('http://www.youtube.com/v/BaW_jenozKc', ['youtube'])
e69ae5b9 48 self.assertMatch('https://youtube.googleapis.com/v/BaW_jenozKc', ['youtube'])
e387eb5a 49
fb6c3199 50 def test_youtube_channel_matching(self):
e3ea4790
JMF
51 assertChannel = lambda url: self.assertMatch(url, ['youtube:channel'])
52 assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM')
53 assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM?feature=gb_ch_rec')
54 assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
fb6c3199 55
f4b05232
JMF
56 def test_youtube_user_matching(self):
57 self.assertMatch('www.youtube.com/NASAgovVideo/videos', ['youtube:user'])
58
faab1d38
JMF
59 def test_youtube_feeds(self):
60 self.assertMatch('https://www.youtube.com/feed/watch_later', ['youtube:watch_later'])
61 self.assertMatch('https://www.youtube.com/feed/subscriptions', ['youtube:subscriptions'])
62 self.assertMatch('https://www.youtube.com/feed/recommended', ['youtube:recommended'])
63 self.assertMatch('https://www.youtube.com/my_favorites', ['youtube:favorites'])
64
e3ea4790
JMF
65 def test_youtube_show_matching(self):
66 self.assertMatch('http://www.youtube.com/show/airdisasters', ['youtube:show'])
67
50b4d259
CD
68 def test_justin_tv_channelid_matching(self):
69 self.assertTrue(JustinTVIE.suitable(u"justin.tv/vanillatv"))
70 self.assertTrue(JustinTVIE.suitable(u"twitch.tv/vanillatv"))
71 self.assertTrue(JustinTVIE.suitable(u"www.justin.tv/vanillatv"))
72 self.assertTrue(JustinTVIE.suitable(u"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 self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv/"))
76 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/"))
77
78 def test_justintv_videoid_matching(self):
79 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/b/328087483"))
80
81 def test_justin_tv_chapterid_matching(self):
82 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/tsm_theoddone/c/2349361"))
83
3bb61659 84 def test_youtube_extract(self):
8963d9c2
JMF
85 assertExtractId = lambda url, id: self.assertEqual(YoutubeIE()._extract_id(url), id)
86 assertExtractId('http://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc')
87 assertExtractId('https://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc')
88 assertExtractId('https://www.youtube.com/watch?feature=player_embedded&v=BaW_jenozKc', 'BaW_jenozKc')
89 assertExtractId('https://www.youtube.com/watch_popup?v=BaW_jenozKc', 'BaW_jenozKc')
90 assertExtractId('http://www.youtube.com/watch?v=BaW_jenozKcsharePLED17F32AD9753930', 'BaW_jenozKc')
91 assertExtractId('BaW_jenozKc', 'BaW_jenozKc')
3bb61659 92
8c8e3eec
PH
93 def test_facebook_matching(self):
94 self.assertTrue(FacebookIE.suitable(u'https://www.facebook.com/Shiniknoh#!/photo.php?v=10153317450565268'))
95
a924876f
PH
96 def test_no_duplicates(self):
97 ies = gen_extractors()
98 for tc in get_testcases():
99 url = tc['url']
100 for ie in ies:
8c8e3eec 101 if type(ie).__name__ in ('GenericIE', tc['name'] + 'IE'):
a924876f
PH
102 self.assertTrue(ie.suitable(url), '%s should match URL %r' % (type(ie).__name__, url))
103 else:
104 self.assertFalse(ie.suitable(url), '%s should not match URL %r' % (type(ie).__name__, url))
105
897f36d1 106 def test_keywords(self):
f4b05232
JMF
107 self.assertMatch(':ytsubs', ['youtube:subscriptions'])
108 self.assertMatch(':ytsubscriptions', ['youtube:subscriptions'])
f459d170 109 self.assertMatch(':ythistory', ['youtube:history'])
16e05584
JMF
110 self.assertMatch(':thedailyshow', ['ComedyCentralShows'])
111 self.assertMatch(':tds', ['ComedyCentralShows'])
112 self.assertMatch(':colbertreport', ['ComedyCentralShows'])
113 self.assertMatch(':cr', ['ComedyCentralShows'])
897f36d1 114
55a10eab
JMF
115 def test_vimeo_matching(self):
116 self.assertMatch('http://vimeo.com/channels/tributes', ['vimeo:channel'])
117 self.assertMatch('http://vimeo.com/user7108434', ['vimeo:user'])
48a20346
PH
118 self.assertMatch('http://vimeo.com/user7108434/videos', ['vimeo:user'])
119 self.assertMatch('https://vimeo.com/user21297594/review/75524534/3c257a1b5d', ['vimeo:review'])
55a10eab 120
4ff50ef8
PH
121 # https://github.com/rg3/youtube-dl/issues/1930
122 def test_soundcloud_not_matching_sets(self):
123 self.assertMatch('http://soundcloud.com/floex/sets/gone-ep', ['soundcloud:set'])
a924876f 124
456895d9
PH
125 def test_tumblr(self):
126 self.assertMatch('http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes', ['Tumblr'])
127 self.assertMatch('http://tatianamaslanydaily.tumblr.com/post/54196191430', ['Tumblr'])
128
e387eb5a
PH
129if __name__ == '__main__':
130 unittest.main()