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.

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