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