]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/twentyfourvideo.py
baeb85d4730a2198bf07f51490984b1e346f6c59
[yt-dlp.git] / yt_dlp / extractor / twentyfourvideo.py
1 from .common import InfoExtractor
2 from ..utils import (
3 parse_iso8601,
4 int_or_none,
5 xpath_attr,
6 xpath_element,
7 )
8
9
10 class TwentyFourVideoIE(InfoExtractor):
11 IE_NAME = '24video'
12 _VALID_URL = r'''(?x)
13 https?://
14 (?P<host>
15 (?:(?:www|porno?)\.)?24video\.
16 (?:net|me|xxx|sexy?|tube|adult|site|vip)
17 )/
18 (?:
19 video/(?:(?:view|xml)/)?|
20 player/new24_play\.swf\?id=
21 )
22 (?P<id>\d+)
23 '''
24
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': 'Как смотрели порно в каменном веке.',
33 'thumbnail': r're:^https?://.*\.jpg$',
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,
41 },
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,
48 }, {
49 'url': 'http://www.24video.tube/video/view/2363750',
50 'only_matching': True,
51 }, {
52 'url': 'https://www.24video.site/video/view/2640421',
53 'only_matching': True,
54 }, {
55 'url': 'https://porno.24video.net/video/2640421-vsya-takaya-gibkaya-i-v-masle',
56 'only_matching': True,
57 }, {
58 'url': 'https://www.24video.vip/video/view/1044982',
59 'only_matching': True,
60 }, {
61 'url': 'https://porn.24video.net/video/2640421-vsya-takay',
62 'only_matching': True,
63 }]
64
65 def _real_extract(self, url):
66 mobj = self._match_valid_url(url)
67 video_id = mobj.group('id')
68 host = mobj.group('host')
69
70 webpage = self._download_webpage(
71 'http://%s/video/view/%s' % (host, video_id), video_id)
72
73 title = self._og_search_title(webpage)
74 description = self._html_search_regex(
75 r'<(p|span)[^>]+itemprop="description"[^>]*>(?P<description>[^<]+)</\1>',
76 webpage, 'description', fatal=False, group='description')
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(
81 r'<time[^>]+\bdatetime="([^"]+)"[^>]+itemprop="uploadDate"',
82 webpage, 'upload date', fatal=False))
83
84 uploader = self._html_search_regex(
85 r'class="video-uploaded"[^>]*>\s*<a href="/jsecUser/movies/[^"]+"[^>]*>([^<]+)</a>',
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(
92 r'<a[^>]+href="#tab-comments"[^>]*>(\d+) комментари',
93 webpage, 'comment count', default=None))
94
95 # Sets some cookies
96 self._download_xml(
97 r'http://%s/video/xml/%s?mode=init' % (host, video_id),
98 video_id, 'Downloading init XML')
99
100 video_xml = self._download_xml(
101 'http://%s/video/xml/%s?mode=play' % (host, video_id),
102 video_id, 'Downloading video XML')
103
104 video = xpath_element(video_xml, './/video', 'video', fatal=True)
105
106 formats = [{
107 'url': xpath_attr(video, '', 'url', 'video URL', fatal=True),
108 }]
109
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
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 }