]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xhamster.py
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(?:\?.*)?'
17 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
18 'md5': '8281348b8d3c53d39fffb377d24eac4e',
22 'title': 'FemaleAgent Shy beauty takes the bait',
23 'upload_date': '20121014',
24 'uploader': 'Ruseful2011',
29 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
33 'title': 'Britney Spears Sexy Booty',
34 'upload_date': '20130914',
35 'uploader': 'jojo747400',
40 'skip_download': True,
44 'url': 'http://xhamster.com/movies/5667973/.html',
49 'upload_date': '20160208',
50 'uploader': 'parejafree',
55 'skip_download': True,
58 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
59 'only_matching': True,
62 def _real_extract(self
, url
):
63 def extract_video_url(webpage
, name
):
64 return self
._search
_regex
(
65 [r
'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
66 r
'''<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumb''',
67 r
'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
68 webpage
, name
, group
='mp4')
71 return '<div class=\'icon iconHD\'' in webpage
73 mobj
= re
.match(self
._VALID
_URL
, url
)
75 video_id
= mobj
.group('id')
76 seo
= mobj
.group('seo')
77 proto
= mobj
.group('proto')
78 mrss_url
= '%s://xhamster.com/movies/%s/%s.html' % (proto
, video_id
, seo
)
79 webpage
= self
._download
_webpage
(mrss_url
, video_id
)
81 title
= self
._html
_search
_regex
(
82 [r
'<h1[^>]*>([^<]+)</h1>',
83 r
'<meta[^>]+itemprop=".*?caption.*?"[^>]+content="(.+?)"',
84 r
'<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>'],
87 # Only a few videos have an description
88 mobj
= re
.search(r
'<span>Description: </span>([^<]+)', webpage
)
89 description
= mobj
.group(1) if mobj
else None
91 upload_date
= unified_strdate(self
._search
_regex
(
92 r
'hint=["\'](\d{4}
-\d{2}
-\d{2}
) \d{2}
:\d{2}
:\d{2}
[A
-Z
]{3,4}',
93 webpage, 'upload date
', fatal=False))
95 uploader = self._html_search_regex(
96 r'<span
[^
>]+itemprop
=["\']author[^>]+><a[^>]+href=["\'].+?xhamster\
.com
/user
/[^
>]+>(?P
<uploader
>.+?
)</a
>',
97 webpage, 'uploader
', default='anonymous
')
99 thumbnail = self._search_regex(
100 [r'''thumb\s*:\s*(?P<q>["'])(?P
<thumbnail
>.+?
)(?P
=q
)''',
101 r'''<video
[^
>]+poster
=(?P
<q
>["'])(?P<thumbnail>.+?)(?P=q)[^>]*>'''],
102 webpage, 'thumbnail', fatal=False, group='thumbnail')
104 duration = float_or_none(self._search_regex(
105 r'(["\'])duration\
1\s
*:\s
*(["\'])(?P<duration>.+?)\2',
106 webpage, 'duration', fatal=False, group='duration'))
108 view_count = int_or_none(self._search_regex(
109 r'content=["\']User(?
:View|Play
)s
:(\d
+)',
110 webpage, 'view count
', fatal=False))
112 mobj = re.search(r"hint='(?P
<likecount
>\d
+) Likes
/ (?P
<dislikecount
>\d
+) Dislikes
'", webpage)
113 (like_count, dislike_count) = (mobj.group('likecount
'), mobj.group('dislikecount
')) if mobj else (None, None)
115 mobj = re.search(r'</label
>Comments \
((?P
<commentcount
>\d
+)\
)</div
>', webpage)
116 comment_count = mobj.group('commentcount
') if mobj else 0
118 age_limit = self._rta_search(webpage)
122 format_id = 'hd
' if hd else 'sd
'
124 video_url = extract_video_url(webpage, format_id)
127 'format_id
': 'hd
' if hd else 'sd
',
132 mrss_url = self._search_regex(r'<link rel
="canonical" href
="([^"]+)', webpage, 'mrss_url
')
133 webpage = self._download_webpage(mrss_url + '?hd
', video_id, note='Downloading HD webpage
')
135 video_url = extract_video_url(webpage, 'hd
')
142 self._sort_formats(formats)
147 'description
': description,
148 'upload_date
': upload_date,
149 'uploader
': uploader,
150 'thumbnail
': thumbnail,
151 'duration
': duration,
152 'view_count
': view_count,
153 'like_count
': int_or_none(like_count),
154 'dislike_count
': int_or_none(dislike_count),
155 'comment_count
': int_or_none(comment_count),
156 'age_limit
': age_limit,
161 class XHamsterEmbedIE(InfoExtractor):
162 _VALID_URL = r'https?
://(?
:www\
.)?xhamster\
.com
/xembed\
.php
\?video
=(?P
<id>\d
+)'
164 'url
': 'http
://xhamster
.com
/xembed
.php?video
=3328539',
168 'title
': 'Pen Masturbation
',
169 'upload_date
': '20140728',
170 'uploader_id
': 'anonymous
',
177 def _extract_urls(webpage):
178 return [url for _, url in re.findall(
179 r'<iframe
[^
>]+?src
=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
182 def _real_extract(self, url):
183 video_id = self._match_id(url)
185 webpage = self._download_webpage(url, video_id)
187 video_url = self._search_regex(
188 r'href="(https?
://xhamster\
.com
/movies
/%s/[^
"]*\.html[^"]*)"' % video_id,
189 webpage, 'xhamster url', default=None)
192 vars = self._parse_json(
193 self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
195 video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
197 return self.url_result(video_url, 'XHamster')