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.

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