]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xhamster.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
15 class XHamsterIE(InfoExtractor
):
16 _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',
19 'md5': '8281348b8d3c53d39fffb377d24eac4e',
23 'title': 'FemaleAgent Shy beauty takes the bait',
24 'upload_date': '20121014',
25 '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',
41 'skip_download': True,
45 'url': 'http://xhamster.com/movies/5667973/.html',
50 'upload_date': '20160208',
51 'uploader': 'parejafree',
56 'skip_download': True,
59 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
60 'only_matching': True,
62 # This video is visible for marcoalfa123456's friends only
63 'url': 'https://it.xhamster.com/movies/7263980/la_mia_vicina.html',
64 'only_matching': True,
67 def _real_extract(self
, url
):
68 def extract_video_url(webpage
, name
):
69 return self
._search
_regex
(
70 [r
'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
71 r
'''<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumb''',
72 r
'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
73 webpage
, name
, group
='mp4')
76 return '<div class=\'icon iconHD\'' in webpage
78 mobj
= re
.match(self
._VALID
_URL
, url
)
80 video_id
= mobj
.group('id')
81 seo
= mobj
.group('seo')
82 proto
= mobj
.group('proto')
83 mrss_url
= '%s://xhamster.com/movies/%s/%s.html' % (proto
, video_id
, seo
)
84 webpage
= self
._download
_webpage
(mrss_url
, video_id
)
86 error
= self
._html
_search
_regex
(
87 r
'<div[^>]+id=["\']videoClosed
["\'][^>]*>(.+?)</div>',
88 webpage, 'error', default=None)
90 raise ExtractorError(error, expected=True)
92 title = self._html_search_regex(
93 [r'<h1[^>]*>([^<]+)</h1>',
94 r'<meta[^>]+itemprop=".*?caption
.*?
"[^>]+content="(.+?
)"',
95 r'<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>'],
98 # Only a few videos have an description
99 mobj = re.search(r'<span>Description: </span>([^<]+)', webpage)
100 description = mobj.group(1) if mobj else None
102 upload_date = unified_strdate(self._search_regex(
103 r'hint=["\'](\d{4}
-\d{2}
-\d{2}
) \d{2}
:\d{2}
:\d{2}
[A
-Z
]{3,4}',
104 webpage, 'upload date
', fatal=False))
106 uploader = self._html_search_regex(
107 r'<span
[^
>]+itemprop
=["\']author[^>]+><a[^>]+href=["\'].+?xhamster\
.com
/user
/[^
>]+>(?P
<uploader
>.+?
)</a
>',
108 webpage, 'uploader
', default='anonymous
')
110 thumbnail = self._search_regex(
111 [r'''thumb\s*:\s*(?P<q>["'])(?P
<thumbnail
>.+?
)(?P
=q
)''',
112 r'''<video
[^
>]+poster
=(?P
<q
>["'])(?P<thumbnail>.+?)(?P=q)[^>]*>'''],
113 webpage, 'thumbnail', fatal=False, group='thumbnail')
115 duration = parse_duration(self._search_regex(
116 r'Runtime:\s*</span>\s*([\d:]+)', webpage,
117 'duration', fatal=False))
119 view_count = int_or_none(self._search_regex(
120 r'content=["\']User(?
:View|Play
)s
:(\d
+)',
121 webpage, 'view count
', fatal=False))
123 mobj = re.search(r"hint='(?P
<likecount
>\d
+) Likes
/ (?P
<dislikecount
>\d
+) Dislikes
'", webpage)
124 (like_count, dislike_count) = (mobj.group('likecount
'), mobj.group('dislikecount
')) if mobj else (None, None)
126 mobj = re.search(r'</label
>Comments \
((?P
<commentcount
>\d
+)\
)</div
>', webpage)
127 comment_count = mobj.group('commentcount
') if mobj else 0
129 age_limit = self._rta_search(webpage)
133 format_id = 'hd
' if hd else 'sd
'
135 video_url = extract_video_url(webpage, format_id)
138 'format_id
': 'hd
' if hd else 'sd
',
143 mrss_url = self._search_regex(r'<link rel
="canonical" href
="([^"]+)', webpage, 'mrss_url
')
144 webpage = self._download_webpage(mrss_url + '?hd
', video_id, note='Downloading HD webpage
')
146 video_url = extract_video_url(webpage, 'hd
')
153 self._sort_formats(formats)
158 'description
': description,
159 'upload_date
': upload_date,
160 'uploader
': uploader,
161 'thumbnail
': thumbnail,
162 'duration
': duration,
163 'view_count
': view_count,
164 'like_count
': int_or_none(like_count),
165 'dislike_count
': int_or_none(dislike_count),
166 'comment_count
': int_or_none(comment_count),
167 'age_limit
': age_limit,
172 class XHamsterEmbedIE(InfoExtractor):
173 _VALID_URL = r'https?
://(?
:www\
.)?xhamster\
.com
/xembed\
.php
\?video
=(?P
<id>\d
+)'
175 'url
': 'http
://xhamster
.com
/xembed
.php?video
=3328539',
179 'title
': 'Pen Masturbation
',
180 'upload_date
': '20140728',
181 'uploader_id
': 'anonymous
',
188 def _extract_urls(webpage):
189 return [url for _, url in re.findall(
190 r'<iframe
[^
>]+?src
=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
193 def _real_extract(self, url):
194 video_id = self._match_id(url)
196 webpage = self._download_webpage(url, video_id)
198 video_url = self._search_regex(
199 r'href="(https?
://xhamster\
.com
/movies
/%s/[^
"]*\.html[^"]*)"' % video_id,
200 webpage, 'xhamster url', default=None)
203 vars = self._parse_json(
204 self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
206 video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
208 return self.url_result(video_url, 'XHamster')