[youtube] Unescape HTML for series (closes #18641)
[youtube-dl] / youtube_dl / extractor / camtube.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     int_or_none,
7     unified_timestamp,
8 )
9
10
11 class CamTubeIE(InfoExtractor):
12     _VALID_URL = r'https?://(?:(?:www|api)\.)?camtube\.co/recordings?/(?P<id>[^/?#&]+)'
13     _TESTS = [{
14         'url': 'https://camtube.co/recording/minafay-030618-1136-chaturbate-female',
15         'info_dict': {
16             'id': '42ad3956-dd5b-445a-8313-803ea6079fac',
17             'display_id': 'minafay-030618-1136-chaturbate-female',
18             'ext': 'mp4',
19             'title': 'minafay-030618-1136-chaturbate-female',
20             'duration': 1274,
21             'timestamp': 1528018608,
22             'upload_date': '20180603',
23         },
24         'params': {
25             'skip_download': True,
26         },
27     }]
28
29     _API_BASE = 'https://api.camtube.co'
30
31     def _real_extract(self, url):
32         display_id = self._match_id(url)
33
34         token = self._download_json(
35             '%s/rpc/session/new' % self._API_BASE, display_id,
36             'Downloading session token')['token']
37
38         self._set_cookie('api.camtube.co', 'session', token)
39
40         video = self._download_json(
41             '%s/recordings/%s' % (self._API_BASE, display_id), display_id,
42             headers={'Referer': url})
43
44         video_id = video['uuid']
45         timestamp = unified_timestamp(video.get('createdAt'))
46         duration = int_or_none(video.get('duration'))
47         view_count = int_or_none(video.get('viewCount'))
48         like_count = int_or_none(video.get('likeCount'))
49         creator = video.get('stageName')
50
51         formats = [{
52             'url': '%s/recordings/%s/manifest.m3u8'
53                    % (self._API_BASE, video_id),
54             'format_id': 'hls',
55             'ext': 'mp4',
56             'protocol': 'm3u8_native',
57         }]
58
59         return {
60             'id': video_id,
61             'display_id': display_id,
62             'title': display_id,
63             'timestamp': timestamp,
64             'duration': duration,
65             'view_count': view_count,
66             'like_count': like_count,
67             'creator': creator,
68             'formats': formats,
69         }