]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xhamster.py
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
22 class XHamsterIE(InfoExtractor
):
23 _DOMAINS
= r
'(?:xhamster\.(?:com|one|desi)|xhms\.pro|xhamster[27]\.com)'
28 movies/(?P<id>\d+)/(?P<display_id>[^/]*)\.html|
29 videos/(?P<display_id_2>[^/]*)-(?P<id_2>\d+)
33 'url': 'https://xhamster.com/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
34 'md5': '98b4687efb1ffd331c4197854dc09e8f',
37 'display_id': 'femaleagent-shy-beauty-takes-the-bait',
39 'title': 'FemaleAgent Shy beauty takes the bait',
40 'timestamp': 1350194821,
41 'upload_date': '20121014',
42 'uploader': 'Ruseful2011',
47 'url': 'https://xhamster.com/videos/britney-spears-sexy-booty-2221348?hd=',
50 'display_id': 'britney-spears-sexy-booty',
52 'title': 'Britney Spears Sexy Booty',
53 'timestamp': 1379123460,
54 'upload_date': '20130914',
55 'uploader': 'jojo747400',
60 'skip_download': True,
63 # empty seo, unavailable via new URL schema
64 'url': 'http://xhamster.com/movies/5667973/.html',
69 'timestamp': 1454948101,
70 'upload_date': '20160208',
71 'uploader': 'parejafree',
76 'skip_download': True,
80 'url': 'https://m.xhamster.com/videos/cute-teen-jacqueline-solo-masturbation-8559111',
81 'only_matching': True,
83 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
84 'only_matching': True,
86 # This video is visible for marcoalfa123456's friends only
87 'url': 'https://it.xhamster.com/movies/7263980/la_mia_vicina.html',
88 'only_matching': True,
91 'url': 'https://pt.xhamster.com/videos/euro-pedal-pumping-7937821',
92 'only_matching': True,
94 'url': 'https://xhamster.one/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
95 'only_matching': True,
97 'url': 'https://xhamster.desi/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
98 'only_matching': True,
100 'url': 'https://xhamster2.com/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
101 'only_matching': True,
103 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
104 'only_matching': True,
106 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
107 'only_matching': True,
110 def _real_extract(self
, url
):
111 mobj
= re
.match(self
._VALID
_URL
, url
)
112 video_id
= mobj
.group('id') or mobj
.group('id_2')
113 display_id
= mobj
.group('display_id') or mobj
.group('display_id_2')
115 desktop_url
= re
.sub(r
'^(https?://(?:.+?\.)?)m\.', r
'\1', url
)
116 webpage
= self
._download
_webpage
(desktop_url
, video_id
)
118 error
= self
._html
_search
_regex
(
119 r
'<div[^>]+id=["\']videoClosed
["\'][^>]*>(.+?)</div>',
120 webpage, 'error', default=None)
122 raise ExtractorError(error, expected=True)
124 age_limit = self._rta_search(webpage)
127 return int_or_none(self._search_regex(
128 r'^(\d+)[pP]', s, 'height', default=None))
130 initials = self._parse_json(
132 r'window\.initials\s*=\s*({.+?})\s*;\s*\n', webpage, 'initials',
134 video_id, fatal=False)
136 video = initials['videoModel']
137 title = video['title']
139 for format_id, formats_dict in video['sources'].items():
140 if not isinstance(formats_dict, dict):
142 for quality, format_item in formats_dict.items():
143 if format_id == 'download':
144 # Download link takes some time to be generated,
147 if not isinstance(format_item, dict):
149 format_url = format_item.get('link')
150 filesize = int_or_none(
151 format_item.get('size'), invscale=1000000)
153 format_url = format_item
155 format_url = url_or_none(format_url)
159 'format_id': '%s-%s' % (format_id, quality),
161 'ext': determine_ext(format_url, 'mp4'),
162 'height': get_height(quality),
163 'filesize': filesize,
165 self._sort_formats(formats)
167 categories_list = video.get('categories')
168 if isinstance(categories_list, list):
170 for c in categories_list:
171 if not isinstance(c, dict):
173 c_name = c.get('name')
174 if isinstance(c_name, compat_str):
175 categories.append(c_name)
181 'display_id': display_id,
183 'description': video.get('description'),
184 'timestamp': int_or_none(video.get('created')),
186 video, lambda x: x['author']['name'], compat_str),
187 'thumbnail': video.get('thumbURL'),
188 'duration': int_or_none(video.get('duration')),
189 'view_count': int_or_none(video.get('views')),
190 'like_count': int_or_none(try_get(
191 video, lambda x: x['rating']['likes'], int)),
192 'dislike_count': int_or_none(try_get(
193 video, lambda x: x['rating']['dislikes'], int)),
194 'comment_count': int_or_none(video.get('views')),
195 'age_limit': age_limit,
196 'categories': categories,
200 # Old layout fallback
202 title = self._html_search_regex(
203 [r'<h1[^>]*>([^<]+)</h1>',
204 r'<meta[^>]+itemprop=".*?caption
.*?
"[^>]+content="(.+?
)"',
205 r'<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>'],
211 sources = self._parse_json(
213 r'sources\s*:\s*({.+?})\s*,?\s*\n', webpage, 'sources',
215 video_id, fatal=False)
216 for format_id, format_url in sources.items():
217 format_url = url_or_none(format_url)
220 if format_url in format_urls:
222 format_urls.add(format_url)
224 'format_id': format_id,
226 'height': get_height(format_id),
229 video_url = self._search_regex(
230 [r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
231 r'''<a\s+href=(?P<q>["'])(?P
<mp4
>.+?
)(?P
=q
)\s
+class=["']mp4Thumb''',
232 r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
233 webpage, 'video url
', group='mp4
', default=None)
234 if video_url and video_url not in format_urls:
239 self._sort_formats(formats)
241 # Only a few videos have an description
242 mobj = re.search(r'<span
>Description
: </span
>([^
<]+)', webpage)
243 description = mobj.group(1) if mobj else None
245 upload_date = unified_strdate(self._search_regex(
246 r'hint
=["\'](\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}',
247 webpage, 'upload date', fatal=False))
249 uploader = self._html_search_regex(
250 r'<span[^>]+itemprop=["\']author
[^
>]+><a
[^
>]+><span
[^
>]+>([^
<]+)',
251 webpage, 'uploader
', default='anonymous
')
253 thumbnail = self._search_regex(
254 [r'''["']thumbUrl
["']\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)''',
255 r'''<video[^>]+"poster"=(?P<q>["'])(?P
<thumbnail
>.+?
)(?P
=q
)[^
>]*>'''],
256 webpage, 'thumbnail', fatal=False, group='thumbnail')
258 duration = parse_duration(self._search_regex(
259 [r'<[^<]+\bitemprop=["\']duration["\'][^<]+\bcontent=["\'](.+?)["\']',
260 r'Runtime:\s*</span>\s*([\d:]+)'], webpage,
261 'duration', fatal=False))
263 view_count = int_or_none(self._search_regex(
264 r'content=["\']User(?:View|Play)s:(\d+)',
265 webpage, 'view count', fatal=False))
267 mobj = re.search(r'hint=[\'"](?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes', webpage)
268 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
270 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
271 comment_count = mobj.group('commentcount') if mobj else 0
273 categories_html = self._search_regex(
274 r'(?s)<table.+?(<span>Categories:.+?)</table>', webpage,
275 'categories', default=None)
276 categories = [clean_html(category) for category in re.findall(
277 r'<a[^>]+>(.+?)</a>', categories_html)] if categories_html else None
281 'display_id': display_id,
283 'description': description,
284 'upload_date': upload_date,
285 'uploader': uploader,
286 'thumbnail': thumbnail,
287 'duration': duration,
288 'view_count': view_count,
289 'like_count': int_or_none(like_count),
290 'dislike_count': int_or_none(dislike_count),
291 'comment_count': int_or_none(comment_count),
292 'age_limit': age_limit,
293 'categories': categories,
298 class XHamsterEmbedIE(InfoExtractor):
299 _VALID_URL = r'https?://(?:.+?\.)?%s/xembed\.php\?video=(?P<id>\d+)' % XHamsterIE._DOMAINS
301 'url': 'http://xhamster.com/xembed.php?video=3328539',
305 'title': 'Pen Masturbation',
306 'timestamp': 1406581861,
307 'upload_date': '20140728',
308 'uploader': 'ManyakisArt',
315 def _extract_urls(webpage):
316 return [url for _, url in re.findall(
317 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
320 def _real_extract(self, url):
321 video_id = self._match_id(url)
323 webpage = self._download_webpage(url, video_id)
325 video_url = self._search_regex(
326 r'href="(https?://xhamster\.com/(?:movies/{0}/[^"]*\.html|videos/[^/]*-{0})[^"]*)"'.format(video_id),
327 webpage, 'xhamster url', default=None)
330 vars = self._parse_json(
331 self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
333 video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
335 return self.url_result(video_url, 'XHamster')
338 class XHamsterUserIE(InfoExtractor):
339 _VALID_URL = r'https?://(?:.+?\.)?%s/users/(?P<id>[^/?#&]+)' % XHamsterIE._DOMAINS
341 # Paginated user profile
342 'url': 'https://xhamster.com/users/netvideogirls/videos',
344 'id': 'netvideogirls',
346 'playlist_mincount': 267,
348 # Non-paginated user profile
349 'url': 'https://xhamster.com/users/firatkaan/videos',
353 'playlist_mincount': 1,
356 def _entries(self, user_id):
357 next_page_url = 'https://xhamster.com/users/%s/videos/1' % user_id
358 for pagenum in itertools.count(1):
359 page = self._download_webpage(
360 next_page_url, user_id, 'Downloading page %s' % pagenum)
361 for video_tag in re.findall(
362 r'(<a[^>]+class=["\'].*?\bvideo-thumb__image-container[^>]+>)',
364 video = extract_attributes(video_tag)
365 video_url = url_or_none(video.get('href'))
366 if not video_url or not XHamsterIE.suitable(video_url):
368 video_id = XHamsterIE._match_id(video_url)
369 yield self.url_result(
370 video_url, ie=XHamsterIE.ie_key(), video_id=video_id)
371 mobj = re.search(r'<a[^>]+data-page=["\']next[^>]+>', page)
374 next_page = extract_attributes(mobj.group(0))
375 next_page_url = url_or_none(next_page.get('href'))
376 if not next_page_url:
379 def _real_extract(self, url):
380 user_id = self._match_id(url)
381 return self.playlist_result(self._entries(user_id), user_id)