]> jfr.im git - yt-dlp.git/blame - devscripts/check-porn.py
Implement a different adult sites checking algorithm
[yt-dlp.git] / devscripts / check-porn.py
CommitLineData
750e9833
FV
1#!/usr/bin/env python
2
3"""
4This script employs a VERY basic heuristic ('porn' in webpage.lower()) to check
5if we are not 'age_limit' tagging some porn site
a45ea170
FV
6
7A second approach implemented relies on a list of porn domains, to activate it
8pass the list filename as the only argument
750e9833
FV
9"""
10
11# Allow direct execution
12import os
13import sys
14sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
15
16from test.helper import get_testcases
a45ea170 17from youtube_dl.utils import compat_urllib_parse_urlparse
750e9833
FV
18from youtube_dl.utils import compat_urllib_request
19
a45ea170
FV
20if len(sys.argv) > 1:
21 METHOD = 'LIST'
22 LIST = open(sys.argv[1]).read().decode('utf8').strip()
23else:
24 METHOD = 'EURISTIC'
25
750e9833 26for test in get_testcases():
a45ea170
FV
27 if METHOD == 'EURISTIC':
28 try:
29 webpage = compat_urllib_request.urlopen(test['url'], timeout=10).read()
30 except:
31 print('\nFail: {0}'.format(test['name']))
32 continue
33
34 webpage = webpage.decode('utf8', 'replace')
35
36 RESULT = 'porn' in webpage.lower()
37
38 elif METHOD == 'LIST':
39 domain = compat_urllib_parse_urlparse(test['url']).netloc
40 if not domain:
41 print('\nFail: {0}'.format(test['name']))
42 continue
43 domain = '.'.join(domain.split('.')[-2:])
750e9833 44
a45ea170 45 RESULT = ('.' + domain + '\n' in LIST or '\n' + domain + '\n' in LIST)
750e9833 46
a45ea170
FV
47 if RESULT and ('info_dict' not in test or 'age_limit' not in test['info_dict']
48 or test['info_dict']['age_limit'] != 18):
750e9833
FV
49 print('\nPotential missing age_limit check: {0}'.format(test['name']))
50
a45ea170
FV
51 elif not RESULT and ('info_dict' in test and 'age_limit' in test['info_dict']
52 and test['info_dict']['age_limit'] == 18):
750e9833
FV
53 print('\nPotential false negative: {0}'.format(test['name']))
54
55 else:
56 sys.stdout.write('.')
57 sys.stdout.flush()
58
59print()