Can now install different songs with the same name

So basically now in each directory created by zspotify
a .song_ids file will be created and appended to every
a song is installed in that directory.

Now, instead of checking if a file exists by name we're
checking with song id.
This commit is contained in:
yiannisha
2021-10-30 15:35:01 +03:00
parent 371de63d21
commit 9f6a40c900
2 changed files with 44 additions and 3 deletions

View File

@@ -11,7 +11,8 @@ from tqdm import tqdm
from const import TRACKS, ALBUM, NAME, ITEMS, DISC_NUMBER, TRACK_NUMBER, IS_PLAYABLE, ARTISTS, IMAGES, URL, \
RELEASE_DATE, ID, TRACKS_URL, SAVED_TRACKS_URL, SPLIT_ALBUM_DISCS, ROOT_PATH, DOWNLOAD_FORMAT, CHUNK_SIZE, \
SKIP_EXISTING_FILES, ANTI_BAN_WAIT_TIME, OVERRIDE_AUTO_WAIT, BITRATE, CODEC_MAP, EXT_MAP, DOWNLOAD_REAL_TIME
from utils import sanitize_data, set_audio_tags, set_music_thumbnail, create_download_directory
from utils import sanitize_data, set_audio_tags, set_music_thumbnail, create_download_directory, \
get_directory_song_ids, add_to_directory_song_ids
from zspotify import ZSpotify
@@ -74,6 +75,16 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
filename = os.path.join(
download_directory, f'{song_name}.{EXT_MAP.get(ZSpotify.get_config(DOWNLOAD_FORMAT))}')
check_name = os.path.isfile(filename) and os.path.getsize(filename)
check_id = scraped_song_id in get_directory_song_ids(download_directory)
# 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
filename = os.path.join(
download_directory, f'{song_name}_1.{EXT_MAP.get(ZSpotify.get_config(DOWNLOAD_FORMAT))}')
except Exception as e:
print('### SKIPPING SONG - FAILED TO QUERY METADATA ###')
print(e)
@@ -83,7 +94,7 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
print('\n### SKIPPING:', song_name,
'(SONG IS UNAVAILABLE) ###')
else:
if os.path.isfile(filename) and os.path.getsize(filename) and ZSpotify.get_config(SKIP_EXISTING_FILES):
if check_id and ZSpotify.get_config(SKIP_EXISTING_FILES):
print('\n### SKIPPING:', song_name,
'(SONG ALREADY EXISTS) ###')
else:
@@ -119,6 +130,9 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
release_year, disc_number, track_number)
set_music_thumbnail(filename, image_url)
# add song id to download directory's .song_ids file
add_to_directory_song_ids(download_directory, scraped_song_id)
if not ZSpotify.get_config(OVERRIDE_AUTO_WAIT):
time.sleep(ZSpotify.get_config(ANTI_BAN_WAIT_TIME))
except Exception as e: