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.

53 lines
1.4 KiB

  1. #!/usr/bin/env python
  2. import sys
  3. import unittest
  4. # Allow direct execution
  5. import os
  6. sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  7. from youtube_dl import YoutubeDL
  8. from .helper import try_rm
  9. def _download_restricted(url, filename, age):
  10. """ Returns true iff 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 = filename + '.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()