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.

70 lines
2.5 KiB

10 years ago
  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals
  3. # Allow direct execution
  4. import os
  5. import sys
  6. import unittest
  7. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  8. from test.helper import FakeYDL
  9. from youtube_dl.extractor import (
  10. YoutubePlaylistIE,
  11. YoutubeIE,
  12. )
  13. class TestYoutubeLists(unittest.TestCase):
  14. def assertIsPlaylist(self, info):
  15. """Make sure the info has '_type' set to 'playlist'"""
  16. self.assertEqual(info['_type'], 'playlist')
  17. def test_youtube_playlist_noplaylist(self):
  18. dl = FakeYDL()
  19. dl.params['noplaylist'] = True
  20. ie = YoutubePlaylistIE(dl)
  21. result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
  22. self.assertEqual(result['_type'], 'url')
  23. self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg')
  24. def test_youtube_course(self):
  25. dl = FakeYDL()
  26. ie = YoutubePlaylistIE(dl)
  27. # TODO find a > 100 (paginating?) videos course
  28. result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
  29. entries = list(result['entries'])
  30. self.assertEqual(YoutubeIE().extract_id(entries[0]['url']), 'j9WZyLZCBzs')
  31. self.assertEqual(len(entries), 25)
  32. self.assertEqual(YoutubeIE().extract_id(entries[-1]['url']), 'rYefUsYuEp0')
  33. def test_youtube_mix(self):
  34. dl = FakeYDL()
  35. ie = YoutubePlaylistIE(dl)
  36. result = ie.extract('https://www.youtube.com/watch?v=W01L70IGBgE&index=2&list=RDOQpdSVF_k_w')
  37. entries = result['entries']
  38. self.assertTrue(len(entries) >= 50)
  39. original_video = entries[0]
  40. self.assertEqual(original_video['id'], 'OQpdSVF_k_w')
  41. def test_youtube_toptracks(self):
  42. print('Skipping: The playlist page gives error 500')
  43. return
  44. dl = FakeYDL()
  45. ie = YoutubePlaylistIE(dl)
  46. result = ie.extract('https://www.youtube.com/playlist?list=MCUS')
  47. entries = result['entries']
  48. self.assertEqual(len(entries), 100)
  49. def test_youtube_flat_playlist_titles(self):
  50. dl = FakeYDL()
  51. dl.params['extract_flat'] = True
  52. ie = YoutubePlaylistIE(dl)
  53. result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
  54. self.assertIsPlaylist(result)
  55. for entry in result['entries']:
  56. self.assertTrue(entry.get('title'))
  57. if __name__ == '__main__':
  58. unittest.main()