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.

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