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.

147 lines
5.5 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(self):
  22. dl = FakeYDL()
  23. ie = YoutubePlaylistIE(dl)
  24. result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
  25. self.assertIsPlaylist(result)
  26. self.assertEqual(result['title'], 'ytdl test PL')
  27. ytie_results = [YoutubeIE().extract_id(url['url']) for url in result['entries']]
  28. self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
  29. def test_youtube_playlist_noplaylist(self):
  30. dl = FakeYDL()
  31. dl.params['noplaylist'] = True
  32. ie = YoutubePlaylistIE(dl)
  33. result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
  34. self.assertEqual(result['_type'], 'url')
  35. self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg')
  36. def test_issue_673(self):
  37. dl = FakeYDL()
  38. ie = YoutubePlaylistIE(dl)
  39. result = ie.extract('PLBB231211A4F62143')
  40. self.assertTrue(len(result['entries']) > 25)
  41. def test_youtube_playlist_long(self):
  42. dl = FakeYDL()
  43. ie = YoutubePlaylistIE(dl)
  44. result = ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
  45. self.assertIsPlaylist(result)
  46. self.assertTrue(len(result['entries']) >= 799)
  47. def test_youtube_playlist_with_deleted(self):
  48. #651
  49. dl = FakeYDL()
  50. ie = YoutubePlaylistIE(dl)
  51. result = ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
  52. ytie_results = [YoutubeIE().extract_id(url['url']) for url in result['entries']]
  53. self.assertFalse('pElCt5oNDuI' in ytie_results)
  54. self.assertFalse('KdPEApIVdWM' in ytie_results)
  55. def test_youtube_playlist_empty(self):
  56. dl = FakeYDL()
  57. ie = YoutubePlaylistIE(dl)
  58. result = ie.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')
  59. self.assertIsPlaylist(result)
  60. self.assertEqual(len(result['entries']), 0)
  61. def test_youtube_course(self):
  62. dl = FakeYDL()
  63. ie = YoutubePlaylistIE(dl)
  64. # TODO find a > 100 (paginating?) videos course
  65. result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
  66. entries = result['entries']
  67. self.assertEqual(YoutubeIE().extract_id(entries[0]['url']), 'j9WZyLZCBzs')
  68. self.assertEqual(len(entries), 25)
  69. self.assertEqual(YoutubeIE().extract_id(entries[-1]['url']), 'rYefUsYuEp0')
  70. def test_youtube_channel(self):
  71. dl = FakeYDL()
  72. ie = YoutubeChannelIE(dl)
  73. #test paginated channel
  74. result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')
  75. self.assertTrue(len(result['entries']) > 90)
  76. #test autogenerated channel
  77. result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
  78. self.assertTrue(len(result['entries']) >= 18)
  79. def test_youtube_user(self):
  80. dl = FakeYDL()
  81. ie = YoutubeUserIE(dl)
  82. result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')
  83. self.assertTrue(len(result['entries']) >= 320)
  84. def test_youtube_safe_search(self):
  85. dl = FakeYDL()
  86. ie = YoutubePlaylistIE(dl)
  87. result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')
  88. self.assertEqual(len(result['entries']), 2)
  89. def test_youtube_show(self):
  90. dl = FakeYDL()
  91. ie = YoutubeShowIE(dl)
  92. result = ie.extract('http://www.youtube.com/show/airdisasters')
  93. self.assertTrue(len(result) >= 3)
  94. def test_youtube_mix(self):
  95. dl = FakeYDL()
  96. ie = YoutubePlaylistIE(dl)
  97. result = ie.extract('https://www.youtube.com/watch?v=W01L70IGBgE&index=2&list=RDOQpdSVF_k_w')
  98. entries = result['entries']
  99. self.assertTrue(len(entries) >= 20)
  100. original_video = entries[0]
  101. self.assertEqual(original_video['id'], 'OQpdSVF_k_w')
  102. def test_youtube_toptracks(self):
  103. print('Skipping: The playlist page gives error 500')
  104. return
  105. dl = FakeYDL()
  106. ie = YoutubePlaylistIE(dl)
  107. result = ie.extract('https://www.youtube.com/playlist?list=MCUS')
  108. entries = result['entries']
  109. self.assertEqual(len(entries), 100)
  110. def test_youtube_toplist(self):
  111. dl = FakeYDL()
  112. ie = YoutubeTopListIE(dl)
  113. result = ie.extract('yttoplist:music:Trending')
  114. entries = result['entries']
  115. self.assertTrue(len(entries) >= 5)
  116. def test_youtube_search_url(self):
  117. dl = FakeYDL()
  118. ie = YoutubeSearchURLIE(dl)
  119. result = ie.extract('https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video')
  120. entries = result['entries']
  121. self.assertIsPlaylist(result)
  122. self.assertEqual(result['title'], 'youtube-dl test video')
  123. self.assertTrue(len(entries) >= 5)
  124. if __name__ == '__main__':
  125. unittest.main()