]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
54007a45 | 2 | |
44a5f171 PH |
3 | # Allow direct execution |
4 | import os | |
8dbe9899 PH |
5 | import sys |
6 | import unittest | |
f8271158 | 7 | |
44a5f171 PH |
8 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
9 | ||
8dbe9899 | 10 | |
54007a45 | 11 | from test.helper import is_download_test, try_rm |
7a5c1cfe | 12 | from yt_dlp import YoutubeDL |
8dbe9899 PH |
13 | |
14 | ||
15 | def _download_restricted(url, filename, age): | |
8ae98080 | 16 | """ Returns true if the file has been downloaded """ |
8dbe9899 PH |
17 | |
18 | params = { | |
19 | 'age_limit': age, | |
20 | 'skip_download': True, | |
21 | 'writeinfojson': True, | |
a0f59cdc | 22 | 'outtmpl': '%(id)s.%(ext)s', |
8dbe9899 PH |
23 | } |
24 | ydl = YoutubeDL(params) | |
25 | ydl.add_default_info_extractors() | |
f99e0f1e | 26 | json_filename = os.path.splitext(filename)[0] + '.info.json' |
8dbe9899 PH |
27 | try_rm(json_filename) |
28 | ydl.download([url]) | |
29 | res = os.path.exists(json_filename) | |
30 | try_rm(json_filename) | |
31 | return res | |
32 | ||
33 | ||
060ac762 | 34 | @is_download_test |
8dbe9899 PH |
35 | class 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 | |
49 | if __name__ == '__main__': | |
50 | unittest.main() |