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.

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