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.

110 lines
5.3 KiB

  1. #!/usr/bin/env python
  2. # Allow direct execution
  3. import os
  4. import sys
  5. import unittest
  6. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  7. from test.helper import get_testcases
  8. from youtube_dl.extractor import (
  9. gen_extractors,
  10. JustinTVIE,
  11. YoutubeIE,
  12. )
  13. class TestAllURLsMatching(unittest.TestCase):
  14. def setUp(self):
  15. self.ies = gen_extractors()
  16. def matching_ies(self, url):
  17. return [ie.IE_NAME for ie in self.ies if ie.suitable(url) and ie.IE_NAME != 'generic']
  18. def assertMatch(self, url, ie_list):
  19. self.assertEqual(self.matching_ies(url), ie_list)
  20. def test_youtube_playlist_matching(self):
  21. assertPlaylist = lambda url: self.assertMatch(url, ['youtube:playlist'])
  22. assertPlaylist(u'ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
  23. assertPlaylist(u'UUBABnxM4Ar9ten8Mdjj1j0Q') #585
  24. assertPlaylist(u'PL63F0C78739B09958')
  25. assertPlaylist(u'https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
  26. assertPlaylist(u'https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
  27. assertPlaylist(u'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
  28. assertPlaylist(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012') #668
  29. self.assertFalse('youtube:playlist' in self.matching_ies(u'PLtS2H6bU1M'))
  30. def test_youtube_matching(self):
  31. self.assertTrue(YoutubeIE.suitable(u'PLtS2H6bU1M'))
  32. self.assertFalse(YoutubeIE.suitable(u'https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) #668
  33. self.assertMatch('http://youtu.be/BaW_jenozKc', ['youtube'])
  34. self.assertMatch('http://www.youtube.com/v/BaW_jenozKc', ['youtube'])
  35. self.assertMatch('https://youtube.googleapis.com/v/BaW_jenozKc', ['youtube'])
  36. def test_youtube_channel_matching(self):
  37. assertChannel = lambda url: self.assertMatch(url, ['youtube:channel'])
  38. assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM')
  39. assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM?feature=gb_ch_rec')
  40. assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
  41. def test_youtube_user_matching(self):
  42. self.assertMatch('www.youtube.com/NASAgovVideo/videos', ['youtube:user'])
  43. def test_youtube_feeds(self):
  44. self.assertMatch('https://www.youtube.com/feed/watch_later', ['youtube:watch_later'])
  45. self.assertMatch('https://www.youtube.com/feed/subscriptions', ['youtube:subscriptions'])
  46. self.assertMatch('https://www.youtube.com/feed/recommended', ['youtube:recommended'])
  47. self.assertMatch('https://www.youtube.com/my_favorites', ['youtube:favorites'])
  48. def test_youtube_show_matching(self):
  49. self.assertMatch('http://www.youtube.com/show/airdisasters', ['youtube:show'])
  50. def test_justin_tv_channelid_matching(self):
  51. self.assertTrue(JustinTVIE.suitable(u"justin.tv/vanillatv"))
  52. self.assertTrue(JustinTVIE.suitable(u"twitch.tv/vanillatv"))
  53. self.assertTrue(JustinTVIE.suitable(u"www.justin.tv/vanillatv"))
  54. self.assertTrue(JustinTVIE.suitable(u"www.twitch.tv/vanillatv"))
  55. self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv"))
  56. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv"))
  57. self.assertTrue(JustinTVIE.suitable(u"http://www.justin.tv/vanillatv/"))
  58. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/"))
  59. def test_justintv_videoid_matching(self):
  60. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/vanillatv/b/328087483"))
  61. def test_justin_tv_chapterid_matching(self):
  62. self.assertTrue(JustinTVIE.suitable(u"http://www.twitch.tv/tsm_theoddone/c/2349361"))
  63. def test_youtube_extract(self):
  64. assertExtractId = lambda url, id: self.assertEqual(YoutubeIE()._extract_id(url), id)
  65. assertExtractId('http://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc')
  66. assertExtractId('https://www.youtube.com/watch?&v=BaW_jenozKc', 'BaW_jenozKc')
  67. assertExtractId('https://www.youtube.com/watch?feature=player_embedded&v=BaW_jenozKc', 'BaW_jenozKc')
  68. assertExtractId('https://www.youtube.com/watch_popup?v=BaW_jenozKc', 'BaW_jenozKc')
  69. assertExtractId('http://www.youtube.com/watch?v=BaW_jenozKcsharePLED17F32AD9753930', 'BaW_jenozKc')
  70. assertExtractId('BaW_jenozKc', 'BaW_jenozKc')
  71. def test_no_duplicates(self):
  72. ies = gen_extractors()
  73. for tc in get_testcases():
  74. url = tc['url']
  75. for ie in ies:
  76. if type(ie).__name__ in ['GenericIE', tc['name'] + 'IE']:
  77. self.assertTrue(ie.suitable(url), '%s should match URL %r' % (type(ie).__name__, url))
  78. else:
  79. self.assertFalse(ie.suitable(url), '%s should not match URL %r' % (type(ie).__name__, url))
  80. def test_keywords(self):
  81. self.assertMatch(':ytsubs', ['youtube:subscriptions'])
  82. self.assertMatch(':ytsubscriptions', ['youtube:subscriptions'])
  83. self.assertMatch(':thedailyshow', ['ComedyCentral'])
  84. self.assertMatch(':tds', ['ComedyCentral'])
  85. self.assertMatch(':colbertreport', ['ComedyCentral'])
  86. self.assertMatch(':cr', ['ComedyCentral'])
  87. if __name__ == '__main__':
  88. unittest.main()