6 # Allow direct execution
8 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10 from youtube_dl import YoutubeDL
11 from helper import try_rm
14 def _download_restricted(url, filename, age):
15 """ Returns true iff the file has been downloaded """
19 'skip_download': True,
20 'writeinfojson': True,
21 "outtmpl": "%(id)s.%(ext)s",
23 ydl = YoutubeDL(params)
24 ydl.add_default_info_extractors()
25 json_filename = filename + '.info.json'
28 res = os.path.exists(json_filename)
33 class TestAgeRestriction(unittest.TestCase):
34 def _assert_restricted(self, url, filename, age, old_age=None):
35 self.assertTrue(_download_restricted(url, filename, old_age))
36 self.assertFalse(_download_restricted(url, filename, age))
38 def test_youtube(self):
39 self._assert_restricted('07FYdnEawAQ', '07FYdnEawAQ.mp4', 10)
41 def test_youporn(self):
42 self._assert_restricted(
43 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
44 '505835.mp4', 2, old_age=25)
46 def test_pornotube(self):
47 self._assert_restricted(
48 'http://pornotube.com/c/173/m/1689755/Marilyn-Monroe-Bathing',
52 if __name__ == '__main__':