aboutsummaryrefslogtreecommitdiffstats
path: root/session_manager.py
blob: 52742c80b47f43615b8fa8fb8e1882d8598efe38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json

class SessionManager:
    def __init__(self, playlist, abController):
        self._playlist = playlist
        self._abController = abController

    def addSong(self, path):
        self._playlist.addSong(path)

    def addLimits(self, aLimit, bLimit):
        self._abController.addLimits(aLimit, bLimit)

    def loadSession(self, file):
        jsonStr = file.read()
        session = json.loads(jsonStr)

        for entry in session:
            songPath = entry["path"]
            abLimits = entry["ab_limits"]
            self._playlist.addSong(songPath)

            if abLimits is not None:
                for l in abLimits:
                    self._abController.addLimits(l[0], l[1], songPath)
            
    def saveSession(self, file):
        songs = self._playlist.getSongs()
        session = list()

        for s in songs:
            entry = {
                "path": s,
                "ab_limits" : self._abController.getLimits(s)
            }
            session.append(entry)

        file.write(json.dumps(session))