]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/twentyfourvideo.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / twentyfourvideo.py
CommitLineData
ac563359
S
1from .common import InfoExtractor
2from ..utils import (
3 parse_iso8601,
4 int_or_none,
128eb31d
S
5 xpath_attr,
6 xpath_element,
ac563359
S
7)
8
9
10class TwentyFourVideoIE(InfoExtractor):
11 IE_NAME = '24video'
f4cc2ca5
S
12 _VALID_URL = r'''(?x)
13 https?://
14 (?P<host>
f6052ec9 15 (?:(?:www|porno?)\.)?24video\.
a4b27694 16 (?:net|me|xxx|sexy?|tube|adult|site|vip)
f4cc2ca5
S
17 )/
18 (?:
19 video/(?:(?:view|xml)/)?|
20 player/new24_play\.swf\?id=
21 )
22 (?P<id>\d+)
23 '''
ac563359 24
c366f8d3
S
25 _TESTS = [{
26 'url': 'http://www.24video.net/video/view/1044982',
27 'md5': 'e09fc0901d9eaeedac872f154931deeb',
28 'info_dict': {
29 'id': '1044982',
30 'ext': 'mp4',
31 'title': 'Эротика каменного века',
32 'description': 'Как смотрели порно в каменном веке.',
ec85ded8 33 'thumbnail': r're:^https?://.*\.jpg$',
c366f8d3
S
34 'uploader': 'SUPERTELO',
35 'duration': 31,
36 'timestamp': 1275937857,
37 'upload_date': '20100607',
38 'age_limit': 18,
39 'like_count': int,
40 'dislike_count': int,
ac563359 41 },
c366f8d3
S
42 }, {
43 'url': 'http://www.24video.net/player/new24_play.swf?id=1044982',
44 'only_matching': True,
45 }, {
46 'url': 'http://www.24video.me/video/view/1044982',
47 'only_matching': True,
71e9577b
S
48 }, {
49 'url': 'http://www.24video.tube/video/view/2363750',
50 'only_matching': True,
11ec06de
S
51 }, {
52 'url': 'https://www.24video.site/video/view/2640421',
53 'only_matching': True,
f4cc2ca5
S
54 }, {
55 'url': 'https://porno.24video.net/video/2640421-vsya-takaya-gibkaya-i-v-masle',
56 'only_matching': True,
a4b27694
S
57 }, {
58 'url': 'https://www.24video.vip/video/view/1044982',
59 'only_matching': True,
f6052ec9
S
60 }, {
61 'url': 'https://porn.24video.net/video/2640421-vsya-takay',
62 'only_matching': True,
c366f8d3 63 }]
ac563359
S
64
65 def _real_extract(self, url):
5ad28e7f 66 mobj = self._match_valid_url(url)
9bae185b
S
67 video_id = mobj.group('id')
68 host = mobj.group('host')
ac563359
S
69
70 webpage = self._download_webpage(
9bae185b 71 'http://%s/video/view/%s' % (host, video_id), video_id)
ac563359
S
72
73 title = self._og_search_title(webpage)
74 description = self._html_search_regex(
f6e588af
S
75 r'<(p|span)[^>]+itemprop="description"[^>]*>(?P<description>[^<]+)</\1>',
76 webpage, 'description', fatal=False, group='description')
ac563359
S
77 thumbnail = self._og_search_thumbnail(webpage)
78 duration = int_or_none(self._og_search_property(
79 'duration', webpage, 'duration', fatal=False))
80 timestamp = parse_iso8601(self._search_regex(
e3440d82
S
81 r'<time[^>]+\bdatetime="([^"]+)"[^>]+itemprop="uploadDate"',
82 webpage, 'upload date', fatal=False))
ac563359
S
83
84 uploader = self._html_search_regex(
687cb3ad 85 r'class="video-uploaded"[^>]*>\s*<a href="/jsecUser/movies/[^"]+"[^>]*>([^<]+)</a>',
ac563359
S
86 webpage, 'uploader', fatal=False)
87
88 view_count = int_or_none(self._html_search_regex(
89 r'<span class="video-views">(\d+) просмотр',
90 webpage, 'view count', fatal=False))
91 comment_count = int_or_none(self._html_search_regex(
bd6fb007 92 r'<a[^>]+href="#tab-comments"[^>]*>(\d+) комментари',
e3440d82 93 webpage, 'comment count', default=None))
ac563359 94
747b0284
S
95 # Sets some cookies
96 self._download_xml(
9bae185b 97 r'http://%s/video/xml/%s?mode=init' % (host, video_id),
747b0284 98 video_id, 'Downloading init XML')
ac563359 99
128eb31d 100 video_xml = self._download_xml(
9bae185b 101 'http://%s/video/xml/%s?mode=play' % (host, video_id),
128eb31d
S
102 video_id, 'Downloading video XML')
103
104 video = xpath_element(video_xml, './/video', 'video', fatal=True)
ac563359 105
747b0284 106 formats = [{
128eb31d 107 'url': xpath_attr(video, '', 'url', 'video URL', fatal=True),
747b0284 108 }]
ac563359 109
747b0284
S
110 like_count = int_or_none(video.get('ratingPlus'))
111 dislike_count = int_or_none(video.get('ratingMinus'))
112 age_limit = 18 if video.get('adult') == 'true' else 0
ac563359
S
113
114 return {
115 'id': video_id,
116 'title': title,
117 'description': description,
118 'thumbnail': thumbnail,
119 'uploader': uploader,
120 'duration': duration,
121 'timestamp': timestamp,
122 'view_count': view_count,
123 'comment_count': comment_count,
124 'like_count': like_count,
125 'dislike_count': dislike_count,
126 'age_limit': age_limit,
127 'formats': formats,
128 }