]>
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, |
964afd06 | 9 | determine_ext, |
6ec371cd S |
10 | ExtractorError, |
11 | int_or_none, | |
13081db1 | 12 | parse_duration, |
cbf46c73 PH |
13 | ) |
14 | ||
15 | ||
16 | class XVideosIE(InfoExtractor): | |
cf5f6ed5 S |
17 | _VALID_URL = r'''(?x) |
18 | https?:// | |
19 | (?: | |
4e72d02f S |
20 | (?:[^/]+\.)?xvideos2?\.com/video| |
21 | (?:www\.)?xvideos\.es/video| | |
849d699a | 22 | (?:www|flashservice)\.xvideos\.com/embedframe/| |
cf5f6ed5 S |
23 | static-hw\.xvideos\.com/swf/xv-player\.swf\?.*?\bid_video= |
24 | ) | |
25 | (?P<id>[0-9]+) | |
26 | ''' | |
27 | _TESTS = [{ | |
a6ffb92f | 28 | 'url': 'http://www.xvideos.com/video4588838/biker_takes_his_girl', |
98affc1a | 29 | 'md5': '14cea69fcb84db54293b1e971466c2e1', |
d7975ea2 | 30 | 'info_dict': { |
a6ffb92f | 31 | 'id': '4588838', |
98affc1a | 32 | 'ext': 'mp4', |
a6ffb92f | 33 | 'title': 'Biker Takes his Girl', |
6ec371cd | 34 | 'duration': 108, |
a6ffb92f | 35 | 'age_limit': 18, |
6f5ac90c | 36 | } |
cf5f6ed5 S |
37 | }, { |
38 | 'url': 'https://flashservice.xvideos.com/embedframe/4588838', | |
39 | 'only_matching': True, | |
849d699a | 40 | }, { |
41 | 'url': 'https://www.xvideos.com/embedframe/4588838', | |
42 | 'only_matching': True, | |
cf5f6ed5 S |
43 | }, { |
44 | 'url': 'http://static-hw.xvideos.com/swf/xv-player.swf?id_video=4588838', | |
45 | 'only_matching': True, | |
4e72d02f S |
46 | }, { |
47 | 'url': 'http://xvideos.com/video4588838/biker_takes_his_girl', | |
48 | 'only_matching': True | |
49 | }, { | |
50 | 'url': 'https://xvideos.com/video4588838/biker_takes_his_girl', | |
51 | 'only_matching': True | |
52 | }, { | |
53 | 'url': 'https://xvideos.es/video4588838/biker_takes_his_girl', | |
54 | 'only_matching': True | |
55 | }, { | |
56 | 'url': 'https://www.xvideos.es/video4588838/biker_takes_his_girl', | |
57 | 'only_matching': True | |
58 | }, { | |
59 | 'url': 'http://xvideos.es/video4588838/biker_takes_his_girl', | |
60 | 'only_matching': True | |
61 | }, { | |
62 | 'url': 'http://www.xvideos.es/video4588838/biker_takes_his_girl', | |
63 | 'only_matching': True | |
64 | }, { | |
65 | 'url': 'http://fr.xvideos.com/video4588838/biker_takes_his_girl', | |
66 | 'only_matching': True | |
67 | }, { | |
68 | 'url': 'https://fr.xvideos.com/video4588838/biker_takes_his_girl', | |
69 | 'only_matching': True | |
70 | }, { | |
71 | 'url': 'http://it.xvideos.com/video4588838/biker_takes_his_girl', | |
72 | 'only_matching': True | |
73 | }, { | |
74 | 'url': 'https://it.xvideos.com/video4588838/biker_takes_his_girl', | |
75 | 'only_matching': True | |
76 | }, { | |
77 | 'url': 'http://de.xvideos.com/video4588838/biker_takes_his_girl', | |
78 | 'only_matching': True | |
79 | }, { | |
80 | 'url': 'https://de.xvideos.com/video4588838/biker_takes_his_girl', | |
81 | 'only_matching': True | |
cf5f6ed5 | 82 | }] |
cbf46c73 PH |
83 | |
84 | def _real_extract(self, url): | |
1cc79574 | 85 | video_id = self._match_id(url) |
2abf0815 | 86 | webpage = self._download_webpage(url, video_id) |
cbf46c73 | 87 | |
3217377b S |
88 | mobj = re.search(r'<h1 class="inlineError">(.+?)</h1>', webpage) |
89 | if mobj: | |
90 | raise ExtractorError('%s said: %s' % (self.IE_NAME, clean_html(mobj.group(1))), expected=True) | |
91 | ||
cf5f6ed5 S |
92 | title = self._html_search_regex( |
93 | (r'<title>(?P<title>.+?)\s+-\s+XVID', | |
94 | r'setVideoTitle\s*\(\s*(["\'])(?P<title>(?:(?!\1).)+)\1'), | |
95 | webpage, 'title', default=None, | |
96 | group='title') or self._og_search_title(webpage) | |
97 | ||
f4da8080 S |
98 | thumbnails = [] |
99 | for preference, thumbnail in enumerate(('', '169')): | |
100 | thumbnail_url = self._search_regex( | |
101 | r'setThumbUrl%s\(\s*(["\'])(?P<thumbnail>(?:(?!\1).)+)\1' % thumbnail, | |
102 | webpage, 'thumbnail', default=None, group='thumbnail') | |
103 | if thumbnail_url: | |
104 | thumbnails.append({ | |
105 | 'url': thumbnail_url, | |
106 | 'preference': preference, | |
107 | }) | |
108 | ||
cf5f6ed5 | 109 | duration = int_or_none(self._og_search_property( |
6ec371cd S |
110 | 'duration', webpage, default=None)) or parse_duration( |
111 | self._search_regex( | |
112 | r'<span[^>]+class=["\']duration["\'][^>]*>.*?(\d[^<]+)', | |
113 | webpage, 'duration', fatal=False)) | |
cbf46c73 | 114 | |
69c9cc27 | 115 | formats = [] |
964afd06 | 116 | |
69c9cc27 S |
117 | video_url = compat_urllib_parse_unquote(self._search_regex( |
118 | r'flv_url=(.+?)&', webpage, 'video URL', default='')) | |
119 | if video_url: | |
70a2829f S |
120 | formats.append({ |
121 | 'url': video_url, | |
122 | 'format_id': 'flv', | |
123 | }) | |
964afd06 | 124 | |
70a2829f S |
125 | for kind, _, format_url in re.findall( |
126 | r'setVideo([^(]+)\((["\'])(http.+?)\2\)', webpage): | |
127 | format_id = kind.lower() | |
128 | if format_id == 'hls': | |
129 | formats.extend(self._extract_m3u8_formats( | |
130 | format_url, video_id, 'mp4', | |
131 | entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)) | |
132 | elif format_id in ('urllow', 'urlhigh'): | |
133 | formats.append({ | |
134 | 'url': format_url, | |
135 | 'format_id': '%s-%s' % (determine_ext(format_url, 'mp4'), format_id[3:]), | |
136 | 'quality': -2 if format_id.endswith('low') else None, | |
137 | }) | |
964afd06 YCH |
138 | |
139 | self._sort_formats(formats) | |
140 | ||
d7975ea2 | 141 | return { |
cbf46c73 | 142 | 'id': video_id, |
964afd06 | 143 | 'formats': formats, |
cf5f6ed5 S |
144 | 'title': title, |
145 | 'duration': duration, | |
f4da8080 | 146 | 'thumbnails': thumbnails, |
8ed6b344 | 147 | 'age_limit': 18, |
cbf46c73 | 148 | } |