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.

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