]> jfr.im git - yt-dlp.git/blame - test/test_all_urls.py
[youtube] Urls like youtube.com/NASA are now interpreted as users (fixes #1069)
[yt-dlp.git] / test / test_all_urls.py
CommitLineData
e387eb5a
PH
1#!/usr/bin/env python
2
3import sys
4import unittest
5
6# Allow direct execution
7import os
8sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
a924876f
PH
10from youtube_dl.extractor import YoutubeIE, YoutubePlaylistIE, YoutubeChannelIE, JustinTVIE, gen_extractors
11from helper import get_testcases
e387eb5a 12
3bb61659 13class TestAllURLsMatching(unittest.TestCase):
f4b05232
JMF
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
3bb61659 23 def test_youtube_playlist_matching(self):
89de9eb1
FV
24 self.assertTrue(YoutubePlaylistIE.suitable(u'ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8'))
25 self.assertTrue(YoutubePlaylistIE.suitable(u'UUBABnxM4Ar9ten8Mdjj1j0Q')) #585
26 self.assertTrue(YoutubePlaylistIE.suitable(u'PL63F0C78739B09958'))
27 self.assertTrue(YoutubePlaylistIE.suitable(u'https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q'))
28 self.assertTrue(YoutubePlaylistIE.suitable(u'https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8'))
29 self.assertTrue(YoutubePlaylistIE.suitable(u'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC'))
30 self.assertTrue(YoutubePlaylistIE.suitable(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
31 self.assertFalse(YoutubePlaylistIE.suitable(u'PLtS2H6bU1M'))
e387eb5a
PH
32
33 def test_youtube_matching(self):
89de9eb1
FV
34 self.assertTrue(YoutubeIE.suitable(u'PLtS2H6bU1M'))
35 self.assertFalse(YoutubeIE.suitable(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
f4b05232
JMF
36 self.assertMatch('http://youtu.be/BaW_jenozKc', ['youtube'])
37 self.assertMatch('http://www.youtube.com/v/BaW_jenozKc', ['youtube'])
e387eb5a 38
fb6c3199 39 def test_youtube_channel_matching(self):
40 self.assertTrue(YoutubeChannelIE.suitable('https://www.youtube.com/channel/HCtnHdj3df7iM'))
41 self.assertTrue(YoutubeChannelIE.suitable('https://www.youtube.com/channel/HCtnHdj3df7iM?feature=gb_ch_rec'))
42 self.assertTrue(YoutubeChannelIE.suitable('https://www.youtube.com/channel/HCtnHdj3df7iM/videos'))
43
f4b05232
JMF
44 def test_youtube_user_matching(self):
45 self.assertMatch('www.youtube.com/NASAgovVideo/videos', ['youtube:user'])
46
50b4d259
CD
47 def test_justin_tv_channelid_matching(self):
48 self.assertTrue(JustinTVIE.suitable(u"justin.tv/vanillatv"))
49 self.assertTrue(JustinTVIE.suitable(u"twitch.tv/vanillatv"))
50 self.assertTrue(JustinTVIE.suitable(u"www.justin.tv/vanillatv"))
51 self.assertTrue(JustinTVIE.suitable(u"www.twitch.tv/vanillatv"))
52 self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv"))
53 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv"))
54 self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv/"))
55 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/"))
56
57 def test_justintv_videoid_matching(self):
58 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/b/328087483"))
59
60 def test_justin_tv_chapterid_matching(self):
61 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/tsm_theoddone/c/2349361"))
62
3bb61659
PH
63 def test_youtube_extract(self):
64 self.assertEqual(YoutubeIE()._extract_id('http://www.youtube.com/watch?&v=BaW_jenozKc'), 'BaW_jenozKc')
65 self.assertEqual(YoutubeIE()._extract_id('https://www.youtube.com/watch?&v=BaW_jenozKc'), 'BaW_jenozKc')
66 self.assertEqual(YoutubeIE()._extract_id('https://www.youtube.com/watch?feature=player_embedded&v=BaW_jenozKc'), 'BaW_jenozKc')
d741e55a 67 self.assertEqual(YoutubeIE()._extract_id('https://www.youtube.com/watch_popup?v=BaW_jenozKc'), 'BaW_jenozKc')
3bb61659 68
a924876f
PH
69 def test_no_duplicates(self):
70 ies = gen_extractors()
71 for tc in get_testcases():
72 url = tc['url']
73 for ie in ies:
74 if type(ie).__name__ in ['GenericIE', tc['name'] + 'IE']:
75 self.assertTrue(ie.suitable(url), '%s should match URL %r' % (type(ie).__name__, url))
76 else:
77 self.assertFalse(ie.suitable(url), '%s should not match URL %r' % (type(ie).__name__, url))
78
897f36d1 79 def test_keywords(self):
f4b05232
JMF
80 self.assertMatch(':ytsubs', ['youtube:subscriptions'])
81 self.assertMatch(':ytsubscriptions', ['youtube:subscriptions'])
82 self.assertMatch(':thedailyshow', ['ComedyCentral'])
83 self.assertMatch(':tds', ['ComedyCentral'])
84 self.assertMatch(':colbertreport', ['ComedyCentral'])
85 self.assertMatch(':cr', ['ComedyCentral'])
897f36d1 86
a924876f 87
e387eb5a
PH
88if __name__ == '__main__':
89 unittest.main()