You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.3 KiB

  1. #!/usr/bin/env python
  2. """
  3. This script employs a VERY basic heuristic ('porn' in webpage.lower()) to check
  4. if we are not 'age_limit' tagging some porn site
  5. """
  6. # Allow direct execution
  7. import os
  8. import sys
  9. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  10. from test.helper import get_testcases
  11. from youtube_dl.utils import compat_urllib_request
  12. for test in get_testcases():
  13. try:
  14. webpage = compat_urllib_request.urlopen(test['url'], timeout=10).read()
  15. except:
  16. print('\nFail: {0}'.format(test['name']))
  17. continue
  18. webpage = webpage.decode('utf8', 'replace')
  19. if 'porn' in webpage.lower() and ('info_dict' not in test
  20. or 'age_limit' not in test['info_dict']
  21. or test['info_dict']['age_limit'] != 18):
  22. print('\nPotential missing age_limit check: {0}'.format(test['name']))
  23. elif 'porn' not in webpage.lower() and ('info_dict' in test and
  24. 'age_limit' in test['info_dict'] and
  25. test['info_dict']['age_limit'] == 18):
  26. print('\nPotential false negative: {0}'.format(test['name']))
  27. else:
  28. sys.stdout.write('.')
  29. sys.stdout.flush()
  30. print()