]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_all_urls.py
Merge tag 'upstream/2013.08.17'
[youtubedl] / 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 test_youtube_playlist_matching(self):
15 self.assertTrue(YoutubePlaylistIE.suitable(u'ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8'))
16 self.assertTrue(YoutubePlaylistIE.suitable(u'UUBABnxM4Ar9ten8Mdjj1j0Q')) #585
17 self.assertTrue(YoutubePlaylistIE.suitable(u'PL63F0C78739B09958'))
18 self.assertTrue(YoutubePlaylistIE.suitable(u'https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q'))
19 self.assertTrue(YoutubePlaylistIE.suitable(u'https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8'))
20 self.assertTrue(YoutubePlaylistIE.suitable(u'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC'))
21 self.assertTrue(YoutubePlaylistIE.suitable(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
22 self.assertFalse(YoutubePlaylistIE.suitable(u'PLtS2H6bU1M'))
23
24 def test_youtube_matching(self):
25 self.assertTrue(YoutubeIE.suitable(u'PLtS2H6bU1M'))
26 self.assertFalse(YoutubeIE.suitable(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
27
28 def test_youtube_channel_matching(self):
29 self.assertTrue(YoutubeChannelIE.suitable('https://www.youtube.com/channel/HCtnHdj3df7iM'))
30 self.assertTrue(YoutubeChannelIE.suitable('https://www.youtube.com/channel/HCtnHdj3df7iM?feature=gb_ch_rec'))
31 self.assertTrue(YoutubeChannelIE.suitable('https://www.youtube.com/channel/HCtnHdj3df7iM/videos'))
32
33 def test_justin_tv_channelid_matching(self):
34 self.assertTrue(JustinTVIE.suitable(u"justin.tv/vanillatv"))
35 self.assertTrue(JustinTVIE.suitable(u"twitch.tv/vanillatv"))
36 self.assertTrue(JustinTVIE.suitable(u"www.justin.tv/vanillatv"))
37 self.assertTrue(JustinTVIE.suitable(u"www.twitch.tv/vanillatv"))
38 self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv"))
39 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv"))
40 self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv/"))
41 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/"))
42
43 def test_justintv_videoid_matching(self):
44 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/b/328087483"))
45
46 def test_justin_tv_chapterid_matching(self):
47 self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/tsm_theoddone/c/2349361"))
48
49 def test_youtube_extract(self):
50 self.assertEqual(YoutubeIE()._extract_id('http://www.youtube.com/watch?&v=BaW_jenozKc'), 'BaW_jenozKc')
51 self.assertEqual(YoutubeIE()._extract_id('https://www.youtube.com/watch?&v=BaW_jenozKc'), 'BaW_jenozKc')
52 self.assertEqual(YoutubeIE()._extract_id('https://www.youtube.com/watch?feature=player_embedded&v=BaW_jenozKc'), 'BaW_jenozKc')
53
54 def test_no_duplicates(self):
55 ies = gen_extractors()
56 for tc in get_testcases():
57 url = tc['url']
58 for ie in ies:
59 if type(ie).__name__ in ['GenericIE', tc['name'] + 'IE']:
60 self.assertTrue(ie.suitable(url), '%s should match URL %r' % (type(ie).__name__, url))
61 else:
62 self.assertFalse(ie.suitable(url), '%s should not match URL %r' % (type(ie).__name__, url))
63
64 def test_keywords(self):
65 ies = gen_extractors()
66 matching_ies = lambda url: [ie.IE_NAME for ie in ies
67 if ie.suitable(url) and ie.IE_NAME != 'generic']
68 self.assertEqual(matching_ies(':ytsubs'), ['youtube:subscriptions'])
69 self.assertEqual(matching_ies(':ytsubscriptions'), ['youtube:subscriptions'])
70 self.assertEqual(matching_ies(':thedailyshow'), ['ComedyCentral'])
71 self.assertEqual(matching_ies(':tds'), ['ComedyCentral'])
72 self.assertEqual(matching_ies(':colbertreport'), ['ComedyCentral'])
73 self.assertEqual(matching_ies(':cr'), ['ComedyCentral'])
74
75
76 if __name__ == '__main__':
77 unittest.main()