From b340f92f293f7847c57b1a8e9465e49e5f99c7d7 Mon Sep 17 00:00:00 2001 From: yiannisha Date: Sat, 30 Oct 2021 15:58:09 +0300 Subject: [PATCH] Added prefixes in case more than two songs have the same name --- zspotify/track.py | 7 +++++-- zspotify/utils.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/zspotify/track.py b/zspotify/track.py index 0322f098..27aac958 100644 --- a/zspotify/track.py +++ b/zspotify/track.py @@ -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: diff --git a/zspotify/utils.py b/zspotify/utils.py index e838bbb1..5f9f5c25 100644 --- a/zspotify/utils.py +++ b/zspotify/utils.py @@ -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 = []