From beea8f1fe75b56ec743b17076d65756bc4e9ec30 Mon Sep 17 00:00:00 2001 From: Robert Honz Date: Tue, 12 Nov 2024 22:36:16 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Fixed=20segment=20order?= =?UTF-8?q?=20after=20download.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tidal_dl_ng/download.py | 6 +++++- tidal_dl_ng/model/downloader.py | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tidal_dl_ng/download.py b/tidal_dl_ng/download.py index 7876368..b1ff2c6 100644 --- a/tidal_dl_ng/download.py +++ b/tidal_dl_ng/download.py @@ -164,6 +164,8 @@ class Download: # mark the whole thing as corrupt. result_segments = False + # Bring list into right order, so segments can be easily merged. + dl_segment_results.sort(key=lambda x: x.id_segment) # TODO: Implement error handling on corrupt segments (also in the following method. reult_merge: bool = self._segments_merge(path_file, dl_segment_results) tmp_path_file_decrypted: pathlib.Path = pathlib.Path("") @@ -205,6 +207,8 @@ class Download: ) -> DownloadSegmentResult: result: bool = False path_segment: pathlib.Path = path_base / url_to_filename(url) + # Calculate the segment ID based on the file name within the URL. + id_segment: int = int(path_segment.stem) try: # Create the request object with stream=True, so the content won't be loaded into memory at once. @@ -228,7 +232,7 @@ class Download: if not progress_to_stdout: self.progress_gui.item.emit(self.progress.tasks[p_task].percentage) - return DownloadSegmentResult(result, url, path_segment) + return DownloadSegmentResult(result=result, url=url, path_segment=path_segment, id_segment=id_segment) def item( self, diff --git a/tidal_dl_ng/model/downloader.py b/tidal_dl_ng/model/downloader.py index b8c5348..52c8e30 100644 --- a/tidal_dl_ng/model/downloader.py +++ b/tidal_dl_ng/model/downloader.py @@ -7,3 +7,4 @@ class DownloadSegmentResult: result: bool url: str path_segment: pathlib.Path + id_segment: int