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