1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Prevent naming collisions when zipping albums

This commit is contained in:
Alban Féron 2022-01-29 17:15:03 +01:00
parent 62bad3b987
commit f387cce9ca
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165

View File

@ -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: