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.

60 lines
2.1 KiB

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