]>
Commit | Line | Data |
---|---|---|
d7975ea2 PH |
1 | from __future__ import unicode_literals |
2 | ||
cbf46c73 PH |
3 | import re |
4 | ||
5 | from .common import InfoExtractor | |
5c2266df | 6 | from ..compat import compat_urllib_parse_unquote |
1cc79574 | 7 | from ..utils import ( |
3217377b | 8 | clean_html, |
1cc79574 | 9 | ExtractorError, |
964afd06 | 10 | determine_ext, |
cbf46c73 PH |
11 | ) |
12 | ||
13 | ||
14 | class XVideosIE(InfoExtractor): | |
1cc79574 | 15 | _VALID_URL = r'https?://(?:www\.)?xvideos\.com/video(?P<id>[0-9]+)(?:.*)' |
6f5ac90c | 16 | _TEST = { |
a6ffb92f | 17 | 'url': 'http://www.xvideos.com/video4588838/biker_takes_his_girl', |
98affc1a | 18 | 'md5': '14cea69fcb84db54293b1e971466c2e1', |
d7975ea2 | 19 | 'info_dict': { |
a6ffb92f | 20 | 'id': '4588838', |
98affc1a | 21 | 'ext': 'mp4', |
a6ffb92f S |
22 | 'title': 'Biker Takes his Girl', |
23 | 'age_limit': 18, | |
6f5ac90c PH |
24 | } |
25 | } | |
cbf46c73 PH |
26 | |
27 | def _real_extract(self, url): | |
1cc79574 | 28 | video_id = self._match_id(url) |
cbf46c73 PH |
29 | webpage = self._download_webpage(url, video_id) |
30 | ||
3217377b S |
31 | mobj = re.search(r'<h1 class="inlineError">(.+?)</h1>', webpage) |
32 | if mobj: | |
33 | raise ExtractorError('%s said: %s' % (self.IE_NAME, clean_html(mobj.group(1))), expected=True) | |
34 | ||
d7975ea2 PH |
35 | video_title = self._html_search_regex( |
36 | r'<title>(.*?)\s+-\s+XVID', webpage, 'title') | |
d7975ea2 PH |
37 | video_thumbnail = self._search_regex( |
38 | r'url_bigthumb=(.+?)&', webpage, 'thumbnail', fatal=False) | |
cbf46c73 | 39 | |
69c9cc27 | 40 | formats = [] |
964afd06 | 41 | |
69c9cc27 S |
42 | video_url = compat_urllib_parse_unquote(self._search_regex( |
43 | r'flv_url=(.+?)&', webpage, 'video URL', default='')) | |
44 | if video_url: | |
70a2829f S |
45 | formats.append({ |
46 | 'url': video_url, | |
47 | 'format_id': 'flv', | |
48 | }) | |
964afd06 | 49 | |
70a2829f S |
50 | for kind, _, format_url in re.findall( |
51 | r'setVideo([^(]+)\((["\'])(http.+?)\2\)', webpage): | |
52 | format_id = kind.lower() | |
53 | if format_id == 'hls': | |
54 | formats.extend(self._extract_m3u8_formats( | |
55 | format_url, video_id, 'mp4', | |
56 | entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)) | |
57 | elif format_id in ('urllow', 'urlhigh'): | |
58 | formats.append({ | |
59 | 'url': format_url, | |
60 | 'format_id': '%s-%s' % (determine_ext(format_url, 'mp4'), format_id[3:]), | |
61 | 'quality': -2 if format_id.endswith('low') else None, | |
62 | }) | |
964afd06 YCH |
63 | |
64 | self._sort_formats(formats) | |
65 | ||
d7975ea2 | 66 | return { |
cbf46c73 | 67 | 'id': video_id, |
964afd06 | 68 | 'formats': formats, |
cbf46c73 | 69 | 'title': video_title, |
cbf46c73 | 70 | 'thumbnail': video_thumbnail, |
8ed6b344 | 71 | 'age_limit': 18, |
cbf46c73 | 72 | } |