diff --git a/supysonic/api/browse.py b/supysonic/api/browse.py index 72949f5..fed98ee 100644 --- a/supysonic/api/browse.py +++ b/supysonic/api/browse.py @@ -42,7 +42,10 @@ def list_indexes(): if musicFolderId is None: folders = Folder.select(lambda f: f.root)[:] else: - mfid = uuid.UUID(musicFolderId) + try: + mfid = int(musicFolderId) + except ValueError: + raise ValueError("Invalid folder ID") folder = Folder[mfid] if not folder.root: raise ObjectNotFound(Folder, mfid) diff --git a/supysonic/config.py b/supysonic/config.py index a83616d..de9d5ea 100644 --- a/supysonic/config.py +++ b/supysonic/config.py @@ -90,8 +90,13 @@ class IniConfig(DefaultConfig): lv = value.lower() if lv in ("yes", "true", "on"): return True - elif lv in ("no", "false", "off"): + if lv in ("no", "false", "off"): return False + try: + if isinstance(value, unicode): + return str(value) + except NameError: + pass return value @classmethod diff --git a/supysonic/db.py b/supysonic/db.py index d23ac53..f079dfb 100644 --- a/supysonic/db.py +++ b/supysonic/db.py @@ -79,7 +79,7 @@ class PathMixin(object): class Folder(PathMixin, db.Entity): _table_ = "folder" - id = PrimaryKey(UUID, default=uuid4) + id = PrimaryKey(int, auto=True) root = Required(bool, default=False) name = Required(str, autostrip=False) path = Required(str, 4096, autostrip=False) # unique diff --git a/supysonic/managers/folder.py b/supysonic/managers/folder.py index db8cb46..eede1da 100644 --- a/supysonic/managers/folder.py +++ b/supysonic/managers/folder.py @@ -21,15 +21,13 @@ from ..py23 import strtype class FolderManager: @staticmethod - def get(uid): - if isinstance(uid, strtype): - uid = uuid.UUID(uid) - elif isinstance(uid, uuid.UUID): - pass - else: + def get(id): + try: + id = int(id) + except ValueError: raise ValueError("Invalid folder id") - return Folder[uid] + return Folder[id] @staticmethod def add(name, path): @@ -55,8 +53,8 @@ class FolderManager: return folder @staticmethod - def delete(uid): - folder = FolderManager.get(uid) + def delete(id): + folder = FolderManager.get(id) if not folder.root: raise ObjectNotFound(Folder) diff --git a/supysonic/schema/sqlite.sql b/supysonic/schema/sqlite.sql index 23a7ff8..40e8441 100644 --- a/supysonic/schema/sqlite.sql +++ b/supysonic/schema/sqlite.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS folder ( - id CHAR(36) PRIMARY KEY, + id INTEGER NOT NULL PRIMARY KEY, root BOOLEAN NOT NULL, name VARCHAR(256) NOT NULL COLLATE NOCASE, path VARCHAR(4096) NOT NULL, @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS folder ( created DATETIME NOT NULL, cover_art VARCHAR(256), last_scan INTEGER NOT NULL, - parent_id CHAR(36) REFERENCES folder + parent_id INTEGER REFERENCES folder ); CREATE INDEX IF NOT EXISTS index_folder_parent_id_fk ON folder(parent_id); CREATE UNIQUE INDEX IF NOT EXISTS index_folder_path ON folder(path_hash); @@ -42,8 +42,8 @@ CREATE TABLE IF NOT EXISTS track ( last_modification INTEGER NOT NULL, play_count INTEGER NOT NULL, last_play DATETIME, - root_folder_id CHAR(36) NOT NULL REFERENCES folder, - folder_id CHAR(36) NOT NULL REFERENCES folder + root_folder_id INTEGER NOT NULL REFERENCES folder, + folder_id INTEGER NOT NULL REFERENCES folder ); CREATE INDEX IF NOT EXISTS index_track_album_id_fk ON track(album_id); CREATE INDEX IF NOT EXISTS index_track_artist_id_fk ON track(artist_id); @@ -75,7 +75,7 @@ CREATE TABLE IF NOT EXISTS client_prefs ( CREATE TABLE IF NOT EXISTS starred_folder ( user_id CHAR(36) NOT NULL REFERENCES user, - starred_id CHAR(36) NOT NULL REFERENCES folder, + starred_id INTEGER NOT NULL REFERENCES folder, date DATETIME NOT NULL, PRIMARY KEY (user_id, starred_id) ); @@ -111,7 +111,7 @@ CREATE INDEX IF NOT EXISTS index_starred_track_starred_id_fk ON starred_track(st CREATE TABLE IF NOT EXISTS rating_folder ( user_id CHAR(36) NOT NULL REFERENCES user, - rated_id CHAR(36) NOT NULL REFERENCES folder, + rated_id INTEGER NOT NULL REFERENCES folder, rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5), PRIMARY KEY (user_id, rated_id) );