[extractor/premiershiprugby] Add extractor (#4129)
[yt-dlp3.git] / test / test_age_restriction.py
blobff248432b9ca070151f95816e1e26b0c2daa9023
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
15 def _download_restricted(url, filename, age):
16 """ Returns true if the file has been downloaded """
18 params = {
19 'age_limit': age,
20 'skip_download': True,
21 'writeinfojson': True,
22 'outtmpl': '%(id)s.%(ext)s',
24 ydl = YoutubeDL(params)
25 ydl.add_default_info_extractors()
26 json_filename = os.path.splitext(filename)[0] + '.info.json'
27 try_rm(json_filename)
28 ydl.download([url])
29 res = os.path.exists(json_filename)
30 try_rm(json_filename)
31 return res
34 @is_download_test
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))
40 def test_youtube(self):
41 self._assert_restricted('07FYdnEawAQ', '07FYdnEawAQ.mp4', 10)
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)
49 if __name__ == '__main__':
50 unittest.main()