From f387cce9ca668ab06e2843994323253dd127503c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alban=20F=C3=A9ron?= Date: Sat, 29 Jan 2022 17:15:03 +0100 Subject: [PATCH] Prevent naming collisions when zipping albums --- supysonic/api/media.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/supysonic/api/media.py b/supysonic/api/media.py index 471cb43..e816203 100644 --- a/supysonic/api/media.py +++ b/supysonic/api/media.py @@ -255,9 +255,20 @@ def download_media(): # Add the entire folder tree to the zip z.add_path(rv.path, recurse=True) else: - # Add tracks + cover art to the zip + # Add tracks + cover art to the zip, preventing potential naming collisions + seen = set() for track in rv.tracks: - z.add_path(track.path) + filename = os.path.basename(track.path) + name, ext = os.path.splitext(filename) + index = 0 + while filename in seen: + index += 1 + filename = f"{name} ({index})" + if ext: + filename += ext + + z.add_path(track.path, filename) + seen.add(filename) cover_path = _cover_from_collection(rv, extract=False) if cover_path: