]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xhamster.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from ..compat
import compat_str
19 class XHamsterIE(InfoExtractor
):
22 (?:.+?\.)?xhamster\.com/
24 movies/(?P<id>\d+)/(?P<display_id>[^/]*)\.html|
25 videos/(?P<display_id_2>[^/]*)-(?P<id_2>\d+)
30 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
31 'md5': '8281348b8d3c53d39fffb377d24eac4e',
34 'display_id': 'femaleagent_shy_beauty_takes_the_bait',
36 'title': 'FemaleAgent Shy beauty takes the bait',
37 'timestamp': 1350194821,
38 'upload_date': '20121014',
39 'uploader': 'Ruseful2011',
42 'categories': ['Fake Hub', 'Amateur', 'MILFs', 'POV', 'Beauti', 'Beauties', 'Beautiful', 'Boss', 'Office', 'Oral', 'Reality', 'Sexy', 'Taking'],
45 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
48 'display_id': 'britney_spears_sexy_booty',
50 'title': 'Britney Spears Sexy Booty',
51 'timestamp': 1379123460,
52 'upload_date': '20130914',
53 'uploader': 'jojo747400',
56 'categories': ['Britney Spears', 'Celebrities', 'HD Videos', 'Sexy', 'Sexy Booty'],
59 'skip_download': True,
63 'url': 'http://xhamster.com/movies/5667973/.html',
68 'timestamp': 1454948101,
69 'upload_date': '20160208',
70 'uploader': 'parejafree',
73 'categories': ['Amateur', 'Blowjobs'],
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,
95 def _real_extract(self
, url
):
96 mobj
= re
.match(self
._VALID
_URL
, url
)
97 video_id
= mobj
.group('id') or mobj
.group('id_2')
98 display_id
= mobj
.group('display_id') or mobj
.group('display_id_2')
100 desktop_url
= re
.sub(r
'^(https?://(?:.+?\.)?)m\.', r
'\1', url
)
101 webpage
= self
._download
_webpage
(desktop_url
, video_id
)
103 error
= self
._html
_search
_regex
(
104 r
'<div[^>]+id=["\']videoClosed
["\'][^>]*>(.+?)</div>',
105 webpage, 'error', default=None)
107 raise ExtractorError(error, expected=True)
109 age_limit = self._rta_search(webpage)
112 return int_or_none(self._search_regex(
113 r'^(\d+)[pP]', s, 'height', default=None))
115 initials = self._parse_json(
117 r'window\.initials\s*=\s*({.+?})\s*;\s*\n', webpage, 'initials',
119 video_id, fatal=False)
121 video = initials['videoModel']
122 title = video['title']
124 for format_id, formats_dict in video['sources'].items():
125 if not isinstance(formats_dict, dict):
127 for quality, format_item in formats_dict.items():
128 if format_id == 'download':
129 # Download link takes some time to be generated,
132 if not isinstance(format_item, dict):
134 format_url = format_item.get('link')
135 filesize = int_or_none(
136 format_item.get('size'), invscale=1000000)
138 format_url = format_item
140 if not isinstance(format_url, compat_str):
143 'format_id': '%s-%s' % (format_id, quality),
145 'ext': determine_ext(format_url, 'mp4'),
146 'height': get_height(quality),
147 'filesize': filesize,
149 self._sort_formats(formats)
151 categories_list = video.get('categories')
152 if isinstance(categories_list, list):
154 for c in categories_list:
155 if not isinstance(c, dict):
157 c_name = c.get('name')
158 if isinstance(c_name, compat_str):
159 categories.append(c_name)
165 'display_id': display_id,
167 'description': video.get('description'),
168 'timestamp': int_or_none(video.get('created')),
170 video, lambda x: x['author']['name'], compat_str),
171 'thumbnail': video.get('thumbURL'),
172 'duration': int_or_none(video.get('duration')),
173 'view_count': int_or_none(video.get('views')),
174 'like_count': int_or_none(try_get(
175 video, lambda x: x['rating']['likes'], int)),
176 'dislike_count': int_or_none(try_get(
177 video, lambda x: x['rating']['dislikes'], int)),
178 'comment_count': int_or_none(video.get('views')),
179 'age_limit': age_limit,
180 'categories': categories,
184 # Old layout fallback
186 title = self._html_search_regex(
187 [r'<h1[^>]*>([^<]+)</h1>',
188 r'<meta[^>]+itemprop=".*?caption
.*?
"[^>]+content="(.+?
)"',
189 r'<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>'],
195 sources = self._parse_json(
197 r'sources\s*:\s*({.+?})\s*,?\s*\n', webpage, 'sources',
199 video_id, fatal=False)
200 for format_id, format_url in sources.items():
201 if not isinstance(format_url, compat_str):
203 if format_url in format_urls:
205 format_urls.add(format_url)
207 'format_id': format_id,
209 'height': get_height(format_id),
212 video_url = self._search_regex(
213 [r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
214 r'''<a\s+href=(?P<q>["'])(?P
<mp4
>.+?
)(?P
=q
)\s
+class=["']mp4Thumb''',
215 r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
216 webpage, 'video url
', group='mp4
', default=None)
217 if video_url and video_url not in format_urls:
222 self._sort_formats(formats)
224 # Only a few videos have an description
225 mobj = re.search(r'<span
>Description
: </span
>([^
<]+)', webpage)
226 description = mobj.group(1) if mobj else None
228 upload_date = unified_strdate(self._search_regex(
229 r'hint
=["\'](\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}',
230 webpage, 'upload date', fatal=False))
232 uploader = self._html_search_regex(
233 r'<span[^>]+itemprop=["\']author
[^
>]+><a
[^
>]+><span
[^
>]+>([^
<]+)',
234 webpage, 'uploader
', default='anonymous
')
236 thumbnail = self._search_regex(
237 [r'''["']thumbUrl
["']\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)''',
238 r'''<video[^>]+"poster"=(?P<q>["'])(?P
<thumbnail
>.+?
)(?P
=q
)[^
>]*>'''],
239 webpage, 'thumbnail', fatal=False, group='thumbnail')
241 duration = parse_duration(self._search_regex(
242 [r'<[^<]+\bitemprop=["\']duration["\'][^<]+\bcontent=["\'](.+?)["\']',
243 r'Runtime:\s*</span>\s*([\d:]+)'], webpage,
244 'duration', fatal=False))
246 view_count = int_or_none(self._search_regex(
247 r'content=["\']User(?:View|Play)s:(\d+)',
248 webpage, 'view count', fatal=False))
250 mobj = re.search(r'hint=[\'"](?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes', webpage)
251 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
253 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
254 comment_count = mobj.group('commentcount') if mobj else 0
256 categories_html = self._search_regex(
257 r'(?s)<table.+?(<span>Categories:.+?)</table>', webpage,
258 'categories', default=None)
259 categories = [clean_html(category) for category in re.findall(
260 r'<a[^>]+>(.+?)</a>', categories_html)] if categories_html else None
264 'display_id': display_id,
266 'description': description,
267 'upload_date': upload_date,
268 'uploader': uploader,
269 'thumbnail': thumbnail,
270 'duration': duration,
271 'view_count': view_count,
272 'like_count': int_or_none(like_count),
273 'dislike_count': int_or_none(dislike_count),
274 'comment_count': int_or_none(comment_count),
275 'age_limit': age_limit,
276 'categories': categories,
281 class XHamsterEmbedIE(InfoExtractor):
282 _VALID_URL = r'https?://(?:.+?\.)?xhamster\.com/xembed\.php\?video=(?P<id>\d+)'
284 'url': 'http://xhamster.com/xembed.php?video=3328539',
288 'title': 'Pen Masturbation',
289 'timestamp': 1406581861,
290 'upload_date': '20140728',
291 'uploader': 'ManyakisArt',
298 def _extract_urls(webpage):
299 return [url for _, url in re.findall(
300 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
303 def _real_extract(self, url):
304 video_id = self._match_id(url)
306 webpage = self._download_webpage(url, video_id)
308 video_url = self._search_regex(
309 r'href="(https?://xhamster\.com/(?:movies/{0}/[^"]*\.html|videos/[^/]*-{0})[^"]*)"'.format(video_id),
310 webpage, 'xhamster url', default=None)
313 vars = self._parse_json(
314 self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
316 video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
318 return self.url_result(video_url, 'XHamster')