[ie/vocaroo] Do not use deprecated `getheader` (#8606)
[yt-dlp3.git] / test / test_age_restriction.py
blob68107590e979b4b69ff2d7f23cc8e2babf733352
1 #!/usr/bin/env python3
3 # Allow direct execution
4 import os
5 import sys
6 import unittest
8 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11 from test.helper import is_download_test, try_rm
12 from yt_dlp import YoutubeDL
13 from yt_dlp.utils import DownloadError
16 def _download_restricted(url, filename, age):
17 """ Returns true if the file has been downloaded """
19 params = {
20 'age_limit': age,
21 'skip_download': True,
22 'writeinfojson': True,
23 'outtmpl': '%(id)s.%(ext)s',
25 ydl = YoutubeDL(params)
26 ydl.add_default_info_extractors()
27 json_filename = os.path.splitext(filename)[0] + '.info.json'
28 try_rm(json_filename)
29 try:
30 ydl.download([url])
31 except DownloadError:
32 pass
33 else:
34 return os.path.exists(json_filename)
35 finally:
36 try_rm(json_filename)
39 @is_download_test
40 class TestAgeRestriction(unittest.TestCase):
41 def _assert_restricted(self, url, filename, age, old_age=None):
42 self.assertTrue(_download_restricted(url, filename, old_age))
43 self.assertFalse(_download_restricted(url, filename, age))
45 def test_youtube(self):
46 self._assert_restricted('HtVdAasjOgU', 'HtVdAasjOgU.mp4', 10)
48 def test_youporn(self):
49 self._assert_restricted(
50 'https://www.youporn.com/watch/16715086/sex-ed-in-detention-18-asmr/',
51 '16715086.mp4', 2, old_age=25)
54 if __name__ == '__main__':
55 unittest.main()