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.

104 lines
5.3 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. assertPlaylist = lambda url: self.assertMatch(url, ['youtube:playlist'])
  18. assertPlaylist(u'ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
  19. assertPlaylist(u'UUBABnxM4Ar9ten8Mdjj1j0Q') #585
  20. assertPlaylist(u'PL63F0C78739B09958')
  21. assertPlaylist(u'https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
  22. assertPlaylist(u'https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
  23. assertPlaylist(u'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
  24. assertPlaylist(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012') #668
  25. self.assertFalse('youtube:playlist' in self.matching_ies(u'PLtS2H6bU1M'))
  26. def test_youtube_matching(self):
  27. self.assertTrue(YoutubeIE.suitable(u'PLtS2H6bU1M'))
  28. self.assertFalse(YoutubeIE.suitable(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
  29. self.assertMatch('http://youtu.be/BaW_jenozKc', ['youtube'])
  30. self.assertMatch('http://www.youtube.com/v/BaW_jenozKc', ['youtube'])
  31. self.assertMatch('https://youtube.googleapis.com/v/BaW_jenozKc', ['youtube'])
  32. def test_youtube_channel_matching(self):
  33. assertChannel = lambda url: self.assertMatch(url, ['youtube:channel'])
  34. assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM')
  35. assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM?feature=gb_ch_rec')
  36. assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
  37. def test_youtube_user_matching(self):
  38. self.assertMatch('www.youtube.com/NASAgovVideo/videos', ['youtube:user'])
  39. def test_youtube_feeds(self):
  40. self.assertMatch('https://www.youtube.com/feed/watch_later', ['youtube:watch_later'])
  41. self.assertMatch('https://www.youtube.com/feed/subscriptions', ['youtube:subscriptions'])
  42. self.assertMatch('https://www.youtube.com/feed/recommended', ['youtube:recommended'])
  43. self.assertMatch('https://www.youtube.com/my_favorites', ['youtube:favorites'])
  44. def test_youtube_show_matching(self):
  45. self.assertMatch('http://www.youtube.com/show/airdisasters', ['youtube:show'])
  46. def test_justin_tv_channelid_matching(self):
  47. self.assertTrue(JustinTVIE.suitable(u"justin.tv/vanillatv"))
  48. self.assertTrue(JustinTVIE.suitable(u"twitch.tv/vanillatv"))
  49. self.assertTrue(JustinTVIE.suitable(u"www.justin.tv/vanillatv"))
  50. self.assertTrue(JustinTVIE.suitable(u"www.twitch.tv/vanillatv"))
  51. self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv"))
  52. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv"))
  53. self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv/"))
  54. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/"))
  55. def test_justintv_videoid_matching(self):
  56. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/b/328087483"))
  57. def test_justin_tv_chapterid_matching(self):
  58. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/tsm_theoddone/c/2349361"))
  59. def test_youtube_extract(self):
  60. assertExtractId = lambda url, id: self.assertEqual(YoutubeIE()._extract_id(url), id)
  61. assertExtractId('http://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc')
  62. assertExtractId('https://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc')
  63. assertExtractId('https://www.youtube.com/watch?feature=player_embedded&v=BaW_jenozKc', 'BaW_jenozKc')
  64. assertExtractId('https://www.youtube.com/watch_popup?v=BaW_jenozKc', 'BaW_jenozKc')
  65. assertExtractId('http://www.youtube.com/watch?v=BaW_jenozKcsharePLED17F32AD9753930', 'BaW_jenozKc')
  66. assertExtractId('BaW_jenozKc', 'BaW_jenozKc')
  67. def test_no_duplicates(self):
  68. ies = gen_extractors()
  69. for tc in get_testcases():
  70. url = tc['url']
  71. for ie in ies:
  72. if type(ie).__name__ in ['GenericIE', tc['name'] + 'IE']:
  73. self.assertTrue(ie.suitable(url), '%s should match URL %r' % (type(ie).__name__, url))
  74. else:
  75. self.assertFalse(ie.suitable(url), '%s should not match URL %r' % (type(ie).__name__, url))
  76. def test_keywords(self):
  77. self.assertMatch(':ytsubs', ['youtube:subscriptions'])
  78. self.assertMatch(':ytsubscriptions', ['youtube:subscriptions'])
  79. self.assertMatch(':thedailyshow', ['ComedyCentral'])
  80. self.assertMatch(':tds', ['ComedyCentral'])
  81. self.assertMatch(':colbertreport', ['ComedyCentral'])
  82. self.assertMatch(':cr', ['ComedyCentral'])
  83. if __name__ == '__main__':
  84. unittest.main()