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.

70 lines
2.5 KiB

  1. #!/usr/bin/env python
  2. import sys
  3. import unittest
  4. import socket
  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.InfoExtractors import YoutubeUserIE,YoutubePlaylistIE
  9. from youtube_dl.utils import *
  10. # General configuration (from __init__, not very elegant...)
  11. jar = compat_cookiejar.CookieJar()
  12. cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
  13. proxy_handler = compat_urllib_request.ProxyHandler()
  14. opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
  15. compat_urllib_request.install_opener(opener)
  16. socket.setdefaulttimeout(300) # 5 minutes should be enough (famous last words)
  17. class FakeDownloader(object):
  18. def __init__(self):
  19. self.result = []
  20. self.params = {}
  21. def to_screen(self, s):
  22. print(s)
  23. def trouble(self, s):
  24. raise Exception(s)
  25. def download(self, x):
  26. self.result.append(x)
  27. class TestYoutubeLists(unittest.TestCase):
  28. def test_youtube_playlist(self):
  29. DL = FakeDownloader()
  30. IE = YoutubePlaylistIE(DL)
  31. IE.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
  32. self.assertEqual(DL.result, [
  33. ['http://www.youtube.com/watch?v=bV9L5Ht9LgY'],
  34. ['http://www.youtube.com/watch?v=FXxLjLQi3Fg'],
  35. ['http://www.youtube.com/watch?v=tU3Bgo5qJZE']
  36. ])
  37. def test_youtube_playlist_long(self):
  38. DL = FakeDownloader()
  39. IE = YoutubePlaylistIE(DL)
  40. IE.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
  41. self.assertTrue(len(DL.result) >= 799)
  42. def test_youtube_course(self):
  43. DL = FakeDownloader()
  44. IE = YoutubePlaylistIE(DL)
  45. # TODO find a > 100 (paginating?) videos course
  46. IE.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
  47. self.assertEqual(DL.result[0], ['http://www.youtube.com/watch?v=j9WZyLZCBzs'])
  48. self.assertEqual(len(DL.result), 25)
  49. self.assertEqual(DL.result[-1], ['http://www.youtube.com/watch?v=rYefUsYuEp0'])
  50. def test_youtube_channel(self):
  51. """I give up, please find a channel that does paginate and test this like test_youtube_playlist_long"""
  52. pass # TODO
  53. def test_youtube_user(self):
  54. DL = FakeDownloader()
  55. IE = YoutubeUserIE(DL)
  56. IE.extract('https://www.youtube.com/user/TheLinuxFoundation')
  57. self.assertTrue(len(DL.result) >= 320)
  58. if __name__ == '__main__':
  59. unittest.main()