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.

55 lines
1.5 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 global_setup, try_rm
  8. global_setup()
  9. from youtube_dl import YoutubeDL
  10. def _download_restricted(url, filename, age):
  11. """ Returns true iff the file has been downloaded """
  12. params = {
  13. 'age_limit': age,
  14. 'skip_download': True,
  15. 'writeinfojson': True,
  16. "outtmpl": "%(id)s.%(ext)s",
  17. }
  18. ydl = YoutubeDL(params)
  19. ydl.add_default_info_extractors()
  20. json_filename = os.path.splitext(filename)[0] + '.info.json'
  21. try_rm(json_filename)
  22. ydl.download([url])
  23. res = os.path.exists(json_filename)
  24. try_rm(json_filename)
  25. return res
  26. class TestAgeRestriction(unittest.TestCase):
  27. def _assert_restricted(self, url, filename, age, old_age=None):
  28. self.assertTrue(_download_restricted(url, filename, old_age))
  29. self.assertFalse(_download_restricted(url, filename, age))
  30. def test_youtube(self):
  31. self._assert_restricted('07FYdnEawAQ', '07FYdnEawAQ.mp4', 10)
  32. def test_youporn(self):
  33. self._assert_restricted(
  34. 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
  35. '505835.mp4', 2, old_age=25)
  36. def test_pornotube(self):
  37. self._assert_restricted(
  38. 'http://pornotube.com/c/173/m/1689755/Marilyn-Monroe-Bathing',
  39. '1689755.flv', 13)
  40. if __name__ == '__main__':
  41. unittest.main()