]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xhamster.py
361619694980d3260ff81aeed2d0d07294739a0e
[youtubedl] / youtube_dl / extractor / xhamster.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 compat_urllib_parse,
6 unescapeHTML,
7 determine_ext,
8 ExtractorError,
9 )
10
11
12 class XHamsterIE(InfoExtractor):
13 """Information Extractor for xHamster"""
14 _VALID_URL = r'(?:http://)?(?:www\.)?xhamster\.com/movies/(?P<id>[0-9]+)/(?P<seo>.+?)\.html(?:\?.*)?'
15 _TESTS = [{
16 u'url': u'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
17 u'file': u'1509445.flv',
18 u'md5': u'9f48e0e8d58e3076bb236ff412ab62fa',
19 u'info_dict': {
20 u"upload_date": u"20121014",
21 u"uploader_id": u"Ruseful2011",
22 u"title": u"FemaleAgent Shy beauty takes the bait"
23 }
24 },
25 {
26 u'url': u'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
27 u'file': u'2221348.flv',
28 u'md5': u'e767b9475de189320f691f49c679c4c7',
29 u'info_dict': {
30 u"upload_date": u"20130914",
31 u"uploader_id": u"jojo747400",
32 u"title": u"Britney Spears Sexy Booty"
33 }
34 }]
35
36 def _real_extract(self,url):
37 mobj = re.match(self._VALID_URL, url)
38
39 video_id = mobj.group('id')
40 seo = mobj.group('seo')
41 mrss_url = 'http://xhamster.com/movies/%s/%s.html?hd' % (video_id, seo)
42 webpage = self._download_webpage(mrss_url, video_id)
43
44 mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
45 if mobj is None:
46 raise ExtractorError(u'Unable to extract media URL')
47 if len(mobj.group('server')) == 0:
48 video_url = compat_urllib_parse.unquote(mobj.group('file'))
49 else:
50 video_url = mobj.group('server')+'/key='+mobj.group('file')
51
52 video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
53 webpage, u'title')
54
55 # Only a few videos have an description
56 mobj = re.search('<span>Description: </span>(?P<description>[^<]+)', webpage)
57 if mobj:
58 video_description = unescapeHTML(mobj.group('description'))
59 else:
60 video_description = None
61
62 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)
63 if mobj:
64 video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
65 else:
66 video_upload_date = None
67 self._downloader.report_warning(u'Unable to extract upload date')
68
69 video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
70 webpage, u'uploader id', default=u'anonymous')
71
72 video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
73 webpage, u'thumbnail', fatal=False)
74
75 return [{
76 'id': video_id,
77 'url': video_url,
78 'ext': determine_ext(video_url),
79 'title': video_title,
80 'description': video_description,
81 'upload_date': video_upload_date,
82 'uploader_id': video_uploader_id,
83 'thumbnail': video_thumbnail
84 }]