]>
jfr.im git - yt-dlp.git/blob - test/test_age_restriction.py
2 # Allow direct execution
6 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
8 from test
.helper
import try_rm
, is_download_test
10 from yt_dlp
import YoutubeDL
13 def _download_restricted(url
, filename
, age
):
14 """ Returns true if the file has been downloaded """
18 'skip_download': True,
19 'writeinfojson': True,
20 'outtmpl': '%(id)s.%(ext)s',
22 ydl
= YoutubeDL(params
)
23 ydl
.add_default_info_extractors()
24 json_filename
= os
.path
.splitext(filename
)[0] + '.info.json'
27 res
= os
.path
.exists(json_filename
)
33 class TestAgeRestriction(unittest
.TestCase
):
34 def _assert_restricted(self
, url
, filename
, age
, old_age
=None):
35 self
.assertTrue(_download_restricted(url
, filename
, old_age
))
36 self
.assertFalse(_download_restricted(url
, filename
, age
))
38 def test_youtube(self
):
39 self
._assert
_restricted
('07FYdnEawAQ', '07FYdnEawAQ.mp4', 10)
41 def test_youporn(self
):
42 self
._assert
_restricted
(
43 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
44 '505835.mp4', 2, old_age
=25)
47 if __name__
== '__main__':