Fix playlist export

This commit is contained in:
Keith Edmunds 2022-03-03 18:30:00 +00:00
parent ca1b11b545
commit 1c56505ab0

View File

@ -315,32 +315,35 @@ class Window(QMainWindow, Ui_MainWindow):
if not self.visible_playlist_tab(): if not self.visible_playlist_tab():
return return
# Get output filename with Session() as session:
pathspec: Tuple[str, str] = QFileDialog.getSaveFileName( playlist = Playlists.get_by_id(
self, 'Save Playlist', session, self.visible_playlist_tab().playlist_id)
directory=f"{self.visible_playlist_tab().name}.m3u", # Get output filename
filter="M3U files (*.m3u);;All files (*.*)" pathspec: Tuple[str, str] = QFileDialog.getSaveFileName(
) self, 'Save Playlist',
if not pathspec: directory=f"{playlist.name}.m3u",
return filter="M3U files (*.m3u);;All files (*.*)"
)
if not pathspec:
return
path: str = pathspec[0] path: str = pathspec[0]
if not path.endswith(".m3u"): if not path.endswith(".m3u"):
path += ".m3u" path += ".m3u"
with open(path, "w") as f: with open(path, "w") as f:
# Required directive on first line # Required directive on first line
f.write("#EXTM3U\n") f.write("#EXTM3U\n")
for track in self.playlist.tracks: for _, track in playlist.tracks.items():
f.write( f.write(
"#EXTINF:" "#EXTINF:"
f"{int(track.duration / 1000)}," f"{int(track.duration / 1000)},"
f"{track.title} - " f"{track.title} - "
f"{track.artist}" f"{track.artist}"
"\n" "\n"
f"{track.path}" f"{track.path}"
"\n" "\n"
) )
def fade(self) -> None: def fade(self) -> None:
"""Fade currently playing track""" """Fade currently playing track"""