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.

270 lines
9.4 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. # private video
  83. 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph56fd731fce6b7',
  84. 'only_matching': True,
  85. }, {
  86. 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
  87. 'only_matching': True,
  88. }]
  89. @classmethod
  90. def _extract_url(cls, webpage):
  91. mobj = re.search(
  92. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?pornhub\.com/embed/\d+)\1', webpage)
  93. if mobj:
  94. return mobj.group('url')
  95. def _extract_count(self, pattern, webpage, name):
  96. return str_to_int(self._search_regex(
  97. pattern, webpage, '%s count' % name, fatal=False))
  98. def _real_extract(self, url):
  99. video_id = self._match_id(url)
  100. req = sanitized_Request(
  101. 'http://www.pornhub.com/view_video.php?viewkey=%s' % video_id)
  102. req.add_header('Cookie', 'age_verified=1')
  103. webpage = self._download_webpage(req, video_id)
  104. error_msg = self._html_search_regex(
  105. r'(?s)<div[^>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
  106. webpage, 'error message', default=None, group='error')
  107. if error_msg:
  108. error_msg = re.sub(r'\s+', ' ', error_msg)
  109. raise ExtractorError(
  110. 'PornHub said: %s' % error_msg,
  111. expected=True, video_id=video_id)
  112. # video_title from flashvars contains whitespace instead of non-ASCII (see
  113. # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
  114. # on that anymore.
  115. title = self._html_search_meta(
  116. 'twitter:title', webpage, default=None) or self._search_regex(
  117. (r'<h1[^>]+class=["\']title["\'][^>]*>(?P<title>[^<]+)',
  118. r'<div[^>]+data-video-title=(["\'])(?P<title>.+?)\1',
  119. r'shareTitle\s*=\s*(["\'])(?P<title>.+?)\1'),
  120. webpage, 'title', group='title')
  121. flashvars = self._parse_json(
  122. self._search_regex(
  123. r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
  124. video_id)
  125. if flashvars:
  126. thumbnail = flashvars.get('image_url')
  127. duration = int_or_none(flashvars.get('video_duration'))
  128. else:
  129. title, thumbnail, duration = [None] * 3
  130. video_uploader = self._html_search_regex(
  131. r'(?s)From:&nbsp;.+?<(?:a href="/users/|a href="/channels/|span class="username)[^>]+>(.+?)<',
  132. webpage, 'uploader', fatal=False)
  133. view_count = self._extract_count(
  134. r'<span class="count">([\d,\.]+)</span> views', webpage, 'view')
  135. like_count = self._extract_count(
  136. r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
  137. dislike_count = self._extract_count(
  138. r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
  139. comment_count = self._extract_count(
  140. r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
  141. video_urls = list(map(compat_urllib_parse_unquote, re.findall(r"player_quality_[0-9]{3}p\s*=\s*'([^']+)'", webpage)))
  142. if webpage.find('"encrypted":true') != -1:
  143. password = compat_urllib_parse_unquote_plus(
  144. self._search_regex(r'"video_title":"([^"]+)', webpage, 'password'))
  145. video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
  146. formats = []
  147. for video_url in video_urls:
  148. path = compat_urllib_parse_urlparse(video_url).path
  149. extension = os.path.splitext(path)[1][1:]
  150. format = path.split('/')[5].split('_')[:2]
  151. format = '-'.join(format)
  152. m = re.match(r'^(?P<height>[0-9]+)[pP]-(?P<tbr>[0-9]+)[kK]$', format)
  153. if m is None:
  154. height = None
  155. tbr = None
  156. else:
  157. height = int(m.group('height'))
  158. tbr = int(m.group('tbr'))
  159. formats.append({
  160. 'url': video_url,
  161. 'ext': extension,
  162. 'format': format,
  163. 'format_id': format,
  164. 'tbr': tbr,
  165. 'height': height,
  166. })
  167. self._sort_formats(formats)
  168. return {
  169. 'id': video_id,
  170. 'uploader': video_uploader,
  171. 'title': title,
  172. 'thumbnail': thumbnail,
  173. 'duration': duration,
  174. 'view_count': view_count,
  175. 'like_count': like_count,
  176. 'dislike_count': dislike_count,
  177. 'comment_count': comment_count,
  178. 'formats': formats,
  179. 'age_limit': 18,
  180. }
  181. class PornHubPlaylistBaseIE(InfoExtractor):
  182. def _extract_entries(self, webpage):
  183. return [
  184. self.url_result(
  185. 'http://www.pornhub.com/%s' % video_url,
  186. PornHubIE.ie_key(), video_title=title)
  187. for video_url, title in orderedSet(re.findall(
  188. r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^"]+)"',
  189. webpage))
  190. ]
  191. def _real_extract(self, url):
  192. playlist_id = self._match_id(url)
  193. webpage = self._download_webpage(url, playlist_id)
  194. entries = self._extract_entries(webpage)
  195. playlist = self._parse_json(
  196. self._search_regex(
  197. r'playlistObject\s*=\s*({.+?});', webpage, 'playlist'),
  198. playlist_id)
  199. return self.playlist_result(
  200. entries, playlist_id, playlist.get('title'), playlist.get('description'))
  201. class PornHubPlaylistIE(PornHubPlaylistBaseIE):
  202. _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
  203. _TESTS = [{
  204. 'url': 'http://www.pornhub.com/playlist/6201671',
  205. 'info_dict': {
  206. 'id': '6201671',
  207. 'title': 'P0p4',
  208. },
  209. 'playlist_mincount': 35,
  210. }]
  211. class PornHubUserVideosIE(PornHubPlaylistBaseIE):
  212. _VALID_URL = r'https?://(?:www\.)?pornhub\.com/users/(?P<id>[^/]+)/videos'
  213. _TESTS = [{
  214. 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
  215. 'info_dict': {
  216. 'id': 'zoe_ph',
  217. },
  218. 'playlist_mincount': 171,
  219. }, {
  220. 'url': 'http://www.pornhub.com/users/rushandlia/videos',
  221. 'only_matching': True,
  222. }]
  223. def _real_extract(self, url):
  224. user_id = self._match_id(url)
  225. entries = []
  226. for page_num in itertools.count(1):
  227. try:
  228. webpage = self._download_webpage(
  229. url, user_id, 'Downloading page %d' % page_num,
  230. query={'page': page_num})
  231. except ExtractorError as e:
  232. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
  233. break
  234. page_entries = self._extract_entries(webpage)
  235. if not page_entries:
  236. break
  237. entries.extend(page_entries)
  238. return self.playlist_result(entries, user_id)