From a9ff6dc558637452e635f5ba44f5842715b41b2d Mon Sep 17 00:00:00 2001 From: Robert Honz Date: Thu, 14 Nov 2024 15:10:14 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Fixed=20segment=20id=20?= =?UTF-8?q?calculation=20for=20BTS=20tracks.=20Fixes=20#232=20Fixed=20GUI?= =?UTF-8?q?=20crash=20on=20trailing=20/=20leading=20spaces=20in=20search?= =?UTF-8?q?=20terms.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tidal_dl_ng/download.py | 6 ++++-- tidal_dl_ng/gui.py | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tidal_dl_ng/download.py b/tidal_dl_ng/download.py index 46c0beb..11ee8da 100644 --- a/tidal_dl_ng/download.py +++ b/tidal_dl_ng/download.py @@ -218,7 +218,9 @@ class Download: 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(str(path_segment.stem).split("_")[-1]) + filename_stem: str = str(path_segment.stem).split("_")[-1] + # CAUTION: This is a workaround, so BTS (LOW quality) track will work. They usually have only ONE link. + id_segment: int = int(filename_stem) if filename_stem.isdecimal() else 0 error: HTTPError | None = None # Retry download on failed segments, with an exponential delay between retries @@ -342,7 +344,7 @@ class Download: stream_manifest: StreamManifest = media_stream.get_stream_manifest() if stream_manifest.file_extension is VideoExtensions.TS: file_extension = stream_manifest.file_extension - elif AudioExtensions.FLAC in stream_manifest.dash_info.first_url: + elif stream_manifest.dash_info and AudioExtensions.FLAC in stream_manifest.dash_info.first_url: file_extension = AudioExtensions.FLAC else: file_extension = AudioExtensions.M4A diff --git a/tidal_dl_ng/gui.py b/tidal_dl_ng/gui.py index 7aa2150..d85c8a0 100644 --- a/tidal_dl_ng/gui.py +++ b/tidal_dl_ng/gui.py @@ -511,6 +511,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): self._init_dl() def search(self, query: str, types_media: SearchTypes) -> [ResultItem]: + query = query.strip() + # If a direct link was searched for, skip search and create the object from the link directly. if "http" in query: media_type = get_tidal_media_type(query)