]> jfr.im git - yt-dlp.git/blame - test/test_age_restriction.py
[cleanup] Misc
[yt-dlp.git] / test / test_age_restriction.py
CommitLineData
cc52de43 1#!/usr/bin/env python3
54007a45 2
44a5f171
PH
3# Allow direct execution
4import os
8dbe9899
PH
5import sys
6import unittest
f8271158 7
44a5f171
PH
8sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
8dbe9899 10
54007a45 11from test.helper import is_download_test, try_rm
7a5c1cfe 12from yt_dlp import YoutubeDL
8dbe9899
PH
13
14
15def _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
35class 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
49if __name__ == '__main__':
50 unittest.main()