[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / cloudycdn.py
blob6e757d79ee2e05e4e1f7f0cb702d16a9f28143aa
1 import re
3 from .common import InfoExtractor
4 from ..utils import (
5 int_or_none,
6 parse_iso8601,
7 url_or_none,
8 urlencode_postdata,
10 from ..utils.traversal import traverse_obj
13 class CloudyCDNIE(InfoExtractor):
14 _VALID_URL = r'(?:https?:)?//embed\.cloudycdn\.services/(?P<site_id>[^/?#]+)/media/(?P<id>[\w-]+)'
15 _EMBED_REGEX = [rf'<iframe[^>]+\bsrc=[\'"](?P<url>{_VALID_URL})']
16 _TESTS = [{
17 'url': 'https://embed.cloudycdn.services/ltv/media/46k_d23-6000-105?',
18 'md5': '64f72a360ca530d5ed89c77646c9eee5',
19 'info_dict': {
20 'id': '46k_d23-6000-105',
21 'ext': 'mp4',
22 'timestamp': 1700589151,
23 'duration': 1442,
24 'upload_date': '20231121',
25 'title': 'D23-6000-105_cetstud',
26 'thumbnail': 'https://store.cloudycdn.services/tmsp00060/assets/media/660858/placeholder1700589200.jpg',
28 }, {
29 'url': 'https://embed.cloudycdn.services/izm/media/26e_lv-8-5-1',
30 'md5': '798828a479151e2444d8dcfbec76e482',
31 'info_dict': {
32 'id': '26e_lv-8-5-1',
33 'ext': 'mp4',
34 'title': 'LV-8-5-1',
35 'timestamp': 1669767167,
36 'thumbnail': 'https://store.cloudycdn.services/tmsp00120/assets/media/488306/placeholder1679423604.jpg',
37 'duration': 1205,
38 'upload_date': '20221130',
40 }, {
41 # Video-only m3u8 formats need manual fixup
42 'url': 'https://embed.cloudycdn.services/ltv/media/08j_d24-6000-074',
43 'md5': 'fc472e40f6e6238446509be411c920e2',
44 'info_dict': {
45 'id': '08j_d24-6000-074',
46 'ext': 'mp4',
47 'upload_date': '20240620',
48 'duration': 1673,
49 'title': 'D24-6000-074-cetstud',
50 'timestamp': 1718902233,
51 'thumbnail': 'https://store.cloudycdn.services/tmsp00060/assets/media/788392/placeholder1718903938.jpg',
53 'params': {'format': 'bv'},
55 _WEBPAGE_TESTS = [{
56 'url': 'https://www.tavaklase.lv/video/es-esmu-mina-um-2/',
57 'md5': '63074e8e6c84ac2a01f2fb8bf03b8f43',
58 'info_dict': {
59 'id': 'cqd_lib-2',
60 'ext': 'mp4',
61 'upload_date': '20230223',
62 'duration': 629,
63 'thumbnail': 'https://store.cloudycdn.services/tmsp00120/assets/media/518407/placeholder1678748124.jpg',
64 'timestamp': 1677181513,
65 'title': 'LIB-2',
69 def _real_extract(self, url):
70 site_id, video_id = self._match_valid_url(url).group('site_id', 'id')
72 data = self._download_json(
73 f'https://player.cloudycdn.services/player/{site_id}/media/{video_id}/',
74 video_id, data=urlencode_postdata({
75 'version': '6.4.0',
76 'referer': url,
77 }))
79 formats, subtitles = [], {}
80 for m3u8_url in traverse_obj(data, ('source', 'sources', ..., 'src', {url_or_none})):
81 fmts, subs = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id, fatal=False)
82 for fmt in fmts:
83 if re.search(r'chunklist_b\d+_vo_', fmt['url']):
84 fmt['acodec'] = 'none'
85 formats.extend(fmts)
86 self._merge_subtitles(subs, target=subtitles)
88 return {
89 'id': video_id,
90 'formats': formats,
91 'subtitles': subtitles,
92 **traverse_obj(data, {
93 'title': ('name', {str}),
94 'duration': ('duration', {int_or_none}),
95 'timestamp': ('upload_date', {parse_iso8601}),
96 'thumbnail': ('source', 'poster', {url_or_none}),
97 }),