feat(dl): warn when the temp volume cannot hold the HLS tracks of a title

This commit is contained in:
imSp4rky
2026-11-28 15:54:41 -07:00
parent 74856d2ddb
commit a80afc4b7e
8 changed files with 264 additions and 41 deletions
+4 -2
View File
@@ -693,6 +693,10 @@ class HLS:
del content[track.sample_slice(starts, window=config.sample)]
unwanted_segments += content
wanted_segments = [seg for seg in master.segments if seg not in unwanted_segments]
if ctx.on_segments:
ctx.on_segments(track, wanted_segments)
# Get session DRM as fallback but prefer media playlist keys for accurate KID matching
if track.drm:
session_drm = track.get_drm_for_cdm(cdm)
@@ -753,8 +757,6 @@ class HLS:
# Downloaded segment files are named by post-filter index; map that back to the wanted
# segment so the IV uses the absolute media sequence number, not the download index.
wanted_segments = [seg for seg in master.segments if seg not in unwanted_segments]
single_init = HLS.single_init_no_rotation(wanted_segments, initial_drm_key, cdm, track.drm_preference)
use_segment_decrypt = (
isinstance(session_drm, (Widevine, PlayReady)) and can_use(session_drm, config.decryption) and single_init
+2
View File
@@ -244,6 +244,7 @@ class Subtitle(Track):
proxy_download: str | None = None,
adaptive_workers: bool = False,
download_processes: int = 1,
on_segments: Callable[[Track, list[Any]], None] | None = None,
) -> None:
super().download(
session,
@@ -255,6 +256,7 @@ class Subtitle(Track):
proxy_download=proxy_download,
adaptive_workers=adaptive_workers,
download_processes=download_processes,
on_segments=on_segments,
)
if not self.path:
return
+4
View File
@@ -400,6 +400,8 @@ class DownloadContext:
download_processes: int = 1
license_widevine: Callable | None = None
cdm: object | None = None
on_segments: Callable[["Track", list[Any]], None] | None = None
"""Called by the HLS step with a track and its wanted media segments, before they download."""
def ensure_session(self) -> AnySession:
"""Return the HTTP session, or a new ``Session`` if none was set."""
@@ -727,6 +729,7 @@ class Track:
proxy_download: str | None = None,
adaptive_workers: bool = False,
download_processes: int = 1,
on_segments: Callable[["Track", list[Any]], None] | None = None,
) -> None:
"""Download and optionally Decrypt this Track.
@@ -826,6 +829,7 @@ class Track:
download_processes=download_processes,
license_widevine=prepare_drm,
cdm=cdm,
on_segments=on_segments,
)
if self.descriptor in manifest_parsers:
manifest_parsers[self.descriptor].download_track(track=self, ctx=ctx)
+17 -2
View File
@@ -8,7 +8,7 @@ from collections import OrderedDict, defaultdict
from collections.abc import Callable, Hashable, Sequence
from concurrent.futures import ThreadPoolExecutor
from dataclasses import dataclass
from typing import TYPE_CHECKING, cast
from typing import TYPE_CHECKING, Any, cast
from urllib.parse import urljoin
from requests import Session
@@ -301,6 +301,17 @@ def manifest_seconds(track: Track) -> float | None:
return None
def playlist_size(bitrate: int | None, segments: list[Any]) -> float:
"""The bytes of HLS media segments from their playlist; it sends no request.
It is the sum of the EXT-X-BYTERANGE lengths when each segment has one, else the bitrate times the EXTINF time.
"""
parsed = hls_segments(segments)
if parsed and all(segment.known_size is not None for segment in parsed):
return float(sum(segment.known_size or 0 for segment in parsed))
return (bitrate or 0) * sum(segment.duration for segment in parsed) / 8
def extract_dash(track: Track, session: Session | RnetSession) -> list[Segment]:
from unshackle.core.manifests import DASH
@@ -348,9 +359,13 @@ def extract_hls(track: Track, session: Session | RnetSession) -> list[Segment]:
playlist_url = track.url if isinstance(track.url, str) else track.url[0]
res = session.get(playlist_url, timeout=PROBE_TIMEOUT)
playlist = m3u8.loads(utf8_text(res), uri=playlist_url)
return hls_segments(playlist.segments)
def hls_segments(segments: list[Any]) -> list[Segment]:
"""Parsed HLS media segments as Segments, each with its EXT-X-BYTERANGE length when it has one."""
out: list[Segment] = []
for segment in playlist.segments:
for segment in segments:
url = urljoin(segment.base_uri or "", segment.uri)
byte_range = segment.byterange # "<length>[@<offset>]"
known_size: int | None = None