]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xhamster.py
Prepare for release.
[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 _TEST = {
15 u'url': u'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
16 u'file': u'1509445.flv',
17 u'md5': u'9f48e0e8d58e3076bb236ff412ab62fa',
18 u'info_dict': {
19 u"upload_date": u"20121014",
20 u"uploader_id": u"Ruseful2011",
21 u"title": u"FemaleAgent Shy beauty takes the bait"
22 }
23 }
24
25 def _real_extract(self,url):
26 mobj = re.match(self._VALID_URL, url)
27
28 video_id = mobj.group('id')
29 mrss_url = 'http://xhamster.com/movies/%s/.html' % video_id
30 webpage = self._download_webpage(mrss_url, video_id)
31
32 mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
33 if mobj is None:
34 raise ExtractorError(u'Unable to extract media URL')
35 if len(mobj.group('server')) == 0:
36 video_url = compat_urllib_parse.unquote(mobj.group('file'))
37 else:
38 video_url = mobj.group('server')+'/key='+mobj.group('file')
39 video_extension = video_url.split('.')[-1]
40
41 video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
42 webpage, u'title')
43
44 # Can't see the description anywhere in the UI
45 # video_description = self._html_search_regex(r'<span>Description: </span>(?P<description>[^<]+)',
46 # webpage, u'description', fatal=False)
47 # if video_description: video_description = unescapeHTML(video_description)
48
49 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)
50 if mobj:
51 video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
52 else:
53 video_upload_date = None
54 self._downloader.report_warning(u'Unable to extract upload date')
55
56 video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
57 webpage, u'uploader id', default=u'anonymous')
58
59 video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
60 webpage, u'thumbnail', fatal=False)
61
62 return [{
63 'id': video_id,
64 'url': video_url,
65 'ext': video_extension,
66 'title': video_title,
67 # 'description': video_description,
68 'upload_date': video_upload_date,
69 'uploader_id': video_uploader_id,
70 'thumbnail': video_thumbnail
71 }]