]>
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, |
5c2266df | 11 | sanitized_Request, |
cbf46c73 PH |
12 | ) |
13 | ||
14 | ||
15 | class XVideosIE(InfoExtractor): | |
1cc79574 | 16 | _VALID_URL = r'https?://(?:www\.)?xvideos\.com/video(?P<id>[0-9]+)(?:.*)' |
6f5ac90c | 17 | _TEST = { |
a6ffb92f S |
18 | 'url': 'http://www.xvideos.com/video4588838/biker_takes_his_girl', |
19 | 'md5': '4b46ae6ea5e6e9086e714d883313c0c9', | |
d7975ea2 | 20 | 'info_dict': { |
a6ffb92f S |
21 | 'id': '4588838', |
22 | 'ext': 'flv', | |
23 | 'title': 'Biker Takes his Girl', | |
24 | 'age_limit': 18, | |
6f5ac90c PH |
25 | } |
26 | } | |
cbf46c73 | 27 | |
964afd06 YCH |
28 | _ANDROID_USER_AGENT = 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19' |
29 | ||
cbf46c73 | 30 | def _real_extract(self, url): |
1cc79574 | 31 | video_id = self._match_id(url) |
cbf46c73 PH |
32 | webpage = self._download_webpage(url, video_id) |
33 | ||
3217377b S |
34 | mobj = re.search(r'<h1 class="inlineError">(.+?)</h1>', webpage) |
35 | if mobj: | |
36 | raise ExtractorError('%s said: %s' % (self.IE_NAME, clean_html(mobj.group(1))), expected=True) | |
37 | ||
aa4789d6 | 38 | video_url = compat_urllib_parse_unquote( |
d7975ea2 | 39 | self._search_regex(r'flv_url=(.+?)&', webpage, 'video URL')) |
d7975ea2 PH |
40 | video_title = self._html_search_regex( |
41 | r'<title>(.*?)\s+-\s+XVID', webpage, 'title') | |
d7975ea2 PH |
42 | video_thumbnail = self._search_regex( |
43 | r'url_bigthumb=(.+?)&', webpage, 'thumbnail', fatal=False) | |
cbf46c73 | 44 | |
964afd06 YCH |
45 | formats = [{ |
46 | 'url': video_url, | |
47 | }] | |
48 | ||
5c2266df | 49 | android_req = sanitized_Request(url) |
964afd06 YCH |
50 | android_req.add_header('User-Agent', self._ANDROID_USER_AGENT) |
51 | android_webpage = self._download_webpage(android_req, video_id, fatal=False) | |
52 | ||
53 | if android_webpage is not None: | |
54 | player_params_str = self._search_regex( | |
55 | 'mobileReplacePlayerDivTwoQual\(([^)]+)\)', | |
56 | android_webpage, 'player parameters', default='') | |
57 | player_params = list(map(lambda s: s.strip(' \''), player_params_str.split(','))) | |
58 | if player_params: | |
59 | formats.extend([{ | |
60 | 'url': param, | |
61 | 'preference': -10, | |
62 | } for param in player_params if determine_ext(param) == 'mp4']) | |
63 | ||
64 | self._sort_formats(formats) | |
65 | ||
d7975ea2 | 66 | return { |
cbf46c73 | 67 | 'id': video_id, |
964afd06 | 68 | 'formats': formats, |
cbf46c73 PH |
69 | 'title': video_title, |
70 | 'ext': 'flv', | |
71 | 'thumbnail': video_thumbnail, | |
8ed6b344 | 72 | 'age_limit': 18, |
cbf46c73 | 73 | } |