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.

69 lines
2.6 KiB

  1. import os
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urllib_parse_urlparse,
  6. compat_urllib_request,
  7. compat_urllib_parse,
  8. unescapeHTML,
  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-9]+))'
  15. _TEST = {
  16. u'url': u'http://www.pornhub.com/view_video.php?viewkey=648719015',
  17. u'file': u'648719015.mp4',
  18. u'md5': u'882f488fa1f0026f023f33576004a2ed',
  19. u'info_dict': {
  20. u"uploader": u"BABES-COM",
  21. u"title": u"Seductive Indian beauty strips down and fingers her pink pussy",
  22. u"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, u'title')
  33. video_uploader = self._html_search_regex(r'<b>From: </b>(?:\s|<[^>]*>)*(.+?)<', webpage, u'uploader', fatal=False)
  34. thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, u'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, u'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. formats.append({
  48. 'url': video_url,
  49. 'ext': extension,
  50. 'format': format,
  51. 'format_id': format,
  52. })
  53. formats.sort(key=lambda format: list(map(lambda s: s.zfill(6), format['format'].split('-'))))
  54. return {
  55. 'id': video_id,
  56. 'uploader': video_uploader,
  57. 'title': video_title,
  58. 'thumbnail': thumbnail,
  59. 'formats': formats,
  60. 'age_limit': 18,
  61. }