3 # Allow direct execution
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 """
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'
34 return os
.path
.exists(json_filename
)
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__':