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.

100 lines
3.6 KiB

  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*[\da-zA-Z_]+\s*=',
  40. webpage, 'config', default='{}'),
  41. display_id, transform_source=js_to_json, fatal=False)
  42. if config:
  43. title = config['title']
  44. formats = [{
  45. 'url': stream['url'],
  46. 'format_id': stream.get('id'),
  47. 'height': int_or_none(self._search_regex(
  48. r'^(\d+)[pP]', stream.get('id') or '', 'height', default=None))
  49. } for stream in config['streams'] if stream.get('url')]
  50. thumbnail = (compat_urlparse.urljoin(
  51. config['thumbCDN'], config['poster'])
  52. if config.get('thumbCDN') and config.get('poster') else None)
  53. duration = int_or_none(config.get('length'))
  54. else:
  55. title = self._search_regex(
  56. (r'<title>([^<]+)</title>', r'<h1[^>]*>([^<]+)</h1>'),
  57. webpage, 'title')
  58. formats = [{
  59. 'url': compat_urlparse.urljoin(url, format_url),
  60. 'format_id': '%sp' % height,
  61. 'height': int(height),
  62. 'filesize_approx': parse_filesize(filesize),
  63. } for format_url, height, filesize in re.findall(
  64. r'<a[^>]+href="(/download/[^"]+)">MPEG4 (\d+)p<span[^>]*>(\d+\s+[a-zA-Z]+)<',
  65. webpage)]
  66. thumbnail = None
  67. duration = None
  68. self._sort_formats(formats)
  69. view_count = str_to_int(self._search_regex(
  70. r'class=["\']views["\'][^>]*><p>([\d,.]+)', webpage,
  71. 'view count', fatal=False))
  72. def extract_list(kind):
  73. s = self._search_regex(
  74. r'(?s)<p[^>]*>%s:(.+?)</p>' % kind.capitalize(),
  75. webpage, kind, fatal=False)
  76. return re.findall(r'<a[^>]+>([^<]+)</a>', s or '')
  77. return {
  78. 'id': video_id,
  79. 'display_id': display_id,
  80. 'title': title,
  81. 'thumbnail': thumbnail,
  82. 'duration': duration,
  83. 'view_count': view_count,
  84. 'formats': formats,
  85. 'age_limit': 18,
  86. 'categories': extract_list('categories'),
  87. 'tags': extract_list('tags'),
  88. }