perf(dl): overlap hybrid builds with muxing, tag in the mux thread, preload DRM in parallel

Submit standalone mux tasks largest-first as soon as they are enqueued and build hybrid tracks while they run, each muxed from its own pool slot when ready; run mkvpropedit inside the mux thread instead of a serial pass at the end; load per-track DRM from a thread pool; decode m3u8 playlists as UTF-8 instead of letting requests run chardet over them.
This commit is contained in:
imSp4rky
2026-08-20 12:41:04 -06:00
parent 537a1dc973
commit 3312c218df
3 changed files with 151 additions and 120 deletions
+6 -1
View File
@@ -79,6 +79,7 @@ class HLS:
if isinstance(res, requests.Response):
if not res.ok:
raise requests.ConnectionError("Failed to request the M3U(8) document.", response=res)
res.encoding = res.encoding or "utf-8"
content = res.text
elif isinstance(res, RnetResponse):
if not res.ok:
@@ -349,7 +350,9 @@ class HLS:
session = Session()
res = session.get(variant_url)
variant = m3u8.loads(res.text if hasattr(res, "text") else res.text, uri=variant_url)
if isinstance(res, requests.Response):
res.encoding = res.encoding or "utf-8"
variant = m3u8.loads(res.text, uri=variant_url)
if not variant.segments:
return None
@@ -542,6 +545,8 @@ class HLS:
if not response.ok:
log.error(f"Failed to request the invariant M3U8 playlist: {response.status_code}")
sys.exit(1)
if isinstance(response, requests.Response):
response.encoding = response.encoding or "utf-8"
playlist_text = response.text
else:
raise TypeError(f"Expected response to be a requests.Response or rnet.Response, not {type(response)}")
+3 -1
View File
@@ -15,7 +15,7 @@ from uuid import UUID
from zlib import crc32
from langcodes import Language
from requests import Session
from requests import Response, Session
from requests.adapters import HTTPAdapter, Retry
from unshackle.core import binaries
@@ -805,6 +805,8 @@ class Track:
session = getattr(self, "session", None) or Session()
response = session.get(self.url)
if isinstance(response, Response):
response.encoding = response.encoding or "utf-8"
playlist = m3u8.loads(response.text, self.url)
drm_list = []