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