You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
4.6 KiB

  1. #!/usr/bin/env python
  2. import sys
  3. import unittest
  4. # Allow direct execution
  5. import os
  6. sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  7. from youtube_dl.extractor import YoutubeIE, YoutubePlaylistIE, YoutubeChannelIE, JustinTVIE, gen_extractors
  8. from helper import get_testcases
  9. class TestAllURLsMatching(unittest.TestCase):
  10. def setUp(self):
  11. self.ies = gen_extractors()
  12. def matching_ies(self, url):
  13. return [ie.IE_NAME for ie in self.ies if ie.suitable(url) and ie.IE_NAME != 'generic']
  14. def assertMatch(self, url, ie_list):
  15. self.assertEqual(self.matching_ies(url), ie_list)
  16. def test_youtube_playlist_matching(self):
  17. self.assertTrue(YoutubePlaylistIE.suitable(u'ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8'))
  18. self.assertTrue(YoutubePlaylistIE.suitable(u'UUBABnxM4Ar9ten8Mdjj1j0Q')) #585
  19. self.assertTrue(YoutubePlaylistIE.suitable(u'PL63F0C78739B09958'))
  20. self.assertTrue(YoutubePlaylistIE.suitable(u'https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q'))
  21. self.assertTrue(YoutubePlaylistIE.suitable(u'https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8'))
  22. self.assertTrue(YoutubePlaylistIE.suitable(u'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC'))
  23. self.assertTrue(YoutubePlaylistIE.suitable(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
  24. self.assertFalse(YoutubePlaylistIE.suitable(u'PLtS2H6bU1M'))
  25. def test_youtube_matching(self):
  26. self.assertTrue(YoutubeIE.suitable(u'PLtS2H6bU1M'))
  27. self.assertFalse(YoutubeIE.suitable(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
  28. self.assertMatch('http://youtu.be/BaW_jenozKc', ['youtube'])
  29. self.assertMatch('http://www.youtube.com/v/BaW_jenozKc', ['youtube'])
  30. def test_youtube_channel_matching(self):
  31. self.assertTrue(YoutubeChannelIE.suitable('https://www.youtube.com/channel/HCtnHdj3df7iM'))
  32. self.assertTrue(YoutubeChannelIE.suitable('https://www.youtube.com/channel/HCtnHdj3df7iM?feature=gb_ch_rec'))
  33. self.assertTrue(YoutubeChannelIE.suitable('https://www.youtube.com/channel/HCtnHdj3df7iM/videos'))
  34. def test_youtube_user_matching(self):
  35. self.assertMatch('www.youtube.com/NASAgovVideo/videos', ['youtube:user'])
  36. def test_justin_tv_channelid_matching(self):
  37. self.assertTrue(JustinTVIE.suitable(u"justin.tv/vanillatv"))
  38. self.assertTrue(JustinTVIE.suitable(u"twitch.tv/vanillatv"))
  39. self.assertTrue(JustinTVIE.suitable(u"www.justin.tv/vanillatv"))
  40. self.assertTrue(JustinTVIE.suitable(u"www.twitch.tv/vanillatv"))
  41. self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv"))
  42. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv"))
  43. self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv/"))
  44. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/"))
  45. def test_justintv_videoid_matching(self):
  46. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/b/328087483"))
  47. def test_justin_tv_chapterid_matching(self):
  48. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/tsm_theoddone/c/2349361"))
  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. self.assertEqual(YoutubeIE()._extract_id('https://www.youtube.com/watch_popup?v=BaW_jenozKc'), 'BaW_jenozKc')
  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. def test_keywords(self):
  64. self.assertMatch(':ytsubs', ['youtube:subscriptions'])
  65. self.assertMatch(':ytsubscriptions', ['youtube:subscriptions'])
  66. self.assertMatch(':thedailyshow', ['ComedyCentral'])
  67. self.assertMatch(':tds', ['ComedyCentral'])
  68. self.assertMatch(':colbertreport', ['ComedyCentral'])
  69. self.assertMatch(':cr', ['ComedyCentral'])
  70. if __name__ == '__main__':
  71. unittest.main()