]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xhamster.py
8938c0e4561d2c6163158e409106dd2e928e85bf
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
14 class XHamsterIE(InfoExtractor
):
15 _VALID_URL
= r
'(?P<proto>https?)://(?:.+?\.)?xhamster\.com/movies/(?P<id>[0-9]+)/(?P<seo>.+?)\.html(?:\?.*)?'
18 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
22 'title': 'FemaleAgent Shy beauty takes the bait',
23 'upload_date': '20121014',
24 'uploader': 'Ruseful2011',
30 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
34 'title': 'Britney Spears Sexy Booty',
35 'upload_date': '20130914',
36 'uploader': 'jojo747400',
42 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
43 'only_matching': True,
47 def _real_extract(self
, url
):
48 def extract_video_url(webpage
, name
):
49 return self
._search
_regex
(
50 [r
'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
51 r
'''<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumb''',
52 r
'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
53 webpage
, name
, group
='mp4')
56 return '<div class=\'icon iconHD\'' in webpage
58 mobj
= re
.match(self
._VALID
_URL
, url
)
60 video_id
= mobj
.group('id')
61 seo
= mobj
.group('seo')
62 proto
= mobj
.group('proto')
63 mrss_url
= '%s://xhamster.com/movies/%s/%s.html' % (proto
, video_id
, seo
)
64 webpage
= self
._download
_webpage
(mrss_url
, video_id
)
66 title
= self
._html
_search
_regex
(
67 [r
'<title>(?P<title>.+?)(?:, (?:[^,]+? )?Porn: xHamster| - xHamster\.com)</title>',
68 r
'<h1>([^<]+)</h1>'], webpage
, 'title')
70 # Only a few videos have an description
71 mobj
= re
.search(r
'<span>Description: </span>([^<]+)', webpage
)
72 description
= mobj
.group(1) if mobj
else None
74 upload_date
= self
._html
_search
_regex
(r
'hint=\'(\d{4}
-\d{2}
-\d{2}
) \d{2}
:\d{2}
:\d{2}
[A
-Z
]{3,4}\'',
75 webpage, 'upload date
', fatal=False)
77 upload_date = unified_strdate(upload_date)
79 uploader = self._html_search_regex(
80 r"<a href='[^
']+xhamster\.com/user/[^>]+>(?P<uploader>[^<]+)",
81 webpage, 'uploader
', default='anonymous
')
83 thumbnail = self._search_regex(
84 [r'''thumb\s*:\s*(?P<q>["'])(?P
<thumbnail
>.+?
)(?P
=q
)''',
85 r'''<video
[^
>]+poster
=(?P
<q
>["'])(?P<thumbnail>.+?)(?P=q)[^>]*>'''],
86 webpage, 'thumbnail', fatal=False, group='thumbnail')
88 duration = parse_duration(self._html_search_regex(r'<span>Runtime:</span> (\d+:\d+)</div>',
89 webpage, 'duration', fatal=False))
91 view_count = self._html_search_regex(r'<span>Views:</span> ([^<]+)</div>', webpage, 'view count', fatal=False)
93 view_count = str_to_int(view_count)
95 mobj = re.search(r"hint
='(?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes'", webpage)
96 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
98 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
99 comment_count = mobj.group('commentcount') if mobj else 0
101 age_limit = self._rta_search(webpage)
105 format_id = 'hd' if hd else 'sd'
107 video_url = extract_video_url(webpage, format_id)
110 'format_id': 'hd' if hd else 'sd',
115 mrss_url = self._search_regex(r'<link rel="canonical
" href="([^
"]+)', webpage, 'mrss_url')
116 webpage = self._download_webpage(mrss_url + '?hd', video_id, note='Downloading HD webpage')
118 video_url = extract_video_url(webpage, 'hd')
125 self._sort_formats(formats)
130 'description': description,
131 'upload_date': upload_date,
132 'uploader': uploader,
133 'thumbnail': thumbnail,
134 'duration': duration,
135 'view_count': view_count,
136 'like_count': int_or_none(like_count),
137 'dislike_count': int_or_none(dislike_count),
138 'comment_count': int_or_none(comment_count),
139 'age_limit': age_limit,
144 class XHamsterEmbedIE(InfoExtractor):
145 _VALID_URL = r'https?://(?:www\.)?xhamster\.com/xembed\.php\?video=(?P<id>\d+)'
147 'url': 'http://xhamster.com/xembed.php?video=3328539',
151 'title': 'Pen Masturbation',
152 'upload_date': '20140728',
153 'uploader_id': 'anonymous',
160 def _extract_urls(webpage):
161 return [url for _, url in re.findall(
162 r'<iframe[^>]+?src=(["\'])(?P
<url
>(?
:https?
:)?
//(?
:www\
.)?xhamster\
.com
/xembed\
.php
\?video
=\d
+)\
1',
165 def _real_extract(self, url):
166 video_id = self._match_id(url)
168 webpage = self._download_webpage(url, video_id)
170 video_url = self._search_regex(
171 r'href
="(https?://xhamster\.com/movies/%s/[^"]+\
.html
[^
"]*)"' % video_id,
172 webpage, 'xhamster url
')
174 return self.url_result(video_url, 'XHamster
')