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.

292 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>[\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_urls = list(map(compat_urllib_parse_unquote, re.findall(r"player_quality_[0-9]{3}p\s*=\s*'([^']+)'", webpage)))
  146. if webpage.find('"encrypted":true') != -1:
  147. password = compat_urllib_parse_unquote_plus(
  148. self._search_regex(r'"video_title":"([^"]+)', webpage, 'password'))
  149. video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
  150. formats = []
  151. for video_url in video_urls:
  152. path = compat_urllib_parse_urlparse(video_url).path
  153. extension = os.path.splitext(path)[1][1:]
  154. format = path.split('/')[5].split('_')[:2]
  155. format = '-'.join(format)
  156. m = re.match(r'^(?P<height>[0-9]+)[pP]-(?P<tbr>[0-9]+)[kK]$', format)
  157. if m is None:
  158. height = None
  159. tbr = None
  160. else:
  161. height = int(m.group('height'))
  162. tbr = int(m.group('tbr'))
  163. formats.append({
  164. 'url': video_url,
  165. 'ext': extension,
  166. 'format': format,
  167. 'format_id': format,
  168. 'tbr': tbr,
  169. 'height': height,
  170. })
  171. self._sort_formats(formats)
  172. page_params = self._parse_json(self._search_regex(
  173. r'page_params\.zoneDetails\[([\'"])[^\'"]+\1\]\s*=\s*(?P<data>{[^}]+})',
  174. webpage, 'page parameters', group='data', default='{}'),
  175. video_id, transform_source=js_to_json, fatal=False)
  176. tags = categories = None
  177. if page_params:
  178. tags = page_params.get('tags', '').split(',')
  179. categories = page_params.get('categories', '').split(',')
  180. return {
  181. 'id': video_id,
  182. 'uploader': video_uploader,
  183. 'title': title,
  184. 'thumbnail': thumbnail,
  185. 'duration': duration,
  186. 'view_count': view_count,
  187. 'like_count': like_count,
  188. 'dislike_count': dislike_count,
  189. 'comment_count': comment_count,
  190. 'formats': formats,
  191. 'age_limit': 18,
  192. 'tags': tags,
  193. 'categories': categories,
  194. }
  195. class PornHubPlaylistBaseIE(InfoExtractor):
  196. def _extract_entries(self, webpage):
  197. return [
  198. self.url_result(
  199. 'http://www.pornhub.com/%s' % video_url,
  200. PornHubIE.ie_key(), video_title=title)
  201. for video_url, title in orderedSet(re.findall(
  202. r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^"]+)"',
  203. webpage))
  204. ]
  205. def _real_extract(self, url):
  206. playlist_id = self._match_id(url)
  207. webpage = self._download_webpage(url, playlist_id)
  208. # Only process container div with main playlist content skipping
  209. # drop-down menu that uses similar pattern for videos (see
  210. # https://github.com/rg3/youtube-dl/issues/11594).
  211. container = self._search_regex(
  212. r'(?s)(<div[^>]+class=["\']container.+)', webpage,
  213. 'container', default=webpage)
  214. entries = self._extract_entries(container)
  215. playlist = self._parse_json(
  216. self._search_regex(
  217. r'playlistObject\s*=\s*({.+?});', webpage, 'playlist'),
  218. playlist_id)
  219. return self.playlist_result(
  220. entries, playlist_id, playlist.get('title'), playlist.get('description'))
  221. class PornHubPlaylistIE(PornHubPlaylistBaseIE):
  222. _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
  223. _TESTS = [{
  224. 'url': 'http://www.pornhub.com/playlist/4667351',
  225. 'info_dict': {
  226. 'id': '4667351',
  227. 'title': 'Nataly Hot',
  228. },
  229. 'playlist_mincount': 2,
  230. }]
  231. class PornHubUserVideosIE(PornHubPlaylistBaseIE):
  232. _VALID_URL = r'https?://(?:www\.)?pornhub\.com/users/(?P<id>[^/]+)/videos'
  233. _TESTS = [{
  234. 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
  235. 'info_dict': {
  236. 'id': 'zoe_ph',
  237. },
  238. 'playlist_mincount': 171,
  239. }, {
  240. 'url': 'http://www.pornhub.com/users/rushandlia/videos',
  241. 'only_matching': True,
  242. }]
  243. def _real_extract(self, url):
  244. user_id = self._match_id(url)
  245. entries = []
  246. for page_num in itertools.count(1):
  247. try:
  248. webpage = self._download_webpage(
  249. url, user_id, 'Downloading page %d' % page_num,
  250. query={'page': page_num})
  251. except ExtractorError as e:
  252. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
  253. break
  254. page_entries = self._extract_entries(webpage)
  255. if not page_entries:
  256. break
  257. entries.extend(page_entries)
  258. return self.playlist_result(entries, user_id)