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.

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