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.

103 lines
5.2 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. def test_youtube_channel_matching(self):
  32. assertChannel = lambda url: self.assertMatch(url, ['youtube:channel'])
  33. assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM')
  34. assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM?feature=gb_ch_rec')
  35. assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
  36. def test_youtube_user_matching(self):
  37. self.assertMatch('www.youtube.com/NASAgovVideo/videos', ['youtube:user'])
  38. def test_youtube_feeds(self):
  39. self.assertMatch('https://www.youtube.com/feed/watch_later', ['youtube:watch_later'])
  40. self.assertMatch('https://www.youtube.com/feed/subscriptions', ['youtube:subscriptions'])
  41. self.assertMatch('https://www.youtube.com/feed/recommended', ['youtube:recommended'])
  42. self.assertMatch('https://www.youtube.com/my_favorites', ['youtube:favorites'])
  43. def test_youtube_show_matching(self):
  44. self.assertMatch('http://www.youtube.com/show/airdisasters', ['youtube:show'])
  45. def test_justin_tv_channelid_matching(self):
  46. self.assertTrue(JustinTVIE.suitable(u"justin.tv/vanillatv"))
  47. self.assertTrue(JustinTVIE.suitable(u"twitch.tv/vanillatv"))
  48. self.assertTrue(JustinTVIE.suitable(u"www.justin.tv/vanillatv"))
  49. self.assertTrue(JustinTVIE.suitable(u"www.twitch.tv/vanillatv"))
  50. self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv"))
  51. self.assertTrue(JustinTVIE.suitable(u"http://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. def test_justintv_videoid_matching(self):
  55. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/b/328087483"))
  56. def test_justin_tv_chapterid_matching(self):
  57. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/tsm_theoddone/c/2349361"))
  58. def test_youtube_extract(self):
  59. assertExtractId = lambda url, id: self.assertEqual(YoutubeIE()._extract_id(url), id)
  60. assertExtractId('http://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc')
  61. assertExtractId('https://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc')
  62. assertExtractId('https://www.youtube.com/watch?feature=player_embedded&v=BaW_jenozKc', 'BaW_jenozKc')
  63. assertExtractId('https://www.youtube.com/watch_popup?v=BaW_jenozKc', 'BaW_jenozKc')
  64. assertExtractId('http://www.youtube.com/watch?v=BaW_jenozKcsharePLED17F32AD9753930', 'BaW_jenozKc')
  65. assertExtractId('BaW_jenozKc', 'BaW_jenozKc')
  66. def test_no_duplicates(self):
  67. ies = gen_extractors()
  68. for tc in get_testcases():
  69. url = tc['url']
  70. for ie in ies:
  71. if type(ie).__name__ in ['GenericIE', tc['name'] + 'IE']:
  72. self.assertTrue(ie.suitable(url), '%s should match URL %r' % (type(ie).__name__, url))
  73. else:
  74. self.assertFalse(ie.suitable(url), '%s should not match URL %r' % (type(ie).__name__, url))
  75. def test_keywords(self):
  76. self.assertMatch(':ytsubs', ['youtube:subscriptions'])
  77. self.assertMatch(':ytsubscriptions', ['youtube:subscriptions'])
  78. self.assertMatch(':thedailyshow', ['ComedyCentral'])
  79. self.assertMatch(':tds', ['ComedyCentral'])
  80. self.assertMatch(':colbertreport', ['ComedyCentral'])
  81. self.assertMatch(':cr', ['ComedyCentral'])
  82. if __name__ == '__main__':
  83. unittest.main()