Enable interrupt/resume of MP4 streams

- skipping the processing of an existing target output file
- skipping the download of an existing target stream file
- resume the download of an existing target stream temporary file
  using a HTTP range request
This commit is contained in:
Barbagus 2023-01-25 08:53:25 +01:00
parent 57da060e73
commit f36d45fb5e
2 changed files with 12 additions and 3 deletions

View File

@ -132,6 +132,11 @@ def download_targets(targets, http_session, on_progress):
from .muxing import mux_target
for target in targets:
output_path = f"{target.output}.mkv"
if os.path.isfile(output_path):
print(f"Skipping {output_path!r}")
continue
video_path = target.output + ".video.mp4"
audio_path = target.output + ".audio.mp4"

View File

@ -19,10 +19,14 @@ def download_mp4_media(url, file_name, http_session, on_progress):
temp_file = f"{file_name}.tmp"
with open(temp_file, "w+b") as f:
r = http_session.get(url, timeout=5, stream=True)
with open(temp_file, "ab") as f:
r = http_session.get(
url, timeout=5, stream=True, headers={"Range": f"bytes={f.tell()}-"}
)
r.raise_for_status()
total = int(r.headers["content-length"])
_, total = r.headers["content-range"].split("/")
total = int(total)
for content in r.iter_content(_CHUNK):
f.write(content)