From 7498495cd2cf24182c3aaa480fc93c9784874d5c Mon Sep 17 00:00:00 2001 From: BridgeSense <88615188+BridgeSenseDev@users.noreply.github.com> Date: Tue, 12 Mar 2024 00:34:58 +0800 Subject: [PATCH] Update track.py (fix "bad escape") --- zotify/track.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/zotify/track.py b/zotify/track.py index bb2af89b..2de27e7e 100644 --- a/zotify/track.py +++ b/zotify/track.py @@ -187,10 +187,14 @@ def download_track(mode: str, track_id: str, extra_keys=None, disable_progressba # a song with the same name is installed if not check_id and check_name: - c = len([file for file in Path(filedir).iterdir() if re.search(f'^{filename}_', str(file))]) + 1 - - fname = PurePath(PurePath(filename).name).parent - ext = PurePath(PurePath(filename).name).suffix + filename_str = str(PurePath(filename)) + escaped_filename = re.escape(filename_str) + pattern = re.compile(f'^{escaped_filename}_') + + c = len([file for file in Path(filedir).iterdir() if pattern.search(str(file))]) + 1 + + fname = PurePath(filename).stem + ext = PurePath(filename).suffix filename = PurePath(filedir).joinpath(f'{fname}_{c}{ext}')