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