]> jfr.im git - yt-dlp.git/blame - test/test_age_restriction.py
[skip travis] renaming
[yt-dlp.git] / test / test_age_restriction.py
CommitLineData
8dbe9899 1#!/usr/bin/env python
a0f59cdc 2from __future__ import unicode_literals
8dbe9899 3
44a5f171
PH
4# Allow direct execution
5import os
8dbe9899
PH
6import sys
7import unittest
44a5f171
PH
8sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
d0efb9ec 10from test.helper import try_rm
8dbe9899 11
8dbe9899 12
cefecac1 13from youtube_dlc import YoutubeDL
8dbe9899
PH
14
15
16def _download_restricted(url, filename, age):
8ae98080 17 """ Returns true if the file has been downloaded """
8dbe9899
PH
18
19 params = {
20 'age_limit': age,
21 'skip_download': True,
22 'writeinfojson': True,
a0f59cdc 23 'outtmpl': '%(id)s.%(ext)s',
8dbe9899
PH
24 }
25 ydl = YoutubeDL(params)
26 ydl.add_default_info_extractors()
f99e0f1e 27 json_filename = os.path.splitext(filename)[0] + '.info.json'
8dbe9899
PH
28 try_rm(json_filename)
29 ydl.download([url])
30 res = os.path.exists(json_filename)
31 try_rm(json_filename)
32 return res
33
34
35class TestAgeRestriction(unittest.TestCase):
36 def _assert_restricted(self, url, filename, age, old_age=None):
37 self.assertTrue(_download_restricted(url, filename, old_age))
38 self.assertFalse(_download_restricted(url, filename, age))
39
40 def test_youtube(self):
41 self._assert_restricted('07FYdnEawAQ', '07FYdnEawAQ.mp4', 10)
42
43 def test_youporn(self):
44 self._assert_restricted(
45 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
46 '505835.mp4', 2, old_age=25)
47
8dbe9899
PH
48
49if __name__ == '__main__':
50 unittest.main()