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.

303 lines
11 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>[\da-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. @staticmethod
  95. def _extract_urls(webpage):
  96. return re.findall(
  97. r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?pornhub\.com/embed/[\da-z]+)',
  98. webpage)
  99. def _extract_count(self, pattern, webpage, name):
  100. return str_to_int(self._search_regex(
  101. pattern, webpage, '%s count' % name, fatal=False))
  102. def _real_extract(self, url):
  103. video_id = self._match_id(url)
  104. req = sanitized_Request(
  105. 'http://www.pornhub.com/view_video.php?viewkey=%s' % video_id)
  106. req.add_header('Cookie', 'age_verified=1')
  107. webpage = self._download_webpage(req, video_id)
  108. error_msg = self._html_search_regex(
  109. r'(?s)<div[^>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
  110. webpage, 'error message', default=None, group='error')
  111. if error_msg:
  112. error_msg = re.sub(r'\s+', ' ', error_msg)
  113. raise ExtractorError(
  114. 'PornHub said: %s' % error_msg,
  115. expected=True, video_id=video_id)
  116. # video_title from flashvars contains whitespace instead of non-ASCII (see
  117. # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
  118. # on that anymore.
  119. title = self._html_search_meta(
  120. 'twitter:title', webpage, default=None) or self._search_regex(
  121. (r'<h1[^>]+class=["\']title["\'][^>]*>(?P<title>[^<]+)',
  122. r'<div[^>]+data-video-title=(["\'])(?P<title>.+?)\1',
  123. r'shareTitle\s*=\s*(["\'])(?P<title>.+?)\1'),
  124. webpage, 'title', group='title')
  125. flashvars = self._parse_json(
  126. self._search_regex(
  127. r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
  128. video_id)
  129. if flashvars:
  130. thumbnail = flashvars.get('image_url')
  131. duration = int_or_none(flashvars.get('video_duration'))
  132. else:
  133. title, thumbnail, duration = [None] * 3
  134. video_uploader = self._html_search_regex(
  135. r'(?s)From:&nbsp;.+?<(?:a href="/users/|a href="/channels/|span class="username)[^>]+>(.+?)<',
  136. webpage, 'uploader', fatal=False)
  137. view_count = self._extract_count(
  138. r'<span class="count">([\d,\.]+)</span> views', webpage, 'view')
  139. like_count = self._extract_count(
  140. r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
  141. dislike_count = self._extract_count(
  142. r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
  143. comment_count = self._extract_count(
  144. r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
  145. video_variables = {}
  146. for video_variablename, quote, video_variable in re.findall(
  147. r'(player_quality_[0-9]{3,4}p\w+)\s*=\s*(["\'])(.+?)\2;', webpage):
  148. video_variables[video_variablename] = video_variable
  149. video_urls = []
  150. for encoded_video_url in re.findall(
  151. r'player_quality_[0-9]{3,4}p\s*=(.+?);', webpage):
  152. for varname, varval in video_variables.items():
  153. encoded_video_url = encoded_video_url.replace(varname, varval)
  154. video_urls.append(re.sub(r'[\s+]', '', encoded_video_url))
  155. if webpage.find('"encrypted":true') != -1:
  156. password = compat_urllib_parse_unquote_plus(
  157. self._search_regex(r'"video_title":"([^"]+)', webpage, 'password'))
  158. video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
  159. formats = []
  160. for video_url in video_urls:
  161. path = compat_urllib_parse_urlparse(video_url).path
  162. extension = os.path.splitext(path)[1][1:]
  163. format = path.split('/')[5].split('_')[:2]
  164. format = '-'.join(format)
  165. m = re.match(r'^(?P<height>[0-9]+)[pP]-(?P<tbr>[0-9]+)[kK]$', format)
  166. if m is None:
  167. height = None
  168. tbr = None
  169. else:
  170. height = int(m.group('height'))
  171. tbr = int(m.group('tbr'))
  172. formats.append({
  173. 'url': video_url,
  174. 'ext': extension,
  175. 'format': format,
  176. 'format_id': format,
  177. 'tbr': tbr,
  178. 'height': height,
  179. })
  180. self._sort_formats(formats)
  181. page_params = self._parse_json(self._search_regex(
  182. r'page_params\.zoneDetails\[([\'"])[^\'"]+\1\]\s*=\s*(?P<data>{[^}]+})',
  183. webpage, 'page parameters', group='data', default='{}'),
  184. video_id, transform_source=js_to_json, fatal=False)
  185. tags = categories = None
  186. if page_params:
  187. tags = page_params.get('tags', '').split(',')
  188. categories = page_params.get('categories', '').split(',')
  189. return {
  190. 'id': video_id,
  191. 'uploader': video_uploader,
  192. 'title': title,
  193. 'thumbnail': thumbnail,
  194. 'duration': duration,
  195. 'view_count': view_count,
  196. 'like_count': like_count,
  197. 'dislike_count': dislike_count,
  198. 'comment_count': comment_count,
  199. 'formats': formats,
  200. 'age_limit': 18,
  201. 'tags': tags,
  202. 'categories': categories,
  203. }
  204. class PornHubPlaylistBaseIE(InfoExtractor):
  205. def _extract_entries(self, webpage):
  206. return [
  207. self.url_result(
  208. 'http://www.pornhub.com/%s' % video_url,
  209. PornHubIE.ie_key(), video_title=title)
  210. for video_url, title in orderedSet(re.findall(
  211. r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^"]+)"',
  212. webpage))
  213. ]
  214. def _real_extract(self, url):
  215. playlist_id = self._match_id(url)
  216. webpage = self._download_webpage(url, playlist_id)
  217. # Only process container div with main playlist content skipping
  218. # drop-down menu that uses similar pattern for videos (see
  219. # https://github.com/rg3/youtube-dl/issues/11594).
  220. container = self._search_regex(
  221. r'(?s)(<div[^>]+class=["\']container.+)', webpage,
  222. 'container', default=webpage)
  223. entries = self._extract_entries(container)
  224. playlist = self._parse_json(
  225. self._search_regex(
  226. r'playlistObject\s*=\s*({.+?});', webpage, 'playlist'),
  227. playlist_id)
  228. return self.playlist_result(
  229. entries, playlist_id, playlist.get('title'), playlist.get('description'))
  230. class PornHubPlaylistIE(PornHubPlaylistBaseIE):
  231. _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
  232. _TESTS = [{
  233. 'url': 'http://www.pornhub.com/playlist/4667351',
  234. 'info_dict': {
  235. 'id': '4667351',
  236. 'title': 'Nataly Hot',
  237. },
  238. 'playlist_mincount': 2,
  239. }]
  240. class PornHubUserVideosIE(PornHubPlaylistBaseIE):
  241. _VALID_URL = r'https?://(?:www\.)?pornhub\.com/users/(?P<id>[^/]+)/videos'
  242. _TESTS = [{
  243. 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
  244. 'info_dict': {
  245. 'id': 'zoe_ph',
  246. },
  247. 'playlist_mincount': 171,
  248. }, {
  249. 'url': 'http://www.pornhub.com/users/rushandlia/videos',
  250. 'only_matching': True,
  251. }]
  252. def _real_extract(self, url):
  253. user_id = self._match_id(url)
  254. entries = []
  255. for page_num in itertools.count(1):
  256. try:
  257. webpage = self._download_webpage(
  258. url, user_id, 'Downloading page %d' % page_num,
  259. query={'page': page_num})
  260. except ExtractorError as e:
  261. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
  262. break
  263. page_entries = self._extract_entries(webpage)
  264. if not page_entries:
  265. break
  266. entries.extend(page_entries)
  267. return self.playlist_result(entries, user_id)