]>
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 """Information Extractor for xHamster"""
17 _VALID_URL
= r
'(?P<proto>https?)://(?:.+?\.)?xhamster\.com/movies/(?P<id>[0-9]+)/(?P<seo>.+?)\.html(?:\?.*)?'
20 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
24 'title': 'FemaleAgent Shy beauty takes the bait',
25 'upload_date': '20121014',
26 'uploader_id': 'Ruseful2011',
32 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
36 'title': 'Britney Spears Sexy Booty',
37 'upload_date': '20130914',
38 'uploader_id': 'jojo747400',
44 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
45 'only_matching': True,
49 def _real_extract(self
, url
):
50 def extract_video_url(webpage
):
51 mp4
= re
.search(r
'<video\s+.*?file="([^"]+)".*?>', webpage
)
53 raise ExtractorError('Unable to extract media URL')
58 return '<div class=\'icon iconHD\'' in webpage
60 mobj
= re
.match(self
._VALID
_URL
, url
)
62 video_id
= mobj
.group('id')
63 seo
= mobj
.group('seo')
64 proto
= mobj
.group('proto')
65 mrss_url
= '%s://xhamster.com/movies/%s/%s.html' % (proto
, video_id
, seo
)
66 webpage
= self
._download
_webpage
(mrss_url
, video_id
)
68 title
= self
._html
_search
_regex
(r
'<title>(?P<title>.+?) - xHamster\.com</title>', 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_id = self._html_search_regex(r'<a href
=\'/user
/[^
>]+>(?P
<uploader_id
>[^
<]+)',
80 webpage, 'uploader
id', default='anonymous
')
82 thumbnail = self._html_search_regex(r'<video\s
+.*?poster
="([^"]+)".*?>', webpage, 'thumbnail', fatal=False)
84 duration = parse_duration(self._html_search_regex(r'<span>Runtime:</span> (\d+:\d+)</div>',
85 webpage, 'duration', fatal=False))
87 view_count = self._html_search_regex(r'<span>Views:</span> ([^<]+)</div>', webpage, 'view count', fatal=False)
89 view_count = str_to_int(view_count)
91 mobj = re.search(r"hint
='(?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes'", webpage)
92 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
94 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
95 comment_count = mobj.group('commentcount') if mobj else 0
97 age_limit = self._rta_search(webpage)
101 video_url = extract_video_url(webpage)
104 'format_id': 'hd' if hd else 'sd',
109 mrss_url = self._search_regex(r'<link rel="canonical
" href="([^
"]+)', webpage, 'mrss_url')
110 webpage = self._download_webpage(mrss_url + '?hd', video_id, note='Downloading HD webpage')
112 video_url = extract_video_url(webpage)
119 self._sort_formats(formats)
124 'description': description,
125 'upload_date': upload_date,
126 'uploader_id': uploader_id,
127 'thumbnail': thumbnail,
128 'duration': duration,
129 'view_count': view_count,
130 'like_count': int_or_none(like_count),
131 'dislike_count': int_or_none(dislike_count),
132 'comment_count': int_or_none(comment_count),
133 'age_limit': age_limit,