]> jfr.im git - yt-dlp.git/blame - test/test_age_restriction.py
[toggo] Improve `_VALID_URL` (#3689)
[yt-dlp.git] / test / test_age_restriction.py
CommitLineData
cc52de43 1#!/usr/bin/env python3
44a5f171
PH
2# Allow direct execution
3import os
8dbe9899
PH
4import sys
5import unittest
f8271158 6
44a5f171
PH
7sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8
f8271158 9from test.helper import is_download_test, try_rm
8dbe9899 10
7a5c1cfe 11from yt_dlp import YoutubeDL
8dbe9899
PH
12
13
14def _download_restricted(url, filename, age):
8ae98080 15 """ Returns true if the file has been downloaded """
8dbe9899
PH
16
17 params = {
18 'age_limit': age,
19 'skip_download': True,
20 'writeinfojson': True,
a0f59cdc 21 'outtmpl': '%(id)s.%(ext)s',
8dbe9899
PH
22 }
23 ydl = YoutubeDL(params)
24 ydl.add_default_info_extractors()
f99e0f1e 25 json_filename = os.path.splitext(filename)[0] + '.info.json'
8dbe9899
PH
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
060ac762 33@is_download_test
8dbe9899
PH
34class 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
8dbe9899
PH
47
48if __name__ == '__main__':
49 unittest.main()