Skip to content

Commit 39526f4

Browse files
committed
Reapply "Manually merge (zotify-dev#112)"
This reverts commit c5bef27.
1 parent c5bef27 commit 39526f4

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

zotify/track.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,17 @@ def download_track(mode: str, track_id: str, extra_keys=None, disable_progressba
191191

192192
# a song with the same name is installed
193193
if not check_id and check_name:
194-
c = len([file for file in Path(filedir).iterdir() if re.search(f'^{filename}_', str(file))]) + 1
195194

196-
fname = PurePath(PurePath(filename).name).parent
197-
ext = PurePath(PurePath(filename).name).suffix
195+
if Zotify.CONFIG.get_skip_existing():
196+
Printer.print(PrintChannel.SKIPS, '\n### SKIPPING: ' + song_name + ' (SONG ALREADY EXISTS) ###' + "\n")
197+
return
198+
else:
199+
c = len([file for file in Path(filedir).iterdir() if re.search(f'^{filename}_', str(file))]) + 1
200+
201+
fname = PurePath(filename).stem
202+
ext = PurePath(PurePath(filename).name).suffix
198203

199-
filename = PurePath(filedir).joinpath(f'{fname}_{c}{ext}')
204+
filename = PurePath(filedir).joinpath(f'{fname}_{c}{ext}')
200205

201206
except Exception as e:
202207
Printer.print(PrintChannel.ERRORS, '### SKIPPING SONG - FAILED TO QUERY METADATA ###')
@@ -289,6 +294,24 @@ def download_track(mode: str, track_id: str, extra_keys=None, disable_progressba
289294
Printer.print(PrintChannel.PROGRESS_INFO, f'Download successful. Waiting {wait_time} seconds.')
290295
time.sleep(wait_time)
291296

297+
# Verifica se o nome da playlist foi fornecido
298+
# Checks if playlist name is provided
299+
if extra_keys and 'playlist' in extra_keys:
300+
playlist_file = PurePath(Zotify.CONFIG.get_root_path()).joinpath(extra_keys['playlist'] + '.m3u8')
301+
302+
# Se for o primeiro item da playlist, realiza o truncamento
303+
# If it is the first item in the playlist, truncate it
304+
if extra_keys['playlist_num'].lstrip('0') == '1':
305+
with open(playlist_file, 'w', encoding='utf-8') as f:
306+
f.write("#EXTM3U\n")
307+
308+
# Adiciona o nome do arquivo da música baixada à playlist M3U8
309+
# Adds the downloaded music file name to the M3U8 playlist
310+
with open(playlist_file, "a", encoding='utf-8') as f:
311+
#f.write("#EXTINF:-1," + urlencode(song_name) + "\n")
312+
#f.write(f"{filename}\n")
313+
f.write(f"{filename.relative_to(PurePath(Zotify.CONFIG.get_root_path()))}\n")
314+
292315
except Exception as e:
293316
Printer.print(PrintChannel.ERRORS, '### SKIPPING: ' + song_name + ' (GENERAL DOWNLOAD ERROR) ###')
294317
Printer.print(PrintChannel.ERRORS, 'Track_ID: ' + str(track_id))

0 commit comments

Comments
 (0)