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.

160 lines
5.6 KiB

Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
  1. from __future__ import unicode_literals
  2. import os
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_parse_unquote,
  7. compat_urllib_parse_unquote_plus,
  8. compat_urllib_parse_urlparse,
  9. )
  10. from ..utils import (
  11. ExtractorError,
  12. sanitized_Request,
  13. str_to_int,
  14. )
  15. from ..aes import (
  16. aes_decrypt_text
  17. )
  18. class PornHubIE(InfoExtractor):
  19. _VALID_URL = r'https?://(?:[a-z]+\.)?pornhub\.com/(?:view_video\.php\?viewkey=|embed/)(?P<id>[0-9a-z]+)'
  20. _TESTS = [{
  21. 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
  22. 'md5': '882f488fa1f0026f023f33576004a2ed',
  23. 'info_dict': {
  24. 'id': '648719015',
  25. 'ext': 'mp4',
  26. "uploader": "Babes",
  27. "title": "Seductive Indian beauty strips down and fingers her pink pussy",
  28. "age_limit": 18
  29. }
  30. }, {
  31. 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
  35. 'only_matching': True,
  36. }]
  37. @classmethod
  38. def _extract_url(cls, webpage):
  39. mobj = re.search(
  40. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?pornhub\.com/embed/\d+)\1', webpage)
  41. if mobj:
  42. return mobj.group('url')
  43. def _extract_count(self, pattern, webpage, name):
  44. return str_to_int(self._search_regex(
  45. pattern, webpage, '%s count' % name, fatal=False))
  46. def _real_extract(self, url):
  47. video_id = self._match_id(url)
  48. req = sanitized_Request(
  49. 'http://www.pornhub.com/view_video.php?viewkey=%s' % video_id)
  50. req.add_header('Cookie', 'age_verified=1')
  51. webpage = self._download_webpage(req, video_id)
  52. error_msg = self._html_search_regex(
  53. r'(?s)<div class="userMessageSection[^"]*".*?>(.*?)</div>',
  54. webpage, 'error message', default=None)
  55. if error_msg:
  56. error_msg = re.sub(r'\s+', ' ', error_msg)
  57. raise ExtractorError(
  58. 'PornHub said: %s' % error_msg,
  59. expected=True, video_id=video_id)
  60. video_title = self._html_search_regex(r'<h1 [^>]+>([^<]+)', webpage, 'title')
  61. video_uploader = self._html_search_regex(
  62. r'(?s)From:&nbsp;.+?<(?:a href="/users/|a href="/channels/|span class="username)[^>]+>(.+?)<',
  63. webpage, 'uploader', fatal=False)
  64. thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, 'thumbnail', fatal=False)
  65. if thumbnail:
  66. thumbnail = compat_urllib_parse_unquote(thumbnail)
  67. view_count = self._extract_count(
  68. r'<span class="count">([\d,\.]+)</span> views', webpage, 'view')
  69. like_count = self._extract_count(
  70. r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
  71. dislike_count = self._extract_count(
  72. r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
  73. comment_count = self._extract_count(
  74. r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
  75. video_urls = list(map(compat_urllib_parse_unquote, re.findall(r"player_quality_[0-9]{3}p\s*=\s*'([^']+)'", webpage)))
  76. if webpage.find('"encrypted":true') != -1:
  77. password = compat_urllib_parse_unquote_plus(
  78. self._search_regex(r'"video_title":"([^"]+)', webpage, 'password'))
  79. video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
  80. formats = []
  81. for video_url in video_urls:
  82. path = compat_urllib_parse_urlparse(video_url).path
  83. extension = os.path.splitext(path)[1][1:]
  84. format = path.split('/')[5].split('_')[:2]
  85. format = "-".join(format)
  86. m = re.match(r'^(?P<height>[0-9]+)[pP]-(?P<tbr>[0-9]+)[kK]$', format)
  87. if m is None:
  88. height = None
  89. tbr = None
  90. else:
  91. height = int(m.group('height'))
  92. tbr = int(m.group('tbr'))
  93. formats.append({
  94. 'url': video_url,
  95. 'ext': extension,
  96. 'format': format,
  97. 'format_id': format,
  98. 'tbr': tbr,
  99. 'height': height,
  100. })
  101. self._sort_formats(formats)
  102. return {
  103. 'id': video_id,
  104. 'uploader': video_uploader,
  105. 'title': video_title,
  106. 'thumbnail': thumbnail,
  107. 'view_count': view_count,
  108. 'like_count': like_count,
  109. 'dislike_count': dislike_count,
  110. 'comment_count': comment_count,
  111. 'formats': formats,
  112. 'age_limit': 18,
  113. }
  114. class PornHubPlaylistIE(InfoExtractor):
  115. _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
  116. _TESTS = [{
  117. 'url': 'http://www.pornhub.com/playlist/6201671',
  118. 'info_dict': {
  119. 'id': '6201671',
  120. 'title': 'P0p4',
  121. },
  122. 'playlist_mincount': 35,
  123. }]
  124. def _real_extract(self, url):
  125. playlist_id = self._match_id(url)
  126. webpage = self._download_webpage(url, playlist_id)
  127. entries = [
  128. self.url_result('http://www.pornhub.com/%s' % video_url, 'PornHub')
  129. for video_url in set(re.findall(
  130. r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"', webpage))
  131. ]
  132. playlist = self._parse_json(
  133. self._search_regex(
  134. r'playlistObject\s*=\s*({.+?});', webpage, 'playlist'),
  135. playlist_id)
  136. return self.playlist_result(
  137. entries, playlist_id, playlist.get('title'), playlist.get('description'))