diff options
author | garret1317 <garret@airmail.cc> | 2025-05-17 22:20:20 +0100 |
---|---|---|
committer | garret1317 <garret@airmail.cc> | 2025-05-17 22:21:01 +0100 |
commit | c028c876287e7dbbd3fe7e1350f36c03d84b40f5 (patch) | |
tree | 176739a8027b9eb3b74c6a27f77f8de4253ec51c /yt_dlp_plugins/extractor/radiko_hacks.py | |
parent | b879d27a7b4fa15ecb41483c25f762eb5d4cb6fa (diff) | |
download | yt-dlp-rajiko-c028c876287e7dbbd3fe7e1350f36c03d84b40f5.tar.gz yt-dlp-rajiko-c028c876287e7dbbd3fe7e1350f36c03d84b40f5.tar.bz2 yt-dlp-rajiko-c028c876287e7dbbd3fe7e1350f36c03d84b40f5.zip |
add quick-downloading support for as-live formats
closes #24
Diffstat (limited to 'yt_dlp_plugins/extractor/radiko_hacks.py')
-rw-r--r-- | yt_dlp_plugins/extractor/radiko_hacks.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/yt_dlp_plugins/extractor/radiko_hacks.py b/yt_dlp_plugins/extractor/radiko_hacks.py new file mode 100644 index 0000000..7b20654 --- /dev/null +++ b/yt_dlp_plugins/extractor/radiko_hacks.py @@ -0,0 +1,41 @@ +import datetime + +from yt_dlp.extractor.common import InfoExtractor +from yt_dlp.utils import ( + join_nonempty, + update_url_query, + traverse_obj, +) + +# "hacks" as in great jank/schizo shit that works anyway + +def _generate_as_live_chunks(playlist_url, start_at, end_at): + chunks = [] + chunk_length = 300 # max the api allows + + duration = int(end_at.timestamp() - start_at.timestamp()) + cursor = 0 + while cursor < duration: + chunk_length = min(chunk_length, duration - cursor) + chunk_start = start_at + datetime.timedelta(seconds=cursor) + chunk_url = update_url_query(playlist_url, { + "seek": chunk_start.timestring(), + "l": chunk_length, + }) + chunks.append(chunk_url) + cursor += chunk_length + + return chunks + +def _playlist_from_chunks(self, chunks, src_id, headers={}): + playlist = "" + for i, chunk in enumerate(chunks): + i +=1 # for more friendly cli output, it gets reset each loop so it shouldnt effect anything + chunk_id = join_nonempty(src_id, i) + base_format = self._extract_m3u8_formats( + chunk, chunk_id, fatal=False, headers=headers, + note=f"Preparing {src_id} chunk {i}" + ) + m3u8_url = traverse_obj(base_format, (..., "url",), get_all=False) + playlist += self._download_webpage(m3u8_url, chunk_id, note=f"Getting {src_id} chunk {i} fragments") + return playlist |