aboutsummaryrefslogtreecommitdiffstats
path: root/playlist.py
diff options
context:
space:
mode:
Diffstat (limited to 'playlist.py')
-rw-r--r--playlist.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/playlist.py b/playlist.py
new file mode 100644
index 0000000..12fd9ed
--- /dev/null
+++ b/playlist.py
@@ -0,0 +1,57 @@
+from PyQt5.QtGui import *
+from PyQt5.QtWidgets import *
+from PyQt5.QtCore import *
+
+import logging
+import vlc
+
+class PlaylistModel(QAbstractListModel):
+ def __init__(self, medialist, *args, **kwargs):
+ super(PlaylistModel, self).__init__(*args, **kwargs)
+ self.medialist = medialist
+
+ def data(self, index, role):
+ if role == Qt.DisplayRole:
+ return self.medialist.item_at_index(index.row()).get_mrl()
+
+ def rowCount(self, index):
+ return self.medialist.count()
+
+class Playlist:
+ def __init__(self, window):
+ self.medialist = vlc.MediaList()
+ self.model = PlaylistModel(self.medialist)
+ self.window = window
+
+ window.player.set_media_list(self.medialist)
+ window.songListView.setModel(self.model)
+ window.songListView.selectionModel().selectionChanged.connect(self.playlistSelectionChanged)
+ window.addSongButton.pressed.connect(self.addSong)
+
+ def addSong(self):
+ path, _ = QFileDialog.getOpenFileName(self.window, "Open file", "", "mp3 Audio (*.mp3);FLAC audio (*.flac);All files (*.*)")
+ if path:
+ media = vlc.Media(path)
+ self.medialist.add_media(media)
+ self.model.layoutChanged.emit()
+ logging.debug(f"Added song: {path}")
+
+ def playlistSelectionChanged(self, ix):
+ i = ix.indexes()[0].row()
+ self.setCurrent(i)
+ #path = self.playlist.current.filePath
+ #self.player.set_media(path)
+ """
+ self.abListModel.abList = self.internalState[path]
+ self.abListView.selectionModel().clearSelection()
+ self.abListModel.layoutChanged.emit()
+ self.aSlider.setValue(0)
+ self.bSlider.setValue(0)
+ """
+
+ def setCurrent(self, index):
+ media = self.medialist.item_at_index(index)
+ if not media:
+ raise Exception(f"Invalid playlist index {index}")
+ self.medialist.set_media(media)
+ logging.debug(f"Selected song: {self.medialist.media().get_mrl()}")