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.

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