]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xvideos.py
Update changelog.
[youtubedl] / youtube_dl / extractor / xvideos.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..compat import (
7 compat_urllib_parse_unquote,
8 compat_urllib_request,
9 )
10 from ..utils import (
11 clean_html,
12 ExtractorError,
13 determine_ext,
14 )
15
16
17 class XVideosIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?xvideos\.com/video(?P<id>[0-9]+)(?:.*)'
19 _TEST = {
20 'url': 'http://www.xvideos.com/video4588838/biker_takes_his_girl',
21 'md5': '4b46ae6ea5e6e9086e714d883313c0c9',
22 'info_dict': {
23 'id': '4588838',
24 'ext': 'flv',
25 'title': 'Biker Takes his Girl',
26 'age_limit': 18,
27 }
28 }
29
30 _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'
31
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
34 webpage = self._download_webpage(url, video_id)
35
36 mobj = re.search(r'<h1 class="inlineError">(.+?)</h1>', webpage)
37 if mobj:
38 raise ExtractorError('%s said: %s' % (self.IE_NAME, clean_html(mobj.group(1))), expected=True)
39
40 video_url = compat_urllib_parse_unquote(
41 self._search_regex(r'flv_url=(.+?)&', webpage, 'video URL'))
42 video_title = self._html_search_regex(
43 r'<title>(.*?)\s+-\s+XVID', webpage, 'title')
44 video_thumbnail = self._search_regex(
45 r'url_bigthumb=(.+?)&amp', webpage, 'thumbnail', fatal=False)
46
47 formats = [{
48 'url': video_url,
49 }]
50
51 android_req = compat_urllib_request.Request(url)
52 android_req.add_header('User-Agent', self._ANDROID_USER_AGENT)
53 android_webpage = self._download_webpage(android_req, video_id, fatal=False)
54
55 if android_webpage is not None:
56 player_params_str = self._search_regex(
57 'mobileReplacePlayerDivTwoQual\(([^)]+)\)',
58 android_webpage, 'player parameters', default='')
59 player_params = list(map(lambda s: s.strip(' \''), player_params_str.split(',')))
60 if player_params:
61 formats.extend([{
62 'url': param,
63 'preference': -10,
64 } for param in player_params if determine_ext(param) == 'mp4'])
65
66 self._sort_formats(formats)
67
68 return {
69 'id': video_id,
70 'formats': formats,
71 'title': video_title,
72 'ext': 'flv',
73 'thumbnail': video_thumbnail,
74 'age_limit': 18,
75 }