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.

82 lines
2.9 KiB

  1. from __future__ import unicode_literals
  2. import os
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_parse_urlparse,
  7. compat_urllib_request,
  8. compat_urllib_parse,
  9. )
  10. from ..aes import (
  11. aes_decrypt_text
  12. )
  13. class PornHubIE(InfoExtractor):
  14. _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>pornhub\.com/view_video\.php\?viewkey=(?P<videoid>[0-9a-f]+))'
  15. _TEST = {
  16. 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
  17. 'file': '648719015.mp4',
  18. 'md5': '882f488fa1f0026f023f33576004a2ed',
  19. 'info_dict': {
  20. "uploader": "BABES-COM",
  21. "title": "Seductive Indian beauty strips down and fingers her pink pussy",
  22. "age_limit": 18
  23. }
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('videoid')
  28. url = 'http://www.' + mobj.group('url')
  29. req = compat_urllib_request.Request(url)
  30. req.add_header('Cookie', 'age_verified=1')
  31. webpage = self._download_webpage(req, video_id)
  32. video_title = self._html_search_regex(r'<h1 [^>]+>([^<]+)', webpage, 'title')
  33. video_uploader = self._html_search_regex(r'<b>From: </b>(?:\s|<[^>]*>)*(.+?)<', webpage, 'uploader', fatal=False)
  34. thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, 'thumbnail', fatal=False)
  35. if thumbnail:
  36. thumbnail = compat_urllib_parse.unquote(thumbnail)
  37. video_urls = list(map(compat_urllib_parse.unquote , re.findall(r'"quality_[0-9]{3}p":"([^"]+)', webpage)))
  38. if webpage.find('"encrypted":true') != -1:
  39. password = self._html_search_regex(r'"video_title":"([^"]+)', webpage, 'password').replace('+', ' ')
  40. video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
  41. formats = []
  42. for video_url in video_urls:
  43. path = compat_urllib_parse_urlparse(video_url).path
  44. extension = os.path.splitext(path)[1][1:]
  45. format = path.split('/')[5].split('_')[:2]
  46. format = "-".join(format)
  47. m = re.match(r'^(?P<height>[0-9]+)P-(?P<tbr>[0-9]+)K$', format)
  48. if m is None:
  49. height = None
  50. tbr = None
  51. else:
  52. height = int(m.group('height'))
  53. tbr = int(m.group('tbr'))
  54. formats.append({
  55. 'url': video_url,
  56. 'ext': extension,
  57. 'format': format,
  58. 'format_id': format,
  59. 'tbr': tbr,
  60. 'height': height,
  61. })
  62. self._sort_formats(formats)
  63. return {
  64. 'id': video_id,
  65. 'uploader': video_uploader,
  66. 'title': video_title,
  67. 'thumbnail': thumbnail,
  68. 'formats': formats,
  69. 'age_limit': 18,
  70. }