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}')