[ie/soundcloud] Various fixes (#11820)
[yt-dlp.git] / yt_dlp / extractor / godresource.py
blob35cc30cd8db4660de620b53cd4d67f8ec371bb25
1 from .common import InfoExtractor
2 from ..utils import (
3 ExtractorError,
4 determine_ext,
5 str_or_none,
6 unified_timestamp,
7 url_or_none,
9 from ..utils.traversal import traverse_obj
12 class GodResourceIE(InfoExtractor):
13 _VALID_URL = r'https?://new\.godresource\.com/video/(?P<id>\w+)'
14 _TESTS = [{
15 # hls stream
16 'url': 'https://new.godresource.com/video/A01mTKjyf6w',
17 'info_dict': {
18 'id': 'A01mTKjyf6w',
19 'ext': 'mp4',
20 'view_count': int,
21 'timestamp': 1710978666,
22 'channel_id': '5',
23 'thumbnail': 'https://cdn-02.godresource.com/e42968ac-9e8b-4231-ab86-f4f9d775841f/thumbnail.jpg',
24 'channel': 'Stedfast Baptist Church',
25 'upload_date': '20240320',
26 'title': 'GodResource video #A01mTKjyf6w',
28 }, {
29 # mp4 link
30 'url': 'https://new.godresource.com/video/01DXmBbQv_X',
31 'md5': '0e8f72aa89a106b9d5c011ba6f8717b7',
32 'info_dict': {
33 'id': '01DXmBbQv_X',
34 'ext': 'mp4',
35 'channel_id': '12',
36 'view_count': int,
37 'timestamp': 1687996800,
38 'thumbnail': 'https://cdn-02.godresource.com/sodomitedeception/thumbnail.jpg',
39 'channel': 'Documentaries',
40 'title': 'The Sodomite Deception',
41 'upload_date': '20230629',
45 def _real_extract(self, url):
46 display_id = self._match_id(url)
48 api_data = self._download_json(
49 f'https://api.godresource.com/api/Streams/{display_id}', display_id)
51 video_url = api_data['streamUrl']
52 is_live = api_data.get('isLive') or False
53 if (ext := determine_ext(video_url)) == 'm3u8':
54 formats, subtitles = self._extract_m3u8_formats_and_subtitles(
55 video_url, display_id, live=is_live)
56 elif ext == 'mp4':
57 formats, subtitles = [{
58 'url': video_url,
59 'ext': ext,
60 }], {}
61 else:
62 raise ExtractorError(f'Unexpected video format {ext}')
64 return {
65 'id': display_id,
66 'formats': formats,
67 'subtitles': subtitles,
68 'title': '',
69 'is_live': is_live,
70 **traverse_obj(api_data, {
71 'title': ('title', {str}),
72 'thumbnail': ('thumbnail', {url_or_none}),
73 'view_count': ('views', {int}),
74 'channel': ('channelName', {str}),
75 'channel_id': ('channelId', {str_or_none}),
76 'timestamp': ('streamDateCreated', {unified_timestamp}),
77 'modified_timestamp': ('streamDataModified', {unified_timestamp}),
78 }),