aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--diagram.drawio1
-rw-r--r--playlist.py59
-rw-r--r--playlist_unittest.py65
3 files changed, 84 insertions, 41 deletions
diff --git a/diagram.drawio b/diagram.drawio
new file mode 100644
index 0000000..0e6ec2f
--- /dev/null
+++ b/diagram.drawio
@@ -0,0 +1 @@
+<mxfile host="app.diagrams.net" modified="2021-12-18T17:44:05.313Z" agent="5.0 (X11)" etag="8pabhAijyeSDnWvFqPHg" version="16.0.0"><diagram id="g-wcGVps3MkI6_XAwNEs" name="Page-1">5Zhtb9owEMc/TV5uInYS4OWAbp3UStOY1O6lmxyJVxNnjnlIP/3OxAGCabtJDJXmFfadn+5/90twPDqer78oVmS3MgHhkV6y9ujEI8QPSA9/jKWqLYMhqQ2p4okdtDNM+RNYo52XLngCZWugllJoXrSNscxziHXLxpSSq/awmRTtXQuWgmOYxky41jue6Mxa/Wi4c1wDTzO79YD0a8ecNYNtJGXGErnaM9Erj46VlLpuzddjEEa8Rpd63udnvNuDKcj130wYzn4HN7OvvTtyfR+kP8qH7zr6YFdZMrGwAXskErjeKOFLbKameQsJZ2YvwSpQzQDcaW+MjVFXjXBKLvIEzN49dK8yrmFasNh4V1gqaMv0XGDP385egtKwfjY8fysaVhvIOWhV4RA7IehZnW2hkaa/2ktbZG3ZfsasjdlKSbdL78TEhtXzH7SlR7Q9EAkSLDbblUpnMpU5E1c766gt427MjZSFFe8XaF1ZcthCy2PSmo1eFhbPJRcqhhcCsufXTKWgXysqN1EKBNN82T7HyVUnjupTPKyJLk8d/bHcdFsuJniaYztGdbDW6cgUJcfnwSfrmPMkqTMDJX9iD5ulTG4KyXO9iSYceeHErIXJKOu8mKVLreQjjKWQuO4kl7lZZcaFODCdAAYStWHwBy4Mx1gg/4uF8L2xEFwCC4Gj+jd8hHeHgsHBK8HvOxQE56Sg/94oiC6BgsilgC1K6A4G/QMMQupgEJ4Tg+GbwADVU9W9nb/p/DSdj2HTnaz3nZPK9k6Iz+AS8Bm4f6g0StwZeg5fIkP3r9RZXyK+72jfDVqaTwJvG5fmlM4FxNyeH1j8aEItAHPRGYJomyBKj9zMyVkRol1F6CKu8M0pX0KowGLWXOadocgfhm2K+kcooqehCLu775Ib397XXXr1Bw==</diagram></mxfile> \ No newline at end of file
diff --git a/playlist.py b/playlist.py
index 12fd9ed..b175a08 100644
--- a/playlist.py
+++ b/playlist.py
@@ -1,10 +1,6 @@
-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)
@@ -16,42 +12,23 @@ class PlaylistModel(QAbstractListModel):
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 __init__(self, setSongCallback):
+ self.songList = list()
+ self.currentSong = None
+ self.callback = setSongCallback
+
+ def addSong(self, path):
+ self.songList.append(path)
+ logging.debug(f"Added song: {path}")
+ if self.currentSong is None:
+ self.setCurrentSong(0)
+
+ def setCurrentSong(self, index):
+ if index < len(self.songList):
+ self.currentSong = index
+ self.callback(self.songList[index])
+ logging.debug(f"Selected song: {self.currentSong}")
- 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()}")
diff --git a/playlist_unittest.py b/playlist_unittest.py
new file mode 100644
index 0000000..685dcb0
--- /dev/null
+++ b/playlist_unittest.py
@@ -0,0 +1,65 @@
+from playlist import Playlist
+
+def test_addAndSelectOneSong():
+ songAddedByUser = "/path/to/song"
+ songSetByCallback = None
+
+ def testCallback(song):
+ nonlocal songSetByCallback
+ songSetByCallback = song
+
+ uut = Playlist(testCallback)
+ uut.addSong(songAddedByUser)
+ uut.setCurrentSong(0)
+
+ assert songAddedByUser == songSetByCallback
+
+def test_addTwoSongsAndSelectBoth():
+ songAddedByUser = ["/path/to/song", "/path/to/second/song"]
+ songSetByCallback = None
+
+ def testCallback(song):
+ nonlocal songSetByCallback
+ songSetByCallback = song
+
+ uut = Playlist(testCallback)
+ uut.addSong(songAddedByUser[0])
+ uut.addSong(songAddedByUser[1])
+
+ uut.setCurrentSong(0)
+ assert songAddedByUser[0] == songSetByCallback
+
+ uut.setCurrentSong(1)
+ assert songAddedByUser[1] == songSetByCallback
+
+def test_firstAddedSongIsSelected():
+ songAddedByUser = "/path/to/song"
+ songSetByCallback = None
+
+ def testCallback(song):
+ nonlocal songSetByCallback
+ songSetByCallback = song
+
+ uut = Playlist(testCallback)
+ uut.addSong(songAddedByUser)
+
+ assert songAddedByUser == songSetByCallback
+
+def test_invalidSongSelection():
+ songAddedByUser = "/path/to/song"
+ songSetByCallback = None
+
+ def testCallback(song):
+ nonlocal songSetByCallback
+ songSetByCallback = song
+
+ uut = Playlist(testCallback)
+ assert songSetByCallback == None
+
+ uut.setCurrentSong(10)
+ assert songSetByCallback == None
+
+ uut.addSong(songAddedByUser)
+ uut.setCurrentSong(10)
+ assert songSetByCallback == songAddedByUser
+