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.

128 lines
4.7 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. )
  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(self):
  21. dl = FakeYDL()
  22. ie = YoutubePlaylistIE(dl)
  23. result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
  24. self.assertIsPlaylist(result)
  25. self.assertEqual(result['title'], 'ytdl test PL')
  26. ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']]
  27. self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
  28. def test_youtube_playlist_noplaylist(self):
  29. dl = FakeYDL()
  30. dl.params['noplaylist'] = True
  31. ie = YoutubePlaylistIE(dl)
  32. result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
  33. self.assertEqual(result['_type'], 'url')
  34. self.assertEqual(YoutubeIE()._extract_id(result['url']), 'FXxLjLQi3Fg')
  35. def test_issue_673(self):
  36. dl = FakeYDL()
  37. ie = YoutubePlaylistIE(dl)
  38. result = ie.extract('PLBB231211A4F62143')
  39. self.assertTrue(len(result['entries']) > 25)
  40. def test_youtube_playlist_long(self):
  41. dl = FakeYDL()
  42. ie = YoutubePlaylistIE(dl)
  43. result = ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
  44. self.assertIsPlaylist(result)
  45. self.assertTrue(len(result['entries']) >= 799)
  46. def test_youtube_playlist_with_deleted(self):
  47. #651
  48. dl = FakeYDL()
  49. ie = YoutubePlaylistIE(dl)
  50. result = ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
  51. ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']]
  52. self.assertFalse('pElCt5oNDuI' in ytie_results)
  53. self.assertFalse('KdPEApIVdWM' in ytie_results)
  54. def test_youtube_playlist_empty(self):
  55. dl = FakeYDL()
  56. ie = YoutubePlaylistIE(dl)
  57. result = ie.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')
  58. self.assertIsPlaylist(result)
  59. self.assertEqual(len(result['entries']), 0)
  60. def test_youtube_course(self):
  61. dl = FakeYDL()
  62. ie = YoutubePlaylistIE(dl)
  63. # TODO find a > 100 (paginating?) videos course
  64. result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
  65. entries = result['entries']
  66. self.assertEqual(YoutubeIE()._extract_id(entries[0]['url']), 'j9WZyLZCBzs')
  67. self.assertEqual(len(entries), 25)
  68. self.assertEqual(YoutubeIE()._extract_id(entries[-1]['url']), 'rYefUsYuEp0')
  69. def test_youtube_channel(self):
  70. dl = FakeYDL()
  71. ie = YoutubeChannelIE(dl)
  72. #test paginated channel
  73. result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')
  74. self.assertTrue(len(result['entries']) > 90)
  75. #test autogenerated channel
  76. result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
  77. self.assertTrue(len(result['entries']) >= 18)
  78. def test_youtube_user(self):
  79. dl = FakeYDL()
  80. ie = YoutubeUserIE(dl)
  81. result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')
  82. self.assertTrue(len(result['entries']) >= 320)
  83. def test_youtube_safe_search(self):
  84. dl = FakeYDL()
  85. ie = YoutubePlaylistIE(dl)
  86. result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')
  87. self.assertEqual(len(result['entries']), 2)
  88. def test_youtube_show(self):
  89. dl = FakeYDL()
  90. ie = YoutubeShowIE(dl)
  91. result = ie.extract('http://www.youtube.com/show/airdisasters')
  92. self.assertTrue(len(result) >= 3)
  93. def test_youtube_mix(self):
  94. dl = FakeYDL()
  95. ie = YoutubePlaylistIE(dl)
  96. result = ie.extract('http://www.youtube.com/watch?v=lLJf9qJHR3E&list=RDrjFaenf1T-Y')
  97. entries = result['entries']
  98. self.assertTrue(len(entries) >= 20)
  99. original_video = entries[0]
  100. self.assertEqual(original_video['id'], 'rjFaenf1T-Y')
  101. def test_youtube_toplist(self):
  102. dl = FakeYDL()
  103. ie = YoutubeTopListIE(dl)
  104. result = ie.extract('yttoplist:music:Top Tracks')
  105. entries = result['entries']
  106. self.assertTrue(len(entries) >= 5)
  107. if __name__ == '__main__':
  108. unittest.main()