]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/caffeinetv.py
Update to ytdl-commit-a08f2b7 (#10012)
[yt-dlp.git] / yt_dlp / extractor / caffeinetv.py
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 int_or_none,
5 parse_iso8601,
6 traverse_obj,
7 urljoin,
8 )
9
10
11 class CaffeineTVIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?caffeine\.tv/[^/?#]+/video/(?P<id>[\da-f-]+)'
13 _TESTS = [{
14 'url': 'https://www.caffeine.tv/TsuSurf/video/cffc0a00-e73f-11ec-8080-80017d29f26e',
15 'info_dict': {
16 'id': 'cffc0a00-e73f-11ec-8080-80017d29f26e',
17 'ext': 'mp4',
18 'title': 'GOOOOD MORNINNNNN #highlights',
19 'timestamp': 1654702180,
20 'upload_date': '20220608',
21 'uploader': 'RahJON Wicc',
22 'uploader_id': 'TsuSurf',
23 'duration': 3145,
24 'age_limit': 17,
25 'thumbnail': 'https://www.caffeine.tv/broadcasts/776b6f84-9cd5-42e3-af1d-4a776eeed697/replay/lobby.jpg',
26 'comment_count': int,
27 'view_count': int,
28 'like_count': int,
29 'tags': ['highlights', 'battlerap'],
30 },
31 'params': {
32 'skip_download': 'm3u8',
33 },
34 }]
35
36 def _real_extract(self, url):
37 video_id = self._match_id(url)
38 json_data = self._download_json(
39 f'https://api.caffeine.tv/social/public/activity/{video_id}', video_id)
40 broadcast_info = traverse_obj(json_data, ('broadcast_info', {dict})) or {}
41
42 video_url = broadcast_info['video_url']
43 ext = determine_ext(video_url)
44 if ext == 'm3u8':
45 formats = self._extract_m3u8_formats(video_url, video_id, 'mp4')
46 else:
47 formats = [{'url': video_url}]
48
49 return {
50 'id': video_id,
51 'formats': formats,
52 **traverse_obj(json_data, {
53 'like_count': ('like_count', {int_or_none}),
54 'view_count': ('view_count', {int_or_none}),
55 'comment_count': ('comment_count', {int_or_none}),
56 'tags': ('tags', ..., {str}, {lambda x: x or None}),
57 'uploader': ('user', 'name', {str}),
58 'uploader_id': (((None, 'user'), 'username'), {str}, any),
59 'is_live': ('is_live', {bool}),
60 }),
61 **traverse_obj(broadcast_info, {
62 'title': ('broadcast_title', {str}),
63 'duration': ('content_duration', {int_or_none}),
64 'timestamp': ('broadcast_start_time', {parse_iso8601}),
65 'thumbnail': ('preview_image_path', {lambda x: urljoin(url, x)}),
66 }),
67 'age_limit': {
68 # assume Apple Store ratings: https://en.wikipedia.org/wiki/Mobile_software_content_rating_system
69 'FOUR_PLUS': 0,
70 'NINE_PLUS': 9,
71 'TWELVE_PLUS': 12,
72 'SEVENTEEN_PLUS': 17,
73 }.get(broadcast_info.get('content_rating'), 17),
74 }