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