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.

103 lines
3.6 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. YoutubeUserIE,
  10. YoutubePlaylistIE,
  11. YoutubeIE,
  12. YoutubeChannelIE,
  13. YoutubeShowIE,
  14. YoutubeTopListIE,
  15. YoutubeSearchURLIE,
  16. )
  17. class TestYoutubeLists(unittest.TestCase):
  18. def assertIsPlaylist(self, info):
  19. """Make sure the info has '_type' set to 'playlist'"""
  20. self.assertEqual(info['_type'], 'playlist')
  21. def test_youtube_playlist_noplaylist(self):
  22. dl = FakeYDL()
  23. dl.params['noplaylist'] = True
  24. ie = YoutubePlaylistIE(dl)
  25. result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
  26. self.assertEqual(result['_type'], 'url')
  27. self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg')
  28. def test_youtube_course(self):
  29. dl = FakeYDL()
  30. ie = YoutubePlaylistIE(dl)
  31. # TODO find a > 100 (paginating?) videos course
  32. result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
  33. entries = result['entries']
  34. self.assertEqual(YoutubeIE().extract_id(entries[0]['url']), 'j9WZyLZCBzs')
  35. self.assertEqual(len(entries), 25)
  36. self.assertEqual(YoutubeIE().extract_id(entries[-1]['url']), 'rYefUsYuEp0')
  37. def test_youtube_channel(self):
  38. dl = FakeYDL()
  39. ie = YoutubeChannelIE(dl)
  40. #test paginated channel
  41. result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')
  42. self.assertTrue(len(result['entries']) > 90)
  43. #test autogenerated channel
  44. result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
  45. self.assertTrue(len(result['entries']) >= 18)
  46. def test_youtube_user(self):
  47. dl = FakeYDL()
  48. ie = YoutubeUserIE(dl)
  49. result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')
  50. self.assertTrue(len(result['entries']) >= 320)
  51. def test_youtube_show(self):
  52. dl = FakeYDL()
  53. ie = YoutubeShowIE(dl)
  54. result = ie.extract('http://www.youtube.com/show/airdisasters')
  55. self.assertTrue(len(result) >= 3)
  56. def test_youtube_mix(self):
  57. dl = FakeYDL()
  58. ie = YoutubePlaylistIE(dl)
  59. result = ie.extract('https://www.youtube.com/watch?v=W01L70IGBgE&index=2&list=RDOQpdSVF_k_w')
  60. entries = result['entries']
  61. self.assertTrue(len(entries) >= 20)
  62. original_video = entries[0]
  63. self.assertEqual(original_video['id'], 'OQpdSVF_k_w')
  64. def test_youtube_toptracks(self):
  65. print('Skipping: The playlist page gives error 500')
  66. return
  67. dl = FakeYDL()
  68. ie = YoutubePlaylistIE(dl)
  69. result = ie.extract('https://www.youtube.com/playlist?list=MCUS')
  70. entries = result['entries']
  71. self.assertEqual(len(entries), 100)
  72. def test_youtube_toplist(self):
  73. dl = FakeYDL()
  74. ie = YoutubeTopListIE(dl)
  75. result = ie.extract('yttoplist:music:Trending')
  76. entries = result['entries']
  77. self.assertTrue(len(entries) >= 5)
  78. def test_youtube_search_url(self):
  79. dl = FakeYDL()
  80. ie = YoutubeSearchURLIE(dl)
  81. result = ie.extract('https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video')
  82. entries = result['entries']
  83. self.assertIsPlaylist(result)
  84. self.assertEqual(result['title'], 'youtube-dl test video')
  85. self.assertTrue(len(entries) >= 5)
  86. if __name__ == '__main__':
  87. unittest.main()