]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/camtube.py
debian/copyright: use spaces rather than tabs to start continuation lines.
[youtubedl] / 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 'age_limit': 18
24 },
25 'params': {
26 'skip_download': True,
27 },
28 }]
29
30 _API_BASE = 'https://api.camtube.co'
31
32 def _real_extract(self, url):
33 display_id = self._match_id(url)
34
35 token = self._download_json(
36 '%s/rpc/session/new' % self._API_BASE, display_id,
37 'Downloading session token')['token']
38
39 self._set_cookie('api.camtube.co', 'session', token)
40
41 video = self._download_json(
42 '%s/recordings/%s' % (self._API_BASE, display_id), display_id,
43 headers={'Referer': url})
44
45 video_id = video['uuid']
46 timestamp = unified_timestamp(video.get('createdAt'))
47 duration = int_or_none(video.get('duration'))
48 view_count = int_or_none(video.get('viewCount'))
49 like_count = int_or_none(video.get('likeCount'))
50 creator = video.get('stageName')
51
52 formats = [{
53 'url': '%s/recordings/%s/manifest.m3u8'
54 % (self._API_BASE, video_id),
55 'format_id': 'hls',
56 'ext': 'mp4',
57 'protocol': 'm3u8_native',
58 }]
59
60 return {
61 'id': video_id,
62 'display_id': display_id,
63 'title': display_id,
64 'timestamp': timestamp,
65 'duration': duration,
66 'view_count': view_count,
67 'like_count': like_count,
68 'creator': creator,
69 'formats': formats,
70 'age_limit': 18
71 }