From ba801739fecf65219fa138730ed23f13ac716c0e Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Fri, 8 Mar 2024 16:15:50 +0000 Subject: [PATCH] fix(aria2c): Support aria2(c) 1.37.0 by handling upstream regression From aria2c's changelog (2007-09-02): ``` Now *.aria2 contorol file is first saved to *.aria2__temp and if it is successful, then renamed to *.aria2. This prevents *.aria2 file from being truncated or corrupted when file system becomes out of space. ``` It seems something went wrong in 1.37.0 resulting in these files sometimes not being renamed back to `.aria2` and then being left there for good. The fix for devine would be to simply detect `.aria2__temp` and delete them once all segments finish downloading. My only worry here is the root cause for why it has failed to rename. Did the download actually complete without error? According to aria2c's RPC, no errors occurred. There's no way to add support for Aria2(c) 1.37.0 without this sort of change as the files to seem to download correctly regardless of the file not being renamed and then deleted. Fixes #71 --- devine/core/manifests/dash.py | 4 ++++ devine/core/manifests/hls.py | 4 ++++ devine/core/tracks/track.py | 3 +++ 3 files changed, 11 insertions(+) diff --git a/devine/core/manifests/dash.py b/devine/core/manifests/dash.py index d7f943b..6580e14 100644 --- a/devine/core/manifests/dash.py +++ b/devine/core/manifests/dash.py @@ -483,6 +483,10 @@ class DASH: status_update["downloaded"] = f"DASH {downloaded}" progress(**status_update) + # see https://github.com/devine-dl/devine/issues/71 + for control_file in save_dir.glob("*.aria2__temp"): + control_file.unlink() + segments_to_merge = sorted(save_dir.iterdir()) progress(downloaded="Merging", completed=0, total=len(segments_to_merge)) diff --git a/devine/core/manifests/hls.py b/devine/core/manifests/hls.py index 258e8aa..7f47e39 100644 --- a/devine/core/manifests/hls.py +++ b/devine/core/manifests/hls.py @@ -291,6 +291,10 @@ class HLS: status_update["downloaded"] = f"HLS {downloaded}" progress(**status_update) + # see https://github.com/devine-dl/devine/issues/71 + for control_file in segment_save_dir.glob("*.aria2__temp"): + control_file.unlink() + progress(total=total_segments, completed=0, downloaded="Merging") name_len = len(str(total_segments)) diff --git a/devine/core/tracks/track.py b/devine/core/tracks/track.py index 0c75c22..219cce6 100644 --- a/devine/core/tracks/track.py +++ b/devine/core/tracks/track.py @@ -225,6 +225,9 @@ class Track: if not file_downloaded: progress(**status_update) + # see https://github.com/devine-dl/devine/issues/71 + save_path.with_suffix(f"{save_path.suffix}.aria2__temp").unlink(missing_ok=True) + self.path = save_path if callable(self.OnDownloaded): self.OnDownloaded()