]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xhamster.py
68a48034ead8036eb28f3815a6588ac4a2253fbb
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from ..compat
import compat_str
20 class XHamsterIE(InfoExtractor
):
23 (?:.+?\.)?xhamster\.com/
25 movies/(?P<id>\d+)/(?P<display_id>[^/]*)\.html|
26 videos/(?P<display_id_2>[^/]*)-(?P<id_2>\d+)
31 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
32 'md5': '8281348b8d3c53d39fffb377d24eac4e',
35 'display_id': 'femaleagent_shy_beauty_takes_the_bait',
37 'title': 'FemaleAgent Shy beauty takes the bait',
38 'timestamp': 1350194821,
39 'upload_date': '20121014',
40 'uploader': 'Ruseful2011',
43 'categories': ['Fake Hub', 'Amateur', 'MILFs', 'POV', 'Beauti', 'Beauties', 'Beautiful', 'Boss', 'Office', 'Oral', 'Reality', 'Sexy', 'Taking'],
46 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
49 'display_id': 'britney_spears_sexy_booty',
51 'title': 'Britney Spears Sexy Booty',
52 'timestamp': 1379123460,
53 'upload_date': '20130914',
54 'uploader': 'jojo747400',
57 'categories': ['Britney Spears', 'Celebrities', 'HD Videos', 'Sexy', 'Sexy Booty'],
60 'skip_download': True,
64 'url': 'http://xhamster.com/movies/5667973/.html',
69 'timestamp': 1454948101,
70 'upload_date': '20160208',
71 'uploader': 'parejafree',
74 'categories': ['Amateur', 'Blowjobs'],
77 'skip_download': True,
81 'url': 'https://m.xhamster.com/videos/cute-teen-jacqueline-solo-masturbation-8559111',
82 'only_matching': True,
84 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
85 'only_matching': True,
87 # This video is visible for marcoalfa123456's friends only
88 'url': 'https://it.xhamster.com/movies/7263980/la_mia_vicina.html',
89 'only_matching': True,
92 'url': 'https://pt.xhamster.com/videos/euro-pedal-pumping-7937821',
93 'only_matching': True,
96 def _real_extract(self
, url
):
97 mobj
= re
.match(self
._VALID
_URL
, url
)
98 video_id
= mobj
.group('id') or mobj
.group('id_2')
99 display_id
= mobj
.group('display_id') or mobj
.group('display_id_2')
101 desktop_url
= re
.sub(r
'^(https?://(?:.+?\.)?)m\.', r
'\1', url
)
102 webpage
= self
._download
_webpage
(desktop_url
, video_id
)
104 error
= self
._html
_search
_regex
(
105 r
'<div[^>]+id=["\']videoClosed
["\'][^>]*>(.+?)</div>',
106 webpage, 'error', default=None)
108 raise ExtractorError(error, expected=True)
110 age_limit = self._rta_search(webpage)
113 return int_or_none(self._search_regex(
114 r'^(\d+)[pP]', s, 'height', default=None))
116 initials = self._parse_json(
118 r'window\.initials\s*=\s*({.+?})\s*;\s*\n', webpage, 'initials',
120 video_id, fatal=False)
122 video = initials['videoModel']
123 title = video['title']
125 for format_id, formats_dict in video['sources'].items():
126 if not isinstance(formats_dict, dict):
128 for quality, format_item in formats_dict.items():
129 if format_id == 'download':
130 # Download link takes some time to be generated,
133 if not isinstance(format_item, dict):
135 format_url = format_item.get('link')
136 filesize = int_or_none(
137 format_item.get('size'), invscale=1000000)
139 format_url = format_item
141 format_url = url_or_none(format_url)
145 'format_id': '%s-%s' % (format_id, quality),
147 'ext': determine_ext(format_url, 'mp4'),
148 'height': get_height(quality),
149 'filesize': filesize,
151 self._sort_formats(formats)
153 categories_list = video.get('categories')
154 if isinstance(categories_list, list):
156 for c in categories_list:
157 if not isinstance(c, dict):
159 c_name = c.get('name')
160 if isinstance(c_name, compat_str):
161 categories.append(c_name)
167 'display_id': display_id,
169 'description': video.get('description'),
170 'timestamp': int_or_none(video.get('created')),
172 video, lambda x: x['author']['name'], compat_str),
173 'thumbnail': video.get('thumbURL'),
174 'duration': int_or_none(video.get('duration')),
175 'view_count': int_or_none(video.get('views')),
176 'like_count': int_or_none(try_get(
177 video, lambda x: x['rating']['likes'], int)),
178 'dislike_count': int_or_none(try_get(
179 video, lambda x: x['rating']['dislikes'], int)),
180 'comment_count': int_or_none(video.get('views')),
181 'age_limit': age_limit,
182 'categories': categories,
186 # Old layout fallback
188 title = self._html_search_regex(
189 [r'<h1[^>]*>([^<]+)</h1>',
190 r'<meta[^>]+itemprop=".*?caption
.*?
"[^>]+content="(.+?
)"',
191 r'<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>'],
197 sources = self._parse_json(
199 r'sources\s*:\s*({.+?})\s*,?\s*\n', webpage, 'sources',
201 video_id, fatal=False)
202 for format_id, format_url in sources.items():
203 format_url = url_or_none(format_url)
206 if format_url in format_urls:
208 format_urls.add(format_url)
210 'format_id': format_id,
212 'height': get_height(format_id),
215 video_url = self._search_regex(
216 [r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
217 r'''<a\s+href=(?P<q>["'])(?P
<mp4
>.+?
)(?P
=q
)\s
+class=["']mp4Thumb''',
218 r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
219 webpage, 'video url
', group='mp4
', default=None)
220 if video_url and video_url not in format_urls:
225 self._sort_formats(formats)
227 # Only a few videos have an description
228 mobj = re.search(r'<span
>Description
: </span
>([^
<]+)', webpage)
229 description = mobj.group(1) if mobj else None
231 upload_date = unified_strdate(self._search_regex(
232 r'hint
=["\'](\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}',
233 webpage, 'upload date', fatal=False))
235 uploader = self._html_search_regex(
236 r'<span[^>]+itemprop=["\']author
[^
>]+><a
[^
>]+><span
[^
>]+>([^
<]+)',
237 webpage, 'uploader
', default='anonymous
')
239 thumbnail = self._search_regex(
240 [r'''["']thumbUrl
["']\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)''',
241 r'''<video[^>]+"poster"=(?P<q>["'])(?P
<thumbnail
>.+?
)(?P
=q
)[^
>]*>'''],
242 webpage, 'thumbnail', fatal=False, group='thumbnail')
244 duration = parse_duration(self._search_regex(
245 [r'<[^<]+\bitemprop=["\']duration["\'][^<]+\bcontent=["\'](.+?)["\']',
246 r'Runtime:\s*</span>\s*([\d:]+)'], webpage,
247 'duration', fatal=False))
249 view_count = int_or_none(self._search_regex(
250 r'content=["\']User(?:View|Play)s:(\d+)',
251 webpage, 'view count', fatal=False))
253 mobj = re.search(r'hint=[\'"](?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes', webpage)
254 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
256 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
257 comment_count = mobj.group('commentcount') if mobj else 0
259 categories_html = self._search_regex(
260 r'(?s)<table.+?(<span>Categories:.+?)</table>', webpage,
261 'categories', default=None)
262 categories = [clean_html(category) for category in re.findall(
263 r'<a[^>]+>(.+?)</a>', categories_html)] if categories_html else None
267 'display_id': display_id,
269 'description': description,
270 'upload_date': upload_date,
271 'uploader': uploader,
272 'thumbnail': thumbnail,
273 'duration': duration,
274 'view_count': view_count,
275 'like_count': int_or_none(like_count),
276 'dislike_count': int_or_none(dislike_count),
277 'comment_count': int_or_none(comment_count),
278 'age_limit': age_limit,
279 'categories': categories,
284 class XHamsterEmbedIE(InfoExtractor):
285 _VALID_URL = r'https?://(?:.+?\.)?xhamster\.com/xembed\.php\?video=(?P<id>\d+)'
287 'url': 'http://xhamster.com/xembed.php?video=3328539',
291 'title': 'Pen Masturbation',
292 'timestamp': 1406581861,
293 'upload_date': '20140728',
294 'uploader': 'ManyakisArt',
301 def _extract_urls(webpage):
302 return [url for _, url in re.findall(
303 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
306 def _real_extract(self, url):
307 video_id = self._match_id(url)
309 webpage = self._download_webpage(url, video_id)
311 video_url = self._search_regex(
312 r'href="(https?://xhamster\.com/(?:movies/{0}/[^"]*\.html|videos/[^/]*-{0})[^"]*)"'.format(video_id),
313 webpage, 'xhamster url', default=None)
316 vars = self._parse_json(
317 self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
319 video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
321 return self.url_result(video_url, 'XHamster')