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.

112 lines
4.2 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, global_setup
  8. global_setup()
  9. from youtube_dl.extractor import (
  10. YoutubeUserIE,
  11. YoutubePlaylistIE,
  12. YoutubeIE,
  13. YoutubeChannelIE,
  14. YoutubeShowIE,
  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')[0]
  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')[0]
  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')[0]
  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')[0]
  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')[0]
  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')[0]
  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')[0]
  74. self.assertTrue(len(result['entries']) > 90)
  75. #test autogenerated channel
  76. result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')[0]
  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')[0]
  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')[0]
  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) >= 4)
  93. if __name__ == '__main__':
  94. unittest.main()