optimize DASH probing and segment download paths

- Switch bruteforce probes from GET to HEAD to avoid downloading
  full segment bodies (only the status code is needed)
- Cap bruteforce concurrency with a semaphore (default 100) instead of issuing one task per tick, and cancel leftover tasks on early exit
- Reuse a single aiohttp session / event loop for the manifest mode's AVC/HEVC/audio bruteforces to keep TCP connections alive
- Hoist the per-request segment headers into a module-level constant
- Use a set for the already-downloaded resume check in save_segments
- Replace read()-into-memory copies with shutil.copyfileobj in   merge_segments and decrypt
This commit is contained in:
√(noham)²
2026-08-13 17:40:06 +02:00
parent a57f0a74a1
commit ae5035c6a8
4 changed files with 114 additions and 91 deletions

View File

@@ -39,7 +39,7 @@ def merge_segments(input_folder: str, track_id: str, output_file: str):
with open(output_file, "wb") as outfile:
for fname in segment_files:
with open(f"{segment_folder}/{fname}", "rb") as infile:
outfile.write(infile.read())
shutil.copyfileobj(infile, outfile)
logger.info("Merged segments into %s", output_file)
@@ -104,7 +104,7 @@ def decrypt(segment_dir, init_path, output_file, key):
with open(chunk_merged, "wb") as outfile:
for fname in chunk_files:
with open(os.path.join(segment_dir, fname), "rb") as infile:
outfile.write(infile.read())
shutil.copyfileobj(infile, outfile)
logger.debug("Decrypting chunk %d", chunk_num)
result = subprocess.run(