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.

104 lines
3.8KB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import compat_urlparse
  5. from ..utils import (
  6. int_or_none,
  7. js_to_json,
  8. parse_filesize,
  9. str_to_int,
  10. )
  11. class PornComIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:[a-zA-Z]+\.)?porn\.com/videos/(?:(?P<display_id>[^/]+)-)?(?P<id>\d+)'
  13. _TESTS = [{
  14. 'url': 'http://www.porn.com/videos/teen-grabs-a-dildo-and-fucks-her-pussy-live-on-1hottie-i-rec-2603339',
  15. 'md5': '3f30ce76267533cd12ba999263156de7',
  16. 'info_dict': {
  17. 'id': '2603339',
  18. 'display_id': 'teen-grabs-a-dildo-and-fucks-her-pussy-live-on-1hottie-i-rec',
  19. 'ext': 'mp4',
  20. 'title': 'Teen grabs a dildo and fucks her pussy live on 1hottie, I rec',
  21. 'thumbnail': r're:^https?://.*\.jpg$',
  22. 'duration': 551,
  23. 'view_count': int,
  24. 'age_limit': 18,
  25. 'categories': list,
  26. 'tags': list,
  27. },
  28. }, {
  29. 'url': 'http://se.porn.com/videos/marsha-may-rides-seth-on-top-of-his-thick-cock-2658067',
  30. 'only_matching': True,
  31. }]
  32. def _real_extract(self, url):
  33. mobj = re.match(self._VALID_URL, url)
  34. video_id = mobj.group('id')
  35. display_id = mobj.group('display_id') or video_id
  36. webpage = self._download_webpage(url, display_id)
  37. config = self._parse_json(
  38. self._search_regex(
  39. (r'=\s*({.+?})\s*;\s*v1ar\b',
  40. r'=\s*({.+?})\s*,\s*[\da-zA-Z_]+\s*='),
  41. webpage, 'config', default='{}'),
  42. display_id, transform_source=js_to_json, fatal=False)
  43. if config:
  44. title = config['title']
  45. formats = [{
  46. 'url': stream['url'],
  47. 'format_id': stream.get('id'),
  48. 'height': int_or_none(self._search_regex(
  49. r'^(\d+)[pP]', stream.get('id') or '', 'height', default=None))
  50. } for stream in config['streams'] if stream.get('url')]
  51. thumbnail = (compat_urlparse.urljoin(
  52. config['thumbCDN'], config['poster'])
  53. if config.get('thumbCDN') and config.get('poster') else None)
  54. duration = int_or_none(config.get('length'))
  55. else:
  56. title = self._search_regex(
  57. (r'<title>([^<]+)</title>', r'<h1[^>]*>([^<]+)</h1>'),
  58. webpage, 'title')
  59. formats = [{
  60. 'url': compat_urlparse.urljoin(url, format_url),
  61. 'format_id': '%sp' % height,
  62. 'height': int(height),
  63. 'filesize_approx': parse_filesize(filesize),
  64. } for format_url, height, filesize in re.findall(
  65. r'<a[^>]+href="(/download/[^"]+)">[^<]*?(\d+)p<span[^>]*>(\d+\s*[a-zA-Z]+)<',
  66. webpage)]
  67. thumbnail = None
  68. duration = None
  69. self._sort_formats(formats)
  70. view_count = str_to_int(self._search_regex(
  71. (r'Views:\s*</span>\s*<span>\s*([\d,.]+)',
  72. r'class=["\']views["\'][^>]*><p>([\d,.]+)'), webpage,
  73. 'view count', fatal=False))
  74. def extract_list(kind):
  75. s = self._search_regex(
  76. (r'(?s)%s:\s*</span>\s*<span>(.+?)</span>' % kind.capitalize(),
  77. r'(?s)<p[^>]*>%s:(.+?)</p>' % kind.capitalize()),
  78. webpage, kind, fatal=False)
  79. return re.findall(r'<a[^>]+>([^<]+)</a>', s or '')
  80. return {
  81. 'id': video_id,
  82. 'display_id': display_id,
  83. 'title': title,
  84. 'thumbnail': thumbnail,
  85. 'duration': duration,
  86. 'view_count': view_count,
  87. 'formats': formats,
  88. 'age_limit': 18,
  89. 'categories': extract_list('categories'),
  90. 'tags': extract_list('tags'),
  91. }