]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xhamster.py
00135092623f61a86bae99862fbf6b788a85be76
[youtubedl] / youtube_dl / extractor / xhamster.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 compat_urllib_parse,
6
7 ExtractorError,
8 )
9
10
11 class XHamsterIE(InfoExtractor):
12 """Information Extractor for xHamster"""
13 _VALID_URL = r'(?:http://)?(?:www.)?xhamster\.com/movies/(?P<id>[0-9]+)/.*\.html'
14
15 def _real_extract(self,url):
16 mobj = re.match(self._VALID_URL, url)
17
18 video_id = mobj.group('id')
19 mrss_url = 'http://xhamster.com/movies/%s/.html' % video_id
20 webpage = self._download_webpage(mrss_url, video_id)
21
22 mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
23 if mobj is None:
24 raise ExtractorError(u'Unable to extract media URL')
25 if len(mobj.group('server')) == 0:
26 video_url = compat_urllib_parse.unquote(mobj.group('file'))
27 else:
28 video_url = mobj.group('server')+'/key='+mobj.group('file')
29 video_extension = video_url.split('.')[-1]
30
31 video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
32 webpage, u'title')
33
34 # Can't see the description anywhere in the UI
35 # video_description = self._html_search_regex(r'<span>Description: </span>(?P<description>[^<]+)',
36 # webpage, u'description', fatal=False)
37 # if video_description: video_description = unescapeHTML(video_description)
38
39 mobj = re.search(r'hint=\'(?P<upload_date_Y>[0-9]{4})-(?P<upload_date_m>[0-9]{2})-(?P<upload_date_d>[0-9]{2}) [0-9]{2}:[0-9]{2}:[0-9]{2} [A-Z]{3,4}\'', webpage)
40 if mobj:
41 video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
42 else:
43 video_upload_date = None
44 self._downloader.report_warning(u'Unable to extract upload date')
45
46 video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
47 webpage, u'uploader id', default=u'anonymous')
48
49 video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
50 webpage, u'thumbnail', fatal=False)
51
52 return [{
53 'id': video_id,
54 'url': video_url,
55 'ext': video_extension,
56 'title': video_title,
57 # 'description': video_description,
58 'upload_date': video_upload_date,
59 'uploader_id': video_uploader_id,
60 'thumbnail': video_thumbnail
61 }]