]> gitweb @ CieloNegro.org - youtube-dl.git/blob - test/test_age_restriction.py
release 2014.02.17
[youtube-dl.git] / test / test_age_restriction.py
1 #!/usr/bin/env python
2
3 # Allow direct execution
4 import os
5 import sys
6 import unittest
7 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8
9 from test.helper import try_rm
10
11
12 from youtube_dl import YoutubeDL
13
14
15 def _download_restricted(url, filename, age):
16     """ Returns true iff the file has been downloaded """
17
18     params = {
19         'age_limit': age,
20         'skip_download': True,
21         'writeinfojson': True,
22         "outtmpl": "%(id)s.%(ext)s",
23     }
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
32
33
34 class 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
47     def test_pornotube(self):
48         self._assert_restricted(
49             'http://pornotube.com/c/173/m/1689755/Marilyn-Monroe-Bathing',
50             '1689755.flv', 13)
51
52
53 if __name__ == '__main__':
54     unittest.main()