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.

64 lines
2.1 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 FakeYDL
  8. from youtube_dl.extractor import (
  9. YoutubePlaylistIE,
  10. YoutubeIE,
  11. YoutubeChannelIE,
  12. YoutubeShowIE,
  13. YoutubeTopListIE,
  14. YoutubeSearchURLIE,
  15. )
  16. class TestYoutubeLists(unittest.TestCase):
  17. def assertIsPlaylist(self, info):
  18. """Make sure the info has '_type' set to 'playlist'"""
  19. self.assertEqual(info['_type'], 'playlist')
  20. def test_youtube_playlist_noplaylist(self):
  21. dl = FakeYDL()
  22. dl.params['noplaylist'] = True
  23. ie = YoutubePlaylistIE(dl)
  24. result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
  25. self.assertEqual(result['_type'], 'url')
  26. self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg')
  27. def test_youtube_course(self):
  28. dl = FakeYDL()
  29. ie = YoutubePlaylistIE(dl)
  30. # TODO find a > 100 (paginating?) videos course
  31. result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
  32. entries = result['entries']
  33. self.assertEqual(YoutubeIE().extract_id(entries[0]['url']), 'j9WZyLZCBzs')
  34. self.assertEqual(len(entries), 25)
  35. self.assertEqual(YoutubeIE().extract_id(entries[-1]['url']), 'rYefUsYuEp0')
  36. def test_youtube_mix(self):
  37. dl = FakeYDL()
  38. ie = YoutubePlaylistIE(dl)
  39. result = ie.extract('https://www.youtube.com/watch?v=W01L70IGBgE&index=2&list=RDOQpdSVF_k_w')
  40. entries = result['entries']
  41. self.assertTrue(len(entries) >= 20)
  42. original_video = entries[0]
  43. self.assertEqual(original_video['id'], 'OQpdSVF_k_w')
  44. def test_youtube_toptracks(self):
  45. print('Skipping: The playlist page gives error 500')
  46. return
  47. dl = FakeYDL()
  48. ie = YoutubePlaylistIE(dl)
  49. result = ie.extract('https://www.youtube.com/playlist?list=MCUS')
  50. entries = result['entries']
  51. self.assertEqual(len(entries), 100)
  52. if __name__ == '__main__':
  53. unittest.main()