diff --git a/app/musicmuster.py b/app/musicmuster.py index 882f0ab..9964b9e 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -122,6 +122,7 @@ class Window(QMainWindow, Ui_MainWindow): self.actionAdd_file.triggered.connect(self.add_file) self.action_Clear_selection.triggered.connect(self.clear_selection) self.actionClosePlaylist.triggered.connect(self.close_playlist) + self.actionExport_playlist.triggered.connect(self.export_playlist) self.actionFade.triggered.connect(self.fade) self.actionMoveSelected.triggered.connect(self.move_selected) self.actionNewPlaylist.triggered.connect(self.create_playlist) @@ -195,6 +196,39 @@ class Window(QMainWindow, Ui_MainWindow): DEBUG("enable_play_next_controls()") self.actionPlay_next.setEnabled(True) + def export_playlist(self): + "Export the current playlist to an m3u file" + + if not self.visible_playlist(): + return + + # Get output filename + pathspec = QFileDialog.getSaveFileName( + self, 'Save Playlist', + directory=f"{self.visible_playlist().db.name}.m3u", + filter="M3U files (*.m3u);;All files (*.*)" + ) + if not pathspec: + return + + path = pathspec[0] + + if not path.endswith(".m3u"): + path += ".m3u" + with open(path, "w") as f: + # Required directive on first line + f.write("#EXTM3U\n") + for track in self.visible_playlist().db.get_tracks(): + f.write( + "#EXTINF:" + f"{int(track.duration / 1000)}," + f"{track.title} - " + f"{track.artist}" + "\n" + f"{track.path}" + "\n" + ) + def fade(self): "Fade currently playing track" diff --git a/app/ui/main_window.ui b/app/ui/main_window.ui index 1e8e4ca..7a81bec 100644 --- a/app/ui/main_window.ui +++ b/app/ui/main_window.ui @@ -751,7 +751,7 @@ border: 1px solid rgb(85, 87, 83); 0 0 1164 - 29 + 18 @@ -775,6 +775,8 @@ border: 1px solid rgb(85, 87, 83); + + @@ -958,6 +960,11 @@ border: 1px solid rgb(85, 87, 83); Mo&ve selected tracks to... + + + E&xport playlist... + +