[youtube] Fix detection of feeds urls (fixes #1294)
[youtube-dl] / 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         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'))
32
33     def test_youtube_matching(self):
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
36         self.assertMatch('http://youtu.be/BaW_jenozKc', ['youtube'])
37         self.assertMatch('http://www.youtube.com/v/BaW_jenozKc', ['youtube'])
38
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
44     def test_youtube_user_matching(self):
45         self.assertMatch('www.youtube.com/NASAgovVideo/videos', ['youtube:user'])
46
47     def test_youtube_feeds(self):
48         self.assertMatch('https://www.youtube.com/feed/watch_later', ['youtube:watch_later'])
49         self.assertMatch('https://www.youtube.com/feed/subscriptions', ['youtube:subscriptions'])
50         self.assertMatch('https://www.youtube.com/feed/recommended', ['youtube:recommended'])
51         self.assertMatch('https://www.youtube.com/my_favorites', ['youtube:favorites'])
52
53     def test_justin_tv_channelid_matching(self):
54         self.assertTrue(JustinTVIE.suitable(u"justin.tv/vanillatv"))
55         self.assertTrue(JustinTVIE.suitable(u"twitch.tv/vanillatv"))
56         self.assertTrue(JustinTVIE.suitable(u"www.justin.tv/vanillatv"))
57         self.assertTrue(JustinTVIE.suitable(u"www.twitch.tv/vanillatv"))
58         self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv"))
59         self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv"))
60         self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv/"))
61         self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/"))
62
63     def test_justintv_videoid_matching(self):
64         self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/b/328087483"))
65
66     def test_justin_tv_chapterid_matching(self):
67         self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/tsm_theoddone/c/2349361"))
68
69     def test_youtube_extract(self):
70         self.assertEqual(YoutubeIE()._extract_id('http://www.youtube.com/watch?&v=BaW_jenozKc'), 'BaW_jenozKc')
71         self.assertEqual(YoutubeIE()._extract_id('https://www.youtube.com/watch?&v=BaW_jenozKc'), 'BaW_jenozKc')
72         self.assertEqual(YoutubeIE()._extract_id('https://www.youtube.com/watch?feature=player_embedded&v=BaW_jenozKc'), 'BaW_jenozKc')
73         self.assertEqual(YoutubeIE()._extract_id('https://www.youtube.com/watch_popup?v=BaW_jenozKc'), 'BaW_jenozKc')
74
75     def test_no_duplicates(self):
76         ies = gen_extractors()
77         for tc in get_testcases():
78             url = tc['url']
79             for ie in ies:
80                 if type(ie).__name__ in ['GenericIE', tc['name'] + 'IE']:
81                     self.assertTrue(ie.suitable(url), '%s should match URL %r' % (type(ie).__name__, url))
82                 else:
83                     self.assertFalse(ie.suitable(url), '%s should not match URL %r' % (type(ie).__name__, url))
84
85     def test_keywords(self):
86         self.assertMatch(':ytsubs', ['youtube:subscriptions'])
87         self.assertMatch(':ytsubscriptions', ['youtube:subscriptions'])
88         self.assertMatch(':thedailyshow', ['ComedyCentral'])
89         self.assertMatch(':tds', ['ComedyCentral'])
90         self.assertMatch(':colbertreport', ['ComedyCentral'])
91         self.assertMatch(':cr', ['ComedyCentral'])
92
93
94 if __name__ == '__main__':
95     unittest.main()