Skip to content

Commit 4e60a60

Browse files
aaron-tandirkf
authored and
GitHub Actions
committed
[caffeine.tv] Add new extractor (#32514)
* Add CaffeineTVIE info extractor to support site caffeine.tv --------- Co-authored-by: dirkf <[email protected]>
1 parent 6f63e71 commit 4e60a60

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

youtube_dl/extractor/caffeine.py

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# coding: utf-8
2+
from __future__ import unicode_literals
3+
4+
from .common import InfoExtractor
5+
from ..utils import (
6+
determine_ext,
7+
int_or_none,
8+
merge_dicts,
9+
parse_iso8601,
10+
T,
11+
traverse_obj,
12+
txt_or_none,
13+
urljoin,
14+
)
15+
16+
17+
class CaffeineTVIE(InfoExtractor):
18+
_VALID_URL = r'https?://(?:www\.)?caffeine\.tv/[^/]+/video/(?P<id>[0-9a-f-]+)'
19+
_TESTS = [{
20+
'url': 'https://www.caffeine.tv/TsuSurf/video/cffc0a00-e73f-11ec-8080-80017d29f26e',
21+
'info_dict': {
22+
'id': 'cffc0a00-e73f-11ec-8080-80017d29f26e',
23+
'ext': 'mp4',
24+
'title': 'GOOOOD MORNINNNNN #highlights',
25+
'timestamp': 1654702180,
26+
'upload_date': '20220608',
27+
'uploader': 'TsuSurf',
28+
'duration': 3145,
29+
'age_limit': 17,
30+
},
31+
'params': {
32+
'format': 'bestvideo',
33+
},
34+
}]
35+
36+
def _real_extract(self, url):
37+
video_id = self._match_id(url)
38+
json_data = self._download_json(
39+
'https://api.caffeine.tv/social/public/activity/' + video_id,
40+
video_id)
41+
broadcast_info = traverse_obj(json_data, ('broadcast_info', T(dict))) or {}
42+
title = broadcast_info['broadcast_title']
43+
video_url = broadcast_info['video_url']
44+
45+
ext = determine_ext(video_url)
46+
if ext == 'm3u8':
47+
formats = self._extract_m3u8_formats(
48+
video_url, video_id, 'mp4', entry_protocol='m3u8',
49+
fatal=False)
50+
else:
51+
formats = [{'url': video_url}]
52+
self._sort_formats(formats)
53+
54+
return merge_dicts({
55+
'id': video_id,
56+
'title': title,
57+
'formats': formats,
58+
}, traverse_obj(json_data, {
59+
'uploader': ((None, 'user'), 'username'),
60+
}, get_all=False), traverse_obj(json_data, {
61+
'like_count': ('like_count', T(int_or_none)),
62+
'view_count': ('view_count', T(int_or_none)),
63+
'comment_count': ('comment_count', T(int_or_none)),
64+
'tags': ('tags', Ellipsis, T(txt_or_none)),
65+
'is_live': 'is_live',
66+
'uploader': ('user', 'name'),
67+
}), traverse_obj(broadcast_info, {
68+
'duration': ('content_duration', T(int_or_none)),
69+
'timestamp': ('broadcast_start_time', T(parse_iso8601)),
70+
'thumbnail': ('preview_image_path', T(lambda u: urljoin(url, u))),
71+
'age_limit': ('content_rating', T(lambda r: r and {
72+
# assume Apple Store ratings [1]
73+
# 1. https://en.wikipedia.org/wiki/Mobile_software_content_rating_system
74+
'FOUR_PLUS': 0,
75+
'NINE_PLUS': 9,
76+
'TWELVE_PLUS': 12,
77+
'SEVENTEEN_PLUS': 17,
78+
}.get(r, 17))),
79+
}))

youtube_dl/extractor/extractors.py

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
from .buzzfeed import BuzzFeedIE
160160
from .byutv import BYUtvIE
161161
from .c56 import C56IE
162+
from .caffeine import CaffeineTVIE
162163
from .callin import CallinIE
163164
from .camdemy import (
164165
CamdemyIE,

0 commit comments

Comments
 (0)