Move segment merging from dl to DASH/HLS classes
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
@@ -181,6 +182,7 @@ class HLS:
|
||||
@staticmethod
|
||||
def download_track(
|
||||
track: AnyTrack,
|
||||
save_path: Path,
|
||||
save_dir: Path,
|
||||
stop_event: Event,
|
||||
progress: partial,
|
||||
@@ -342,13 +344,13 @@ class HLS:
|
||||
|
||||
progress(total=len(master.segments))
|
||||
|
||||
finished_threads = 0
|
||||
has_stopped = False
|
||||
has_failed = False
|
||||
download_sizes = []
|
||||
last_speed_refresh = time.time()
|
||||
|
||||
with ThreadPoolExecutor(max_workers=16) as pool:
|
||||
finished_threads = 0
|
||||
has_stopped = False
|
||||
has_failed = False
|
||||
for download in futures.as_completed((
|
||||
pool.submit(
|
||||
download_segment,
|
||||
@@ -396,10 +398,23 @@ class HLS:
|
||||
progress(downloaded=f"HLS {filesize.decimal(download_speed)}/s")
|
||||
last_speed_refresh = now
|
||||
download_sizes.clear()
|
||||
if has_failed:
|
||||
progress(downloaded="[red]FAILED")
|
||||
|
||||
try:
|
||||
if has_stopped:
|
||||
progress(downloaded="[yellow]STOPPED")
|
||||
return
|
||||
if has_failed:
|
||||
progress(downloaded="[red]FAILED")
|
||||
return
|
||||
|
||||
with open(save_path, "wb") as f:
|
||||
for segment_file in sorted(save_dir.iterdir()):
|
||||
f.write(segment_file.read_bytes())
|
||||
segment_file.unlink()
|
||||
|
||||
track.path = save_path
|
||||
finally:
|
||||
shutil.rmtree(save_dir)
|
||||
|
||||
@staticmethod
|
||||
def get_drm(
|
||||
|
||||
Reference in New Issue
Block a user