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