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.

87 lines
3.2 KiB

12 years ago
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.InfoExtractors import YoutubeUserIE, YoutubePlaylistIE, YoutubeIE
  9. from youtube_dl.utils import *
  10. from youtube_dl.FileDownloader import FileDownloader
  11. PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
  12. with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
  13. parameters = json.load(pf)
  14. # General configuration (from __init__, not very elegant...)
  15. jar = compat_cookiejar.CookieJar()
  16. cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
  17. proxy_handler = compat_urllib_request.ProxyHandler()
  18. opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
  19. compat_urllib_request.install_opener(opener)
  20. class FakeDownloader(FileDownloader):
  21. def __init__(self):
  22. self.result = []
  23. self.params = parameters
  24. def to_screen(self, s):
  25. print(s)
  26. def trouble(self, s):
  27. raise Exception(s)
  28. def extract_info(self, url):
  29. self.result.append(url)
  30. return url
  31. class TestYoutubeLists(unittest.TestCase):
  32. def test_youtube_playlist(self):
  33. dl = FakeDownloader()
  34. ie = YoutubePlaylistIE(dl)
  35. ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
  36. ytie_results = [YoutubeIE()._extract_id(url) for url in dl.result]
  37. self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
  38. def test_issue_673(self):
  39. dl = FakeDownloader()
  40. ie = YoutubePlaylistIE(dl)
  41. ie.extract('PLBB231211A4F62143')
  42. self.assertTrue(len(dl.result) > 40)
  43. def test_youtube_playlist_long(self):
  44. dl = FakeDownloader()
  45. ie = YoutubePlaylistIE(dl)
  46. ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
  47. self.assertTrue(len(dl.result) >= 799)
  48. def test_youtube_playlist_with_deleted(self):
  49. #651
  50. dl = FakeDownloader()
  51. ie = YoutubePlaylistIE(dl)
  52. ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
  53. ytie_results = [YoutubeIE()._extract_id(url) for url in dl.result]
  54. self.assertFalse('pElCt5oNDuI' in ytie_results)
  55. self.assertFalse('KdPEApIVdWM' in ytie_results)
  56. def test_youtube_course(self):
  57. dl = FakeDownloader()
  58. ie = YoutubePlaylistIE(dl)
  59. # TODO find a > 100 (paginating?) videos course
  60. ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
  61. self.assertEqual(YoutubeIE()._extract_id(dl.result[0]), 'j9WZyLZCBzs')
  62. self.assertEqual(len(dl.result), 25)
  63. self.assertEqual(YoutubeIE()._extract_id(dl.result[-1]), 'rYefUsYuEp0')
  64. def test_youtube_channel(self):
  65. # I give up, please find a channel that does paginate and test this like test_youtube_playlist_long
  66. pass # TODO
  67. def test_youtube_user(self):
  68. dl = FakeDownloader()
  69. ie = YoutubeUserIE(dl)
  70. ie.extract('https://www.youtube.com/user/TheLinuxFoundation')
  71. self.assertTrue(len(dl.result) >= 320)
  72. if __name__ == '__main__':
  73. unittest.main()