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.

221 lines
7.5 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 itertools
  3. import os
  4. import re
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_HTTPError,
  8. compat_urllib_parse_unquote,
  9. compat_urllib_parse_unquote_plus,
  10. compat_urllib_parse_urlparse,
  11. )
  12. from ..utils import (
  13. ExtractorError,
  14. int_or_none,
  15. orderedSet,
  16. sanitized_Request,
  17. str_to_int,
  18. )
  19. from ..aes import (
  20. aes_decrypt_text
  21. )
  22. class PornHubIE(InfoExtractor):
  23. _VALID_URL = r'https?://(?:[a-z]+\.)?pornhub\.com/(?:view_video\.php\?viewkey=|embed/)(?P<id>[0-9a-z]+)'
  24. _TESTS = [{
  25. 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
  26. 'md5': '1e19b41231a02eba417839222ac9d58e',
  27. 'info_dict': {
  28. 'id': '648719015',
  29. 'ext': 'mp4',
  30. 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
  31. 'uploader': 'Babes',
  32. 'duration': 361,
  33. 'view_count': int,
  34. 'like_count': int,
  35. 'dislike_count': int,
  36. 'comment_count': int,
  37. 'age_limit': 18,
  38. }
  39. }, {
  40. 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
  44. 'only_matching': True,
  45. }]
  46. @classmethod
  47. def _extract_url(cls, webpage):
  48. mobj = re.search(
  49. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?pornhub\.com/embed/\d+)\1', webpage)
  50. if mobj:
  51. return mobj.group('url')
  52. def _extract_count(self, pattern, webpage, name):
  53. return str_to_int(self._search_regex(
  54. pattern, webpage, '%s count' % name, fatal=False))
  55. def _real_extract(self, url):
  56. video_id = self._match_id(url)
  57. req = sanitized_Request(
  58. 'http://www.pornhub.com/view_video.php?viewkey=%s' % video_id)
  59. req.add_header('Cookie', 'age_verified=1')
  60. webpage = self._download_webpage(req, video_id)
  61. error_msg = self._html_search_regex(
  62. r'(?s)<div class="userMessageSection[^"]*".*?>(.*?)</div>',
  63. webpage, 'error message', default=None)
  64. if error_msg:
  65. error_msg = re.sub(r'\s+', ' ', error_msg)
  66. raise ExtractorError(
  67. 'PornHub said: %s' % error_msg,
  68. expected=True, video_id=video_id)
  69. flashvars = self._parse_json(
  70. self._search_regex(
  71. r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
  72. video_id)
  73. if flashvars:
  74. video_title = flashvars.get('video_title')
  75. thumbnail = flashvars.get('image_url')
  76. duration = int_or_none(flashvars.get('video_duration'))
  77. else:
  78. video_title, thumbnail, duration = [None] * 3
  79. if not video_title:
  80. video_title = self._html_search_regex(r'<h1 [^>]+>([^<]+)', webpage, 'title')
  81. video_uploader = self._html_search_regex(
  82. r'(?s)From:&nbsp;.+?<(?:a href="/users/|a href="/channels/|span class="username)[^>]+>(.+?)<',
  83. webpage, 'uploader', fatal=False)
  84. view_count = self._extract_count(
  85. r'<span class="count">([\d,\.]+)</span> views', webpage, 'view')
  86. like_count = self._extract_count(
  87. r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
  88. dislike_count = self._extract_count(
  89. r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
  90. comment_count = self._extract_count(
  91. r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
  92. video_urls = list(map(compat_urllib_parse_unquote, re.findall(r"player_quality_[0-9]{3}p\s*=\s*'([^']+)'", webpage)))
  93. if webpage.find('"encrypted":true') != -1:
  94. password = compat_urllib_parse_unquote_plus(
  95. self._search_regex(r'"video_title":"([^"]+)', webpage, 'password'))
  96. video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
  97. formats = []
  98. for video_url in video_urls:
  99. path = compat_urllib_parse_urlparse(video_url).path
  100. extension = os.path.splitext(path)[1][1:]
  101. format = path.split('/')[5].split('_')[:2]
  102. format = '-'.join(format)
  103. m = re.match(r'^(?P<height>[0-9]+)[pP]-(?P<tbr>[0-9]+)[kK]$', format)
  104. if m is None:
  105. height = None
  106. tbr = None
  107. else:
  108. height = int(m.group('height'))
  109. tbr = int(m.group('tbr'))
  110. formats.append({
  111. 'url': video_url,
  112. 'ext': extension,
  113. 'format': format,
  114. 'format_id': format,
  115. 'tbr': tbr,
  116. 'height': height,
  117. })
  118. self._sort_formats(formats)
  119. return {
  120. 'id': video_id,
  121. 'uploader': video_uploader,
  122. 'title': video_title,
  123. 'thumbnail': thumbnail,
  124. 'duration': duration,
  125. 'view_count': view_count,
  126. 'like_count': like_count,
  127. 'dislike_count': dislike_count,
  128. 'comment_count': comment_count,
  129. 'formats': formats,
  130. 'age_limit': 18,
  131. }
  132. class PornHubPlaylistBaseIE(InfoExtractor):
  133. def _extract_entries(self, webpage):
  134. return [
  135. self.url_result(
  136. 'http://www.pornhub.com/%s' % video_url,
  137. PornHubIE.ie_key(), video_title=title)
  138. for video_url, title in orderedSet(re.findall(
  139. r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^"]+)"',
  140. webpage))
  141. ]
  142. def _real_extract(self, url):
  143. playlist_id = self._match_id(url)
  144. webpage = self._download_webpage(url, playlist_id)
  145. entries = self._extract_entries(webpage)
  146. playlist = self._parse_json(
  147. self._search_regex(
  148. r'playlistObject\s*=\s*({.+?});', webpage, 'playlist'),
  149. playlist_id)
  150. return self.playlist_result(
  151. entries, playlist_id, playlist.get('title'), playlist.get('description'))
  152. class PornHubPlaylistIE(PornHubPlaylistBaseIE):
  153. _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
  154. _TESTS = [{
  155. 'url': 'http://www.pornhub.com/playlist/6201671',
  156. 'info_dict': {
  157. 'id': '6201671',
  158. 'title': 'P0p4',
  159. },
  160. 'playlist_mincount': 35,
  161. }]
  162. class PornHubUserVideosIE(PornHubPlaylistBaseIE):
  163. _VALID_URL = r'https?://(?:www\.)?pornhub\.com/users/(?P<id>[^/]+)/videos'
  164. _TESTS = [{
  165. 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
  166. 'info_dict': {
  167. 'id': 'zoe_ph',
  168. },
  169. 'playlist_mincount': 171,
  170. }, {
  171. 'url': 'http://www.pornhub.com/users/rushandlia/videos',
  172. 'only_matching': True,
  173. }]
  174. def _real_extract(self, url):
  175. user_id = self._match_id(url)
  176. entries = []
  177. for page_num in itertools.count(1):
  178. try:
  179. webpage = self._download_webpage(
  180. url, user_id, 'Downloading page %d' % page_num,
  181. query={'page': page_num})
  182. except ExtractorError as e:
  183. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
  184. break
  185. page_entries = self._extract_entries(webpage)
  186. if not page_entries:
  187. break
  188. entries.extend(page_entries)
  189. return self.playlist_result(entries, user_id)