]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/xvideos.py
[youtube] Add extractor-arg to skip auto-translated subs
[yt-dlp.git] / yt_dlp / extractor / xvideos.py
CommitLineData
d7975ea2
PH
1from __future__ import unicode_literals
2
cbf46c73
PH
3import re
4
5from .common import InfoExtractor
5c2266df 6from ..compat import compat_urllib_parse_unquote
1cc79574 7from ..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
16class 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 = [{
8efffafa 28 'url': 'https://www.xvideos.com/video4588838/motorcycle_guy_cucks_influencer_steals_his_gf',
98affc1a 29 'md5': '14cea69fcb84db54293b1e971466c2e1',
d7975ea2 30 'info_dict': {
a6ffb92f 31 'id': '4588838',
98affc1a 32 'ext': 'mp4',
8efffafa 33 'title': 'Motorcycle Guy Cucks Influencer, Steals his GF',
6ec371cd 34 'duration': 108,
a6ffb92f 35 'age_limit': 18,
8efffafa
M
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',
6f5ac90c 49 }
cf5f6ed5
S
50 }, {
51 'url': 'https://flashservice.xvideos.com/embedframe/4588838',
52 'only_matching': True,
849d699a 53 }, {
54 'url': 'https://www.xvideos.com/embedframe/4588838',
55 'only_matching': True,
cf5f6ed5
S
56 }, {
57 'url': 'http://static-hw.xvideos.com/swf/xv-player.swf?id_video=4588838',
58 'only_matching': True,
4e72d02f
S
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
cf5f6ed5 95 }]
cbf46c73
PH
96
97 def _real_extract(self, url):
1cc79574 98 video_id = self._match_id(url)
2abf0815 99 webpage = self._download_webpage(url, video_id)
cbf46c73 100
3217377b
S
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
cf5f6ed5
S
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
f4da8080
S
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
cf5f6ed5 122 duration = int_or_none(self._og_search_property(
6ec371cd
S
123 'duration', webpage, default=None)) or parse_duration(
124 self._search_regex(
125 r'<span[^>]+class=["\']duration["\'][^>]*>.*?(\d[^<]+)',
126 webpage, 'duration', fatal=False))
cbf46c73 127
69c9cc27 128 formats = []
964afd06 129
69c9cc27
S
130 video_url = compat_urllib_parse_unquote(self._search_regex(
131 r'flv_url=(.+?)&', webpage, 'video URL', default=''))
132 if video_url:
70a2829f
S
133 formats.append({
134 'url': video_url,
135 'format_id': 'flv',
136 })
964afd06 137
70a2829f
S
138 for kind, _, format_url in re.findall(
139 r'setVideo([^(]+)\((["\'])(http.+?)\2\)', webpage):
140 format_id = kind.lower()
141 if format_id == 'hls':
8efffafa 142 hls_formats = self._extract_m3u8_formats(
70a2829f 143 format_url, video_id, 'mp4',
8efffafa
M
144 entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)
145 self._check_formats(hls_formats, video_id)
146 formats.extend(hls_formats)
70a2829f
S
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 })
964afd06
YCH
153
154 self._sort_formats(formats)
155
d7975ea2 156 return {
cbf46c73 157 'id': video_id,
964afd06 158 'formats': formats,
cf5f6ed5
S
159 'title': title,
160 'duration': duration,
f4da8080 161 'thumbnails': thumbnails,
8ed6b344 162 'age_limit': 18,
cbf46c73 163 }