mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-28 18:21:26 +01:00
Compare commits
No commits in common. "b6668a4ea043da6f14f1175c5c351b013595fa68" and "ca4bd6746a0a71b51be476143ab8b240ec899bdd" have entirely different histories.
b6668a4ea0
...
ca4bd6746a
|
@ -4,12 +4,8 @@ from ..utils import (
|
||||||
clean_html,
|
clean_html,
|
||||||
get_element_by_id,
|
get_element_by_id,
|
||||||
urljoin,
|
urljoin,
|
||||||
js_to_json,
|
|
||||||
traverse_obj,
|
|
||||||
int_or_none,
|
|
||||||
url_or_none,
|
|
||||||
)
|
)
|
||||||
from urllib.parse import parse_qs
|
from ..compat import compat_parse_qs
|
||||||
|
|
||||||
|
|
||||||
class KukuluLiveIE(InfoExtractor):
|
class KukuluLiveIE(InfoExtractor):
|
||||||
|
@ -30,32 +26,39 @@ class KukuluLiveIE(InfoExtractor):
|
||||||
},
|
},
|
||||||
note=f'Downloading {description} quality metadata',
|
note=f'Downloading {description} quality metadata',
|
||||||
errnote=f'Unable to download {description} quality metadata')
|
errnote=f'Unable to download {description} quality metadata')
|
||||||
return parse_qs(qs)
|
return compat_parse_qs(qs)
|
||||||
|
|
||||||
def _add_quality_formats(self, formats, quality_meta):
|
def _add_quality_formats(self, formats, quality_meta):
|
||||||
vcodec = traverse_obj(quality_meta, ('vcodec', 0))
|
vcodec = quality_meta.get('vcodec')[0]
|
||||||
quality = traverse_obj(quality_meta, ('now_quality', 0))
|
quality = quality_meta.get('now_quality')[0]
|
||||||
quality_priority = {
|
quality_priority = {
|
||||||
'high': 3,
|
'high': 3,
|
||||||
'h264': 2,
|
'h264': 2,
|
||||||
'low': 1,
|
'low': 1,
|
||||||
}.get(quality, 0)
|
}
|
||||||
if traverse_obj(quality_meta, ('hlsaddr', 0, {url_or_none})):
|
formats.extend([
|
||||||
formats.append({
|
{
|
||||||
'format_id': quality,
|
'format_id': quality,
|
||||||
'url': quality_meta['hlsaddr'][0],
|
'url': quality_meta.get('hlsaddr')[0],
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'vcodec': vcodec,
|
'vcodec': vcodec,
|
||||||
'quality': quality_priority,
|
'quality': quality_priority[quality],
|
||||||
})
|
},
|
||||||
if traverse_obj(quality_meta, ('hlsaddr_audioonly', 0, {url_or_none})):
|
{
|
||||||
formats.append({
|
'format_id': f'{quality}-rtmp',
|
||||||
|
'url': quality_meta.get('streamaddr')[0],
|
||||||
|
'ext': 'mp4',
|
||||||
|
'vcodec': vcodec,
|
||||||
|
'quality': quality_priority[quality] - 5,
|
||||||
|
},
|
||||||
|
{
|
||||||
'format_id': f'{quality}-audioonly',
|
'format_id': f'{quality}-audioonly',
|
||||||
'url': quality_meta['hlsaddr_audioonly'][0],
|
'url': quality_meta.get('hlsaddr_audioonly')[0],
|
||||||
'ext': 'm4a',
|
'ext': 'aac',
|
||||||
'vcodec': 'none',
|
'vcodec': 'none',
|
||||||
'quality': quality_priority,
|
'quality': quality_priority[quality] - 10,
|
||||||
})
|
},
|
||||||
|
])
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
@ -97,38 +100,26 @@ class KukuluLiveIE(InfoExtractor):
|
||||||
note='Downloading player html',
|
note='Downloading player html',
|
||||||
errnote='Unable to download player html')
|
errnote='Unable to download player html')
|
||||||
|
|
||||||
sources_json = self._search_json(
|
# https://regex101.com/r/3AXpSA/3
|
||||||
r'var\s+fplayer_source\s*=', player_html, 'stream data', video_id,
|
sources = self._search_regex(r'var fplayer_source = ([^;]+)', player_html, 'sources')
|
||||||
contains_pattern=r'\[(?s:.+)\]', transform_source=js_to_json)
|
sources_json = self._parse_json(sources.replace('.mp4",', '.mp4"'), video_id)
|
||||||
|
|
||||||
def _parse_segment(segment, id, title):
|
formats = []
|
||||||
path = segment.get('file')
|
for source in sources_json:
|
||||||
if not path:
|
path = source.get('file')
|
||||||
return None
|
formats.append({
|
||||||
formats = [{
|
|
||||||
'url': urljoin('https://live.erinn.biz', path),
|
'url': urljoin('https://live.erinn.biz', path),
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'protocol': 'm3u8_native',
|
'protocol': 'm3u8_native',
|
||||||
}]
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': id,
|
'id': video_id,
|
||||||
'title': title,
|
'title': title,
|
||||||
'description': description,
|
'description': description,
|
||||||
'timestamp': traverse_obj(segment, ('time_start', {int_or_none})),
|
'timestamp': sources_json[0].get('time_start'),
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
}
|
}
|
||||||
|
|
||||||
is_playlist = len(sources_json) > 1
|
raise ExtractorError('Cannot parse live stream or VOD', expected=True)
|
||||||
if is_playlist:
|
|
||||||
entries = []
|
|
||||||
for i, segment in enumerate(sources_json):
|
|
||||||
entry = _parse_segment(segment, f'{video_id}_{i}', f'{title} (Part {i + 1})')
|
|
||||||
if not entry:
|
|
||||||
continue
|
|
||||||
entries.append(entry)
|
|
||||||
return self.playlist_result(entries, video_id, title, description, multi_video=True)
|
|
||||||
else:
|
|
||||||
return _parse_segment(sources_json[0], video_id, title)
|
|
||||||
|
|
||||||
raise ExtractorError('Could not detect media type')
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user