aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2025-02-22 11:26:27 +0100
committerEddy Pedroni <epedroni@pm.me>2025-02-22 11:26:27 +0100
commite6f712c656365241434a71983024ac2a6e829cc8 (patch)
tree5bc9ac292834067aa3c1640165d050ff61aed399
parent336ee67aa4b6c467d3d936124db16ce7dcd5a3b3 (diff)
Removed playlist class, simplified a bunch of stuff
-rw-r--r--solo-tool-project/src/solo_tool/playlist.py26
-rw-r--r--solo-tool-project/src/solo_tool/session_manager.py11
-rw-r--r--solo-tool-project/src/solo_tool/solo_tool.py33
-rw-r--r--solo-tool-project/test/playlist_unittest.py103
-rw-r--r--solo-tool-project/test/session_manager_unittest.py28
5 files changed, 27 insertions, 174 deletions
diff --git a/solo-tool-project/src/solo_tool/playlist.py b/solo-tool-project/src/solo_tool/playlist.py
deleted file mode 100644
index 988cc04..0000000
--- a/solo-tool-project/src/solo_tool/playlist.py
+++ /dev/null
@@ -1,26 +0,0 @@
-class Playlist:
- def __init__(self, callback):
- self._songList = list()
- self._currentSong = None
- self._setSongCallback = callback
-
- def addSong(self, path):
- self._songList.append(path)
-
- def setCurrentSong(self, index):
- if index >= 0 and index < len(self._songList):
- self._currentSong = index
- self._setSongCallback(self._songList[index])
-
- def getCurrentSong(self):
- index = self._currentSong
- return self._songList[index] if index is not None else None
-
- def getCurrentSongIndex(self):
- return self._currentSong
-
- def getSongs(self):
- return self._songList
-
- def clear(self):
- self.__init__(self._setSongCallback)
diff --git a/solo-tool-project/src/solo_tool/session_manager.py b/solo-tool-project/src/solo_tool/session_manager.py
index 0896b22..a4dabc0 100644
--- a/solo-tool-project/src/solo_tool/session_manager.py
+++ b/solo-tool-project/src/solo_tool/session_manager.py
@@ -1,26 +1,25 @@
import json
-def loadSession(file, playlist, abController):
+def loadSession(file, songList, abController):
jsonStr = file.read()
session = json.loads(jsonStr)
- playlist.clear()
+ songList.clear()
abController.clear()
for entry in session:
songPath = entry["path"]
abLimits = entry["ab_limits"]
- playlist.addSong(songPath)
+ songList.append(songPath)
if abLimits is not None:
for l in abLimits:
abController.storeLimits(l[0], l[1], songPath)
-def saveSession(file, playlist, abController):
- songs = playlist.getSongs()
+def saveSession(file, songList, abController):
session = list()
- for s in songs:
+ for s in songList:
entry = {
"path": s,
"ab_limits" : abController.getStoredLimits(s)
diff --git a/solo-tool-project/src/solo_tool/solo_tool.py b/solo-tool-project/src/solo_tool/solo_tool.py
index 743c8d5..a4c7af8 100644
--- a/solo-tool-project/src/solo_tool/solo_tool.py
+++ b/solo-tool-project/src/solo_tool/solo_tool.py
@@ -1,6 +1,5 @@
import os
-from .playlist import Playlist
from .abcontroller import ABController
from .session_manager import loadSession, saveSession
from .notifier import Notifier
@@ -9,13 +8,17 @@ from .player_vlc import Player
class SoloTool:
def __init__(self, playerOverride=None):
self._player = Player() if playerOverride is None else playerOverride
- self._playlist = Playlist(self._playlistCallback)
self._abController = ABController(enabled=False, callback=self._abControllerCallback)
self._notifier = Notifier(self._player)
+ self._songList = []
+ self._song = None
- def _playlistCallback(self, path):
+ def _updateSong(self, index):
+ self._song = index
+ path = self._songList[index]
self._player.setCurrentSong(path)
self._abController.setCurrentSong(path)
+ self._notifier.notify(Notifier.CURRENT_SONG_EVENT, index)
def _abControllerCallback(self, position):
self._player.setPlaybackPosition(position)
@@ -26,23 +29,20 @@ class SoloTool:
@property
def songList(self) -> list[str]:
- return self._playlist.getSongs()
+ return self._songList
def addSong(self, path: str) -> None:
if os.path.isfile(path):
- self._playlist.addSong(path)
+ self._songList.append(path)
@property
def song(self) -> int:
- return self._playlist.getCurrentSongIndex()
+ return self._song
@song.setter
- def song(self, index: int) -> None:
- previous = self._playlist.getCurrentSongIndex()
- self._playlist.setCurrentSong(index)
- new = self._playlist.getCurrentSongIndex()
- if previous != new:
- self._notifier.notify(Notifier.CURRENT_SONG_EVENT, new)
+ def song(self, new: int) -> None:
+ if new >= 0 and new < len(self._songList) and new != self._song:
+ self._updateSong(new)
def storeAbLimits(self, aLimit, bLimit):
self._abController.storeLimits(aLimit, bLimit)
@@ -58,9 +58,8 @@ class SoloTool:
self._abController.setLimits(aLimit, bLimit)
def getStoredAbLimits(self):
- currentSong = self._playlist.getCurrentSong()
- if currentSong is not None:
- return self._abController.getStoredLimits(currentSong)
+ if self._song is not None:
+ return self._abController.getStoredLimits(self.songList[self._song])
else:
return list()
@@ -95,11 +94,11 @@ class SoloTool:
def loadSession(self, path):
with open(path, "r") as f:
- loadSession(f, self._playlist, self._abController)
+ loadSession(f, self._songList, self._abController)
def saveSession(self, path):
with open(path, "w") as f:
- saveSession(f, self._playlist, self._abController)
+ saveSession(f, self._songList, self._abController)
def play(self):
self._player.play()
diff --git a/solo-tool-project/test/playlist_unittest.py b/solo-tool-project/test/playlist_unittest.py
deleted file mode 100644
index 4b0186b..0000000
--- a/solo-tool-project/test/playlist_unittest.py
+++ /dev/null
@@ -1,103 +0,0 @@
-from solo_tool.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
- assert uut.getCurrentSong() == songAddedByUser
- assert uut.getCurrentSongIndex() == 0
- assert uut.getSongs() == [songAddedByUser]
-
-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])
- assert uut.getSongs() == songAddedByUser
-
- uut.setCurrentSong(0)
- assert songAddedByUser[0] == songSetByCallback
- assert uut.getCurrentSong() == songAddedByUser[0]
- assert uut.getCurrentSongIndex() == 0
-
- uut.setCurrentSong(1)
- assert songAddedByUser[1] == songSetByCallback
- assert uut.getCurrentSong() == songAddedByUser[1]
- assert uut.getCurrentSongIndex() == 1
-
-def test_firstAddedSongIsNotSelected():
- songAddedByUser = "/path/to/song"
- songSetByCallback = None
-
- def testCallback(song):
- nonlocal songSetByCallback
- songSetByCallback = song
-
- uut = Playlist(testCallback)
- uut.addSong(songAddedByUser)
-
- assert songSetByCallback == None
- assert uut.getCurrentSong() == None
- assert uut.getCurrentSongIndex() == None
- assert uut.getSongs() == [songAddedByUser]
-
-def test_invalidSongSelection():
- songAddedByUser = "/path/to/song"
- songSetByCallback = None
-
- def testCallback(song):
- nonlocal songSetByCallback
- songSetByCallback = song
-
- uut = Playlist(testCallback)
- assert songSetByCallback == None
- assert uut.getCurrentSong() == None
- assert uut.getCurrentSongIndex() == None
-
- uut.setCurrentSong(10)
- assert songSetByCallback == None
- assert uut.getCurrentSong() == None
- assert uut.getCurrentSongIndex() == None
-
- uut.addSong(songAddedByUser)
- uut.setCurrentSong(10)
- assert songSetByCallback == None
- assert uut.getCurrentSong() == None
- assert uut.getCurrentSongIndex() == None
- assert uut.getSongs() == [songAddedByUser]
-
-def test_clearPlaylist():
- songAddedByUser = ["/path/to/song", "/path/to/second/song"]
-
- def dummy(index):
- pass
-
- uut = Playlist(dummy)
- for s in songAddedByUser:
- uut.addSong(s)
- uut.setCurrentSong(0)
-
- assert uut.getSongs() == songAddedByUser
- assert uut.getCurrentSong() == songAddedByUser[0]
- assert uut.getCurrentSongIndex() == 0
-
- uut.clear()
-
- assert uut.getSongs() == []
- assert uut.getCurrentSong() == None
- assert uut.getCurrentSongIndex() == None
diff --git a/solo-tool-project/test/session_manager_unittest.py b/solo-tool-project/test/session_manager_unittest.py
index d7c5e7f..d89b82a 100644
--- a/solo-tool-project/test/session_manager_unittest.py
+++ b/solo-tool-project/test/session_manager_unittest.py
@@ -23,21 +23,6 @@ testSession = [
}
]
-class PlaylistMock:
- def __init__(self):
- self.lastAddedSong = None
- self.songs = list()
-
- def addSong(self, s):
- self.songs.append(s)
- self.lastAddedSong = s
-
- def getSongs(self):
- return self.songs
-
- def clear(self):
- self.__init__()
-
class ABControllerMock:
def __init__(self):
self.limits = dict()
@@ -68,7 +53,7 @@ class MockFile:
@pytest.fixture
def playlistMock():
- return PlaylistMock()
+ return []
@pytest.fixture
def abControllerMock():
@@ -81,7 +66,7 @@ def test_loadSession(playlistMock, abControllerMock):
for i, entry in enumerate(testSession):
expectedSong = entry["path"]
expectedLimits = entry["ab_limits"]
- loadedSong = playlistMock.songs[i]
+ loadedSong = playlistMock[i]
loadedLimits = abControllerMock.limits.get(expectedSong)
assert loadedSong == expectedSong
@@ -90,7 +75,7 @@ def test_loadSession(playlistMock, abControllerMock):
def test_saveSession(playlistMock, abControllerMock):
for i, entry in enumerate(testSession):
song = entry["path"]
- playlistMock.addSong(song)
+ playlistMock.append(song)
abLimits = entry["ab_limits"]
if abLimits is not None:
@@ -111,9 +96,8 @@ def test_loadAndSaveEmptySession(playlistMock, abControllerMock):
loadSession(sessionFile, playlistMock, abControllerMock)
- songs = playlistMock.getSongs()
- assert songs == list()
- for s in songs:
+ assert playlistMock == list()
+ for s in playlistMock:
assert abControllerMock.getStoredLimits(s) == None
def test_loadSessionNotAdditive(playlistMock, abControllerMock):
@@ -121,7 +105,7 @@ def test_loadSessionNotAdditive(playlistMock, abControllerMock):
loadSession(sessionFile, playlistMock, abControllerMock)
loadSession(sessionFile, playlistMock, abControllerMock)
- songs = playlistMock.getSongs()
+ songs = playlistMock
assert len(songs) == len(set(songs))
for s in songs:
abLimits = abControllerMock.getStoredLimits(s)