]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/twentyfourvideo.py
Prepare to upload.
[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'https?://(?P<host>(?:www\.)?24video\.(?:net|me|xxx|sexy?|tube|adult))/(?:video/(?:view|xml)/|player/new24_play\.swf\?id=)(?P<id>\d+)'
18
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': 'Как смотрели порно в каменном веке.',
27 'thumbnail': r're:^https?://.*\.jpg$',
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,
35 },
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,
42 }, {
43 'url': 'http://www.24video.tube/video/view/2363750',
44 'only_matching': True,
45 }]
46
47 def _real_extract(self, url):
48 mobj = re.match(self._VALID_URL, url)
49 video_id = mobj.group('id')
50 host = mobj.group('host')
51
52 webpage = self._download_webpage(
53 'http://%s/video/view/%s' % (host, video_id), video_id)
54
55 title = self._og_search_title(webpage)
56 description = self._html_search_regex(
57 r'<(p|span)[^>]+itemprop="description"[^>]*>(?P<description>[^<]+)</\1>',
58 webpage, 'description', fatal=False, group='description')
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(
63 r'<time[^>]+\bdatetime="([^"]+)"[^>]+itemprop="uploadDate"',
64 webpage, 'upload date', fatal=False))
65
66 uploader = self._html_search_regex(
67 r'class="video-uploaded"[^>]*>\s*<a href="/jsecUser/movies/[^"]+"[^>]*>([^<]+)</a>',
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(
74 r'<a[^>]+href="#tab-comments"[^>]*>(\d+) комментари',
75 webpage, 'comment count', default=None))
76
77 # Sets some cookies
78 self._download_xml(
79 r'http://%s/video/xml/%s?mode=init' % (host, video_id),
80 video_id, 'Downloading init XML')
81
82 video_xml = self._download_xml(
83 'http://%s/video/xml/%s?mode=play' % (host, video_id),
84 video_id, 'Downloading video XML')
85
86 video = xpath_element(video_xml, './/video', 'video', fatal=True)
87
88 formats = [{
89 'url': xpath_attr(video, '', 'url', 'video URL', fatal=True),
90 }]
91
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
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 }