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