Added prefixes in case more than two songs have the same name

This commit is contained in:
yiannisha 2021-10-30 15:58:09 +03:00
parent 857b1d949a
commit b340f92f29
2 changed files with 6 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import os
import re
import time
from typing import Any, Tuple, List
@ -80,9 +81,11 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
# a song with the same name is installed
if not check_id and check_name:
# TODO: count songs with the same name but different id and add prefix based on that
c = len([file for file in os.listdir(download_directory)
if re.search(f'^{song_name}_', file)]) + 1
filename = os.path.join(
download_directory, f'{song_name}_1.{EXT_MAP.get(ZSpotify.get_config(DOWNLOAD_FORMAT))}')
download_directory, f'{song_name}_{c}.{EXT_MAP.get(ZSpotify.get_config(DOWNLOAD_FORMAT))}')
except Exception as e:

View File

@ -27,7 +27,7 @@ def create_download_directory(download_path: str) -> None:
with open(hidden_file_path, 'w', encoding='utf-8') as f:
pass
def get_directory_song_ids(download_path: str) -> list[str]:
def get_directory_song_ids(download_path: str) -> List[str]:
""" Gets song ids of songs in directory """
song_ids = []