diff options
| author | garret1317 <garret@airmail.cc> | 2025-11-06 23:37:22 +0000 |
|---|---|---|
| committer | garret1317 <garret@airmail.cc> | 2025-11-07 00:18:22 +0000 |
| commit | ca6531cc800c209533cd9ebea9544e892c2c12e0 (patch) | |
| tree | 1a105dbf221308bd34d766e19e32a198d4fa1302 /yt_dlp_plugins/extractor | |
| parent | 92918e2ba1e5c745aff2dcf046c82a3c1f9529af (diff) | |
| download | yt-dlp-rajiko-ca6531cc800c209533cd9ebea9544e892c2c12e0.tar.gz yt-dlp-rajiko-ca6531cc800c209533cd9ebea9544e892c2c12e0.tar.bz2 yt-dlp-rajiko-ca6531cc800c209533cd9ebea9544e892c2c12e0.zip | |
Get the first chunk in advance
so that the returned `url` "works" in mpv etc
i can download the first one as part of the normal self._extract_m3u8_formats, and pass the url as the first chunk of my chunking set up
then the chunks stuff still works, and i can return an url that will play in mpv
...except that it will be 5 minutes ahead because it's a "live"stream
oh well its better than nothing lmao
Diffstat (limited to 'yt_dlp_plugins/extractor')
| -rw-r--r-- | yt_dlp_plugins/extractor/radiko.py | 19 | ||||
| -rw-r--r-- | yt_dlp_plugins/extractor/radiko_hacks.py | 28 |
2 files changed, 29 insertions, 18 deletions
diff --git a/yt_dlp_plugins/extractor/radiko.py b/yt_dlp_plugins/extractor/radiko.py index 2ec363a..dadde05 100644 --- a/yt_dlp_plugins/extractor/radiko.py +++ b/yt_dlp_plugins/extractor/radiko.py @@ -286,6 +286,7 @@ class _RadikoBaseIE(InfoExtractor): "end_at": end_at.timestring(), "to": end_at.timestring(), + "l": 300, }) domain = urllib.parse.urlparse(playlist_url).netloc @@ -308,11 +309,19 @@ class _RadikoBaseIE(InfoExtractor): auth_headers = auth_data["token"] + m3u8_formats = self._extract_m3u8_formats( + playlist_url, station, m3u8_id=domain, fatal=False, headers=auth_headers, + live=delivered_live, preference=preference, entry_protocol=entry_protocol, + note=f"Downloading m3u8 information from {domain}" + ) + if delivered_live and timefree and do_as_live_chunks: + first_chunk = traverse_obj(m3u8_formats, (..., "url",), get_all=False) + def fragments_generator(_): return hacks._generate_as_live_fragments( - self, playlist_url, start_at, end_at, domain, auth_headers + self, playlist_url, start_at, end_at, domain, auth_headers, first_chunk ) m3u8_formats = [{ @@ -324,17 +333,11 @@ class _RadikoBaseIE(InfoExtractor): "vcodec": "none", # fallback to live for ffmpeg etc - "url": playlist_url, + "url": first_chunk, "http_headers": auth_headers, "is_live": "yesn't", }] format_note.append("Chunked") - else: - - m3u8_formats = self._extract_m3u8_formats( - playlist_url, station, m3u8_id=domain, fatal=False, headers=auth_headers, - live=delivered_live, preference=preference, entry_protocol=entry_protocol, - note=f"Downloading m3u8 information from {domain}") for f in m3u8_formats: # ffmpeg sends a Range header which some streams reject. here we disable that (and also some icecast header as well) diff --git a/yt_dlp_plugins/extractor/radiko_hacks.py b/yt_dlp_plugins/extractor/radiko_hacks.py index 418aa70..1d2d1df 100644 --- a/yt_dlp_plugins/extractor/radiko_hacks.py +++ b/yt_dlp_plugins/extractor/radiko_hacks.py @@ -10,7 +10,7 @@ from yt_dlp.utils import ( # "hacks" as in great jank/schizo shit that works anyway -def _generate_as_live_fragments(self, playlist_base_url, start_at, end_at, domain, headers={}): +def _generate_as_live_fragments(self, playlist_base_url, start_at, end_at, domain, headers={}, first_chunk=None): playlist = [] chunk_length = 300 # max the api allows @@ -26,27 +26,35 @@ def _generate_as_live_fragments(self, playlist_base_url, start_at, end_at, domai "l": chunk_length, }) - chunk_fragments, real_chunk_length = _get_chunk_playlist(self, chunk_url, domain, chunk_num, headers) + chunk_fragments, real_chunk_length = _get_chunk_playlist(self, chunk_url, domain, chunk_num, headers, first_chunk) cursor += round(real_chunk_length) chunk_num += 1 + first_chunk = None for frag in chunk_fragments: yield frag -def _get_chunk_playlist(self, chunk_url, src_id, chunk_num, headers={}): +def _get_chunk_playlist(self, chunk_url, src_id, chunk_num, headers={}, first_chunk=None): EXTINF_duration = re.compile(r"^#EXTINF:([\d.]+),", flags=re.MULTILINE) playlist = "" chunk_id = join_nonempty(src_id, chunk_num) - base_format = self._extract_m3u8_formats( - chunk_url, chunk_id, fatal=False, headers=headers, -# note=f"Preparing {src_id} chunk {chunk_num}" - note=False, - errnote=f"Failed to get {src_id} chunk {chunk_num} base format", - ) - m3u8_url = traverse_obj(base_format, (..., "url",), get_all=False) + + if first_chunk: + m3u8_url = first_chunk + else: + self.write_debug(f"Preparing {src_id} chunk {chunk_num}") + base_formats = self._extract_m3u8_formats( + chunk_url, chunk_id, fatal=False, headers=headers, + # note=f"Preparing {src_id} chunk {chunk_num}" + note=False, + errnote=f"Failed to get {src_id} chunk {chunk_num} base format", + ) + m3u8_url = traverse_obj(base_formats, (..., "url",), get_all=False) + + self.write_debug(f"Getting {src_id} chunk {chunk_num} playlist") playlist = self._download_webpage(m3u8_url, chunk_id, note=False, errnote=f"Failed to get {src_id} chunk {chunk_num} playlist") #note=f"Getting {src_id} chunk {chunk_num} fragments") |