Skip to content

Commit bf7768a

Browse files
committed
Manually merge (zotify-dev#112)
Manually merge fix for _1.ext files (missing normal filename part) and adds creation of M3U playlist files. (zotify-dev#112)
1 parent 8c7f25f commit bf7768a

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
@@ -187,12 +187,17 @@ def download_track(mode: str, track_id: str, extra_keys=None, disable_progressba
187187

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

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

195-
filename = PurePath(filedir).joinpath(f'{fname}_{c}{ext}')
200+
filename = PurePath(filedir).joinpath(f'{fname}_{c}{ext}')
196201

197202
except Exception as e:
198203
Printer.print(PrintChannel.ERRORS, '### SKIPPING SONG - FAILED TO QUERY METADATA ###')
@@ -285,6 +290,24 @@ def download_track(mode: str, track_id: str, extra_keys=None, disable_progressba
285290
Printer.print(PrintChannel.PROGRESS_INFO, f'Download successful. Waiting {wait_time} seconds.')
286291
time.sleep(wait_time)
287292

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

0 commit comments

Comments
 (0)