]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/xvideos.py
[README.md] Fix lists formatting (closes #20558)
[yt-dlp.git] / youtube_dl / 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 (?:
20 (?:www\.)?xvideos\.com/video|
21 flashservice\.xvideos\.com/embedframe/|
22 static-hw\.xvideos\.com/swf/xv-player\.swf\?.*?\bid_video=
23 )
24 (?P<id>[0-9]+)
25 '''
26 _TESTS = [{
a6ffb92f 27 'url': 'http://www.xvideos.com/video4588838/biker_takes_his_girl',
98affc1a 28 'md5': '14cea69fcb84db54293b1e971466c2e1',
d7975ea2 29 'info_dict': {
a6ffb92f 30 'id': '4588838',
98affc1a 31 'ext': 'mp4',
a6ffb92f 32 'title': 'Biker Takes his Girl',
6ec371cd 33 'duration': 108,
a6ffb92f 34 'age_limit': 18,
6f5ac90c 35 }
cf5f6ed5
S
36 }, {
37 'url': 'https://flashservice.xvideos.com/embedframe/4588838',
38 'only_matching': True,
39 }, {
40 'url': 'http://static-hw.xvideos.com/swf/xv-player.swf?id_video=4588838',
41 'only_matching': True,
42 }]
cbf46c73
PH
43
44 def _real_extract(self, url):
1cc79574 45 video_id = self._match_id(url)
cf5f6ed5
S
46
47 webpage = self._download_webpage(
ebb04490 48 'https://www.xvideos.com/video%s/' % video_id, video_id)
cbf46c73 49
3217377b
S
50 mobj = re.search(r'<h1 class="inlineError">(.+?)</h1>', webpage)
51 if mobj:
52 raise ExtractorError('%s said: %s' % (self.IE_NAME, clean_html(mobj.group(1))), expected=True)
53
cf5f6ed5
S
54 title = self._html_search_regex(
55 (r'<title>(?P<title>.+?)\s+-\s+XVID',
56 r'setVideoTitle\s*\(\s*(["\'])(?P<title>(?:(?!\1).)+)\1'),
57 webpage, 'title', default=None,
58 group='title') or self._og_search_title(webpage)
59
60 thumbnail = self._search_regex(
0669f8fd
PV
61 (r'setThumbUrl\(\s*(["\'])(?P<thumbnail>(?:(?!\1).)+)\1',
62 r'url_bigthumb=(?P<thumbnail>.+?)&amp'),
63 webpage, 'thumbnail', fatal=False, group='thumbnail')
cf5f6ed5 64 duration = int_or_none(self._og_search_property(
6ec371cd
S
65 'duration', webpage, default=None)) or parse_duration(
66 self._search_regex(
67 r'<span[^>]+class=["\']duration["\'][^>]*>.*?(\d[^<]+)',
68 webpage, 'duration', fatal=False))
cbf46c73 69
69c9cc27 70 formats = []
964afd06 71
69c9cc27
S
72 video_url = compat_urllib_parse_unquote(self._search_regex(
73 r'flv_url=(.+?)&', webpage, 'video URL', default=''))
74 if video_url:
70a2829f
S
75 formats.append({
76 'url': video_url,
77 'format_id': 'flv',
78 })
964afd06 79
70a2829f
S
80 for kind, _, format_url in re.findall(
81 r'setVideo([^(]+)\((["\'])(http.+?)\2\)', webpage):
82 format_id = kind.lower()
83 if format_id == 'hls':
84 formats.extend(self._extract_m3u8_formats(
85 format_url, video_id, 'mp4',
86 entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
87 elif format_id in ('urllow', 'urlhigh'):
88 formats.append({
89 'url': format_url,
90 'format_id': '%s-%s' % (determine_ext(format_url, 'mp4'), format_id[3:]),
91 'quality': -2 if format_id.endswith('low') else None,
92 })
964afd06
YCH
93
94 self._sort_formats(formats)
95
d7975ea2 96 return {
cbf46c73 97 'id': video_id,
964afd06 98 'formats': formats,
cf5f6ed5
S
99 'title': title,
100 'duration': duration,
101 'thumbnail': thumbnail,
8ed6b344 102 'age_limit': 18,
cbf46c73 103 }