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.

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