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.

106 lines
4.2 KiB

12 years ago
11 years ago
  1. #!/usr/bin/env python
  2. import sys
  3. import unittest
  4. import json
  5. # Allow direct execution
  6. import os
  7. sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  8. from youtube_dl.extractor import YoutubeUserIE, YoutubePlaylistIE, YoutubeIE, YoutubeChannelIE, YoutubeShowIE
  9. from youtube_dl.utils import *
  10. from helper import FakeYDL
  11. class TestYoutubeLists(unittest.TestCase):
  12. def assertIsPlaylist(self,info):
  13. """Make sure the info has '_type' set to 'playlist'"""
  14. self.assertEqual(info['_type'], 'playlist')
  15. def test_youtube_playlist(self):
  16. dl = FakeYDL()
  17. ie = YoutubePlaylistIE(dl)
  18. result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')[0]
  19. self.assertIsPlaylist(result)
  20. self.assertEqual(result['title'], 'ytdl test PL')
  21. ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']]
  22. self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
  23. def test_youtube_playlist_noplaylist(self):
  24. dl = FakeYDL()
  25. dl.params['noplaylist'] = True
  26. ie = YoutubePlaylistIE(dl)
  27. result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
  28. self.assertEqual(result['_type'], 'url')
  29. self.assertEqual(YoutubeIE()._extract_id(result['url']), 'FXxLjLQi3Fg')
  30. def test_issue_673(self):
  31. dl = FakeYDL()
  32. ie = YoutubePlaylistIE(dl)
  33. result = ie.extract('PLBB231211A4F62143')[0]
  34. self.assertTrue(len(result['entries']) > 25)
  35. def test_youtube_playlist_long(self):
  36. dl = FakeYDL()
  37. ie = YoutubePlaylistIE(dl)
  38. result = ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')[0]
  39. self.assertIsPlaylist(result)
  40. self.assertTrue(len(result['entries']) >= 799)
  41. def test_youtube_playlist_with_deleted(self):
  42. #651
  43. dl = FakeYDL()
  44. ie = YoutubePlaylistIE(dl)
  45. result = ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')[0]
  46. ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']]
  47. self.assertFalse('pElCt5oNDuI' in ytie_results)
  48. self.assertFalse('KdPEApIVdWM' in ytie_results)
  49. def test_youtube_playlist_empty(self):
  50. dl = FakeYDL()
  51. ie = YoutubePlaylistIE(dl)
  52. result = ie.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')[0]
  53. self.assertIsPlaylist(result)
  54. self.assertEqual(len(result['entries']), 0)
  55. def test_youtube_course(self):
  56. dl = FakeYDL()
  57. ie = YoutubePlaylistIE(dl)
  58. # TODO find a > 100 (paginating?) videos course
  59. result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')[0]
  60. entries = result['entries']
  61. self.assertEqual(YoutubeIE()._extract_id(entries[0]['url']), 'j9WZyLZCBzs')
  62. self.assertEqual(len(entries), 25)
  63. self.assertEqual(YoutubeIE()._extract_id(entries[-1]['url']), 'rYefUsYuEp0')
  64. def test_youtube_channel(self):
  65. dl = FakeYDL()
  66. ie = YoutubeChannelIE(dl)
  67. #test paginated channel
  68. result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')[0]
  69. self.assertTrue(len(result['entries']) > 90)
  70. #test autogenerated channel
  71. result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')[0]
  72. self.assertTrue(len(result['entries']) >= 18)
  73. def test_youtube_user(self):
  74. dl = FakeYDL()
  75. ie = YoutubeUserIE(dl)
  76. result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')[0]
  77. self.assertTrue(len(result['entries']) >= 320)
  78. def test_youtube_safe_search(self):
  79. dl = FakeYDL()
  80. ie = YoutubePlaylistIE(dl)
  81. result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')[0]
  82. self.assertEqual(len(result['entries']), 2)
  83. def test_youtube_show(self):
  84. dl = FakeYDL()
  85. ie = YoutubeShowIE(dl)
  86. result = ie.extract('http://www.youtube.com/show/airdisasters')
  87. self.assertTrue(len(result) >= 4)
  88. if __name__ == '__main__':
  89. unittest.main()