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