sexu.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from .common import InfoExtractor
  2. class SexuIE(InfoExtractor):
  3. _VALID_URL = r'https?://(?:www\.)?sexu\.com/(?P<id>\d+)'
  4. _TEST = {
  5. 'url': 'http://sexu.com/961791/',
  6. 'md5': 'ff615aca9691053c94f8f10d96cd7884',
  7. 'info_dict': {
  8. 'id': '961791',
  9. 'ext': 'mp4',
  10. 'title': 'md5:4d05a19a5fc049a63dbbaf05fb71d91b',
  11. 'description': 'md5:2b75327061310a3afb3fbd7d09e2e403',
  12. 'categories': list, # NSFW
  13. 'thumbnail': r're:https?://.*\.jpg$',
  14. 'age_limit': 18,
  15. }
  16. }
  17. def _real_extract(self, url):
  18. video_id = self._match_id(url)
  19. webpage = self._download_webpage(url, video_id)
  20. jwvideo = self._parse_json(
  21. self._search_regex(r'\.setup\(\s*({.+?})\s*\);', webpage, 'jwvideo'),
  22. video_id)
  23. sources = jwvideo['sources']
  24. formats = [{
  25. 'url': source['file'].replace('\\', ''),
  26. 'format_id': source.get('label'),
  27. 'height': int(self._search_regex(
  28. r'^(\d+)[pP]', source.get('label', ''), 'height',
  29. default=None)),
  30. } for source in sources if source.get('file')]
  31. title = self._html_search_regex(
  32. r'<title>([^<]+)\s*-\s*Sexu\.Com</title>', webpage, 'title')
  33. description = self._html_search_meta(
  34. 'description', webpage, 'description')
  35. thumbnail = jwvideo.get('image')
  36. categories_str = self._html_search_meta(
  37. 'keywords', webpage, 'categories')
  38. categories = (
  39. None if categories_str is None
  40. else categories_str.split(','))
  41. return {
  42. 'id': video_id,
  43. 'title': title,
  44. 'description': description,
  45. 'thumbnail': thumbnail,
  46. 'categories': categories,
  47. 'formats': formats,
  48. 'age_limit': 18,
  49. }