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.

101 lines
3.8 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. str_to_int,
  10. )
  11. from ..aes import (
  12. aes_decrypt_text
  13. )
  14. class PornHubIE(InfoExtractor):
  15. _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>pornhub\.com/view_video\.php\?viewkey=(?P<videoid>[0-9a-f]+))'
  16. _TEST = {
  17. 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
  18. 'file': '648719015.mp4',
  19. 'md5': '882f488fa1f0026f023f33576004a2ed',
  20. 'info_dict': {
  21. "uploader": "BABES-COM",
  22. "title": "Seductive Indian beauty strips down and fingers her pink pussy",
  23. "age_limit": 18
  24. }
  25. }
  26. def _extract_count(self, pattern, webpage, name):
  27. count = self._html_search_regex(pattern, webpage, '%s count' % name, fatal=False)
  28. if count:
  29. count = str_to_int(count)
  30. return count
  31. def _real_extract(self, url):
  32. mobj = re.match(self._VALID_URL, url)
  33. video_id = mobj.group('videoid')
  34. url = 'http://www.' + mobj.group('url')
  35. req = compat_urllib_request.Request(url)
  36. req.add_header('Cookie', 'age_verified=1')
  37. webpage = self._download_webpage(req, video_id)
  38. video_title = self._html_search_regex(r'<h1 [^>]+>([^<]+)', webpage, 'title')
  39. video_uploader = self._html_search_regex(
  40. r'(?s)From:&nbsp;.+?<(?:a href="/users/|<span class="username)[^>]+>(.+?)<',
  41. webpage, 'uploader', fatal=False)
  42. thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, 'thumbnail', fatal=False)
  43. if thumbnail:
  44. thumbnail = compat_urllib_parse.unquote(thumbnail)
  45. view_count = self._extract_count(r'<span class="count">([\d,\.]+)</span> views', webpage, 'view')
  46. like_count = self._extract_count(r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
  47. dislike_count = self._extract_count(r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
  48. comment_count = self._extract_count(
  49. r'All comments \(<var class="videoCommentCount">([\d,\.]+)</var>', webpage, 'comment')
  50. video_urls = list(map(compat_urllib_parse.unquote , re.findall(r'"quality_[0-9]{3}p":"([^"]+)', webpage)))
  51. if webpage.find('"encrypted":true') != -1:
  52. password = compat_urllib_parse.unquote_plus(self._html_search_regex(r'"video_title":"([^"]+)', webpage, 'password'))
  53. video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
  54. formats = []
  55. for video_url in video_urls:
  56. path = compat_urllib_parse_urlparse(video_url).path
  57. extension = os.path.splitext(path)[1][1:]
  58. format = path.split('/')[5].split('_')[:2]
  59. format = "-".join(format)
  60. m = re.match(r'^(?P<height>[0-9]+)P-(?P<tbr>[0-9]+)K$', format)
  61. if m is None:
  62. height = None
  63. tbr = None
  64. else:
  65. height = int(m.group('height'))
  66. tbr = int(m.group('tbr'))
  67. formats.append({
  68. 'url': video_url,
  69. 'ext': extension,
  70. 'format': format,
  71. 'format_id': format,
  72. 'tbr': tbr,
  73. 'height': height,
  74. })
  75. self._sort_formats(formats)
  76. return {
  77. 'id': video_id,
  78. 'uploader': video_uploader,
  79. 'title': video_title,
  80. 'thumbnail': thumbnail,
  81. 'view_count': view_count,
  82. 'like_count': like_count,
  83. 'dislike_count': dislike_count,
  84. 'comment_count': comment_count,
  85. 'formats': formats,
  86. 'age_limit': 18,
  87. }