[24video] Add support for 24video.site (closes #21193)
[youtube-dl] / 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|site))/(?: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         'url': 'https://www.24video.site/video/view/2640421',
47         'only_matching': True,
48     }]
49
50     def _real_extract(self, url):
51         mobj = re.match(self._VALID_URL, url)
52         video_id = mobj.group('id')
53         host = mobj.group('host')
54
55         webpage = self._download_webpage(
56             'http://%s/video/view/%s' % (host, video_id), video_id)
57
58         title = self._og_search_title(webpage)
59         description = self._html_search_regex(
60             r'<(p|span)[^>]+itemprop="description"[^>]*>(?P<description>[^<]+)</\1>',
61             webpage, 'description', fatal=False, group='description')
62         thumbnail = self._og_search_thumbnail(webpage)
63         duration = int_or_none(self._og_search_property(
64             'duration', webpage, 'duration', fatal=False))
65         timestamp = parse_iso8601(self._search_regex(
66             r'<time[^>]+\bdatetime="([^"]+)"[^>]+itemprop="uploadDate"',
67             webpage, 'upload date', fatal=False))
68
69         uploader = self._html_search_regex(
70             r'class="video-uploaded"[^>]*>\s*<a href="/jsecUser/movies/[^"]+"[^>]*>([^<]+)</a>',
71             webpage, 'uploader', fatal=False)
72
73         view_count = int_or_none(self._html_search_regex(
74             r'<span class="video-views">(\d+) просмотр',
75             webpage, 'view count', fatal=False))
76         comment_count = int_or_none(self._html_search_regex(
77             r'<a[^>]+href="#tab-comments"[^>]*>(\d+) комментари',
78             webpage, 'comment count', default=None))
79
80         # Sets some cookies
81         self._download_xml(
82             r'http://%s/video/xml/%s?mode=init' % (host, video_id),
83             video_id, 'Downloading init XML')
84
85         video_xml = self._download_xml(
86             'http://%s/video/xml/%s?mode=play' % (host, video_id),
87             video_id, 'Downloading video XML')
88
89         video = xpath_element(video_xml, './/video', 'video', fatal=True)
90
91         formats = [{
92             'url': xpath_attr(video, '', 'url', 'video URL', fatal=True),
93         }]
94
95         like_count = int_or_none(video.get('ratingPlus'))
96         dislike_count = int_or_none(video.get('ratingMinus'))
97         age_limit = 18 if video.get('adult') == 'true' else 0
98
99         return {
100             'id': video_id,
101             'title': title,
102             'description': description,
103             'thumbnail': thumbnail,
104             'uploader': uploader,
105             'duration': duration,
106             'timestamp': timestamp,
107             'view_count': view_count,
108             'comment_count': comment_count,
109             'like_count': like_count,
110             'dislike_count': dislike_count,
111             'age_limit': age_limit,
112             'formats': formats,
113         }