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.

78 lines
4.4 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. self.assertEqual(YoutubeIE()._extract_id('https://www.youtube.com/watch_popup?v=BaW_jenozKc'), 'BaW_jenozKc')
  44. def test_no_duplicates(self):
  45. ies = gen_extractors()
  46. for tc in get_testcases():
  47. url = tc['url']
  48. for ie in ies:
  49. if type(ie).__name__ in ['GenericIE', tc['name'] + 'IE']:
  50. self.assertTrue(ie.suitable(url), '%s should match URL %r' % (type(ie).__name__, url))
  51. else:
  52. self.assertFalse(ie.suitable(url), '%s should not match URL %r' % (type(ie).__name__, url))
  53. def test_keywords(self):
  54. ies = gen_extractors()
  55. matching_ies = lambda url: [ie.IE_NAME for ie in ies
  56. if ie.suitable(url) and ie.IE_NAME != 'generic']
  57. self.assertEqual(matching_ies(':ytsubs'), ['youtube:subscriptions'])
  58. self.assertEqual(matching_ies(':ytsubscriptions'), ['youtube:subscriptions'])
  59. self.assertEqual(matching_ies(':thedailyshow'), ['ComedyCentral'])
  60. self.assertEqual(matching_ies(':tds'), ['ComedyCentral'])
  61. self.assertEqual(matching_ies(':colbertreport'), ['ComedyCentral'])
  62. self.assertEqual(matching_ies(':cr'), ['ComedyCentral'])
  63. if __name__ == '__main__':
  64. unittest.main()