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.

98 lines
3.8 KiB

12 years ago
12 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_issue_673(self):
  24. dl = FakeYDL()
  25. ie = YoutubePlaylistIE(dl)
  26. result = ie.extract('PLBB231211A4F62143')[0]
  27. self.assertTrue(len(result['entries']) > 25)
  28. def test_youtube_playlist_long(self):
  29. dl = FakeYDL()
  30. ie = YoutubePlaylistIE(dl)
  31. result = ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')[0]
  32. self.assertIsPlaylist(result)
  33. self.assertTrue(len(result['entries']) >= 799)
  34. def test_youtube_playlist_with_deleted(self):
  35. #651
  36. dl = FakeYDL()
  37. ie = YoutubePlaylistIE(dl)
  38. result = ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')[0]
  39. ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']]
  40. self.assertFalse('pElCt5oNDuI' in ytie_results)
  41. self.assertFalse('KdPEApIVdWM' in ytie_results)
  42. def test_youtube_playlist_empty(self):
  43. dl = FakeYDL()
  44. ie = YoutubePlaylistIE(dl)
  45. result = ie.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')[0]
  46. self.assertIsPlaylist(result)
  47. self.assertEqual(len(result['entries']), 0)
  48. def test_youtube_course(self):
  49. dl = FakeYDL()
  50. ie = YoutubePlaylistIE(dl)
  51. # TODO find a > 100 (paginating?) videos course
  52. result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')[0]
  53. entries = result['entries']
  54. self.assertEqual(YoutubeIE()._extract_id(entries[0]['url']), 'j9WZyLZCBzs')
  55. self.assertEqual(len(entries), 25)
  56. self.assertEqual(YoutubeIE()._extract_id(entries[-1]['url']), 'rYefUsYuEp0')
  57. def test_youtube_channel(self):
  58. dl = FakeYDL()
  59. ie = YoutubeChannelIE(dl)
  60. #test paginated channel
  61. result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')[0]
  62. self.assertTrue(len(result['entries']) > 90)
  63. #test autogenerated channel
  64. result = ie.extract('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')[0]
  65. self.assertTrue(len(result['entries']) >= 18)
  66. def test_youtube_user(self):
  67. dl = FakeYDL()
  68. ie = YoutubeUserIE(dl)
  69. result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')[0]
  70. self.assertTrue(len(result['entries']) >= 320)
  71. def test_youtube_safe_search(self):
  72. dl = FakeYDL()
  73. ie = YoutubePlaylistIE(dl)
  74. result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')[0]
  75. self.assertEqual(len(result['entries']), 2)
  76. def test_youtube_show(self):
  77. dl = FakeYDL()
  78. ie = YoutubeShowIE(dl)
  79. result = ie.extract('http://www.youtube.com/show/airdisasters')
  80. self.assertTrue(len(result) >= 4)
  81. if __name__ == '__main__':
  82. unittest.main()