]> jfr.im git - yt-dlp.git/blame - devscripts/check-porn.py
[cleanup,build] Cleanup some build-related code
[yt-dlp.git] / devscripts / check-porn.py
CommitLineData
cc52de43 1#!/usr/bin/env python3
750e9833
FV
2"""
3This script employs a VERY basic heuristic ('porn' in webpage.lower()) to check
4if we are not 'age_limit' tagging some porn site
a45ea170
FV
5
6A second approach implemented relies on a list of porn domains, to activate it
7pass the list filename as the only argument
750e9833
FV
8"""
9
10# Allow direct execution
11import os
12import sys
f8271158 13
750e9833
FV
14sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
15
8a1a60d1 16from test.helper import gettestcases
f8271158 17
18from yt_dlp.utils import compat_urllib_parse_urlparse, compat_urllib_request
750e9833 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
8a1a60d1 26for test in gettestcases():
a45ea170
FV
27 if METHOD == 'EURISTIC':
28 try:
29 webpage = compat_urllib_request.urlopen(test['url'], timeout=10).read()
70a1165b 30 except Exception:
86e5f3ed 31 print('\nFail: {}'.format(test['name']))
a45ea170
FV
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:
86e5f3ed 41 print('\nFail: {}'.format(test['name']))
a45ea170
FV
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
3089bc74
S
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):
86e5f3ed 49 print('\nPotential missing age_limit check: {}'.format(test['name']))
750e9833 50
3089bc74
S
51 elif not RESULT and ('info_dict' in test and 'age_limit' in test['info_dict']
52 and test['info_dict']['age_limit'] == 18):
86e5f3ed 53 print('\nPotential false negative: {}'.format(test['name']))
750e9833
FV
54
55 else:
56 sys.stdout.write('.')
57 sys.stdout.flush()
58
59print()