fix hard coded library paths
This commit is contained in:
parent
3aedfcf139
commit
5f3b2e471b
|
@ -271,8 +271,9 @@ class PysonicApi(object):
|
||||||
moreargs.update(name=child["name"],
|
moreargs.update(name=child["name"],
|
||||||
isDir="true", # TODO song files in artist dir
|
isDir="true", # TODO song files in artist dir
|
||||||
parent=entity["id"],
|
parent=entity["id"],
|
||||||
coverArt=child["coverid"],
|
|
||||||
id=child["dir"])
|
id=child["dir"])
|
||||||
|
if child["coverid"]:
|
||||||
|
moreargs.update(coverArt=child["coverid"])
|
||||||
# album=item["name"],
|
# album=item["name"],
|
||||||
# title=item["name"], # TODO dupe?
|
# title=item["name"], # TODO dupe?
|
||||||
# artist=artist["name"],
|
# artist=artist["name"],
|
||||||
|
@ -281,13 +282,14 @@ class PysonicApi(object):
|
||||||
moreargs.update(name=child["title"],
|
moreargs.update(name=child["title"],
|
||||||
artist=child["_artist"]["name"],
|
artist=child["_artist"]["name"],
|
||||||
contentType=child["format"],
|
contentType=child["format"],
|
||||||
coverArt=entity["coverid"],
|
id=child["id"],
|
||||||
id=child["id"], # this is probably fucked ?
|
|
||||||
duration=child["length"],
|
duration=child["length"],
|
||||||
isDir="false",
|
isDir="false",
|
||||||
parent=entity["dir"],
|
parent=entity["dir"],
|
||||||
# title=xxx
|
# title=xxx
|
||||||
)
|
)
|
||||||
|
if entity["coverid"]:
|
||||||
|
moreargs.update(coverArt=entity["coverid"])
|
||||||
# duration="230" size="8409237" suffix="mp3" track="2" year="2005"/>
|
# duration="230" size="8409237" suffix="mp3" track="2" year="2005"/>
|
||||||
response.add_child("child", _parent="directory",
|
response.add_child("child", _parent="directory",
|
||||||
size="4096",
|
size="4096",
|
||||||
|
@ -346,11 +348,7 @@ class PysonicApi(object):
|
||||||
maxBitRate = int(maxBitRate)
|
maxBitRate = int(maxBitRate)
|
||||||
assert maxBitRate >= 32 and maxBitRate <= 320
|
assert maxBitRate >= 32 and maxBitRate <= 320
|
||||||
song = self.library.get_song(id)
|
song = self.library.get_song(id)
|
||||||
fpath = "library/" + song["file"]
|
fpath = song["_fullpath"]
|
||||||
# import pdb
|
|
||||||
# from pprint import pprint
|
|
||||||
# pdb.set_trace()
|
|
||||||
# meta = self.library.get_file_metadata(id)
|
|
||||||
to_bitrate = min(maxBitRate, self.options.max_bitrate, song.get("bitrate", 320 * 1024) / 1024)
|
to_bitrate = min(maxBitRate, self.options.max_bitrate, song.get("bitrate", 320 * 1024) / 1024)
|
||||||
cherrypy.response.headers['Content-Type'] = 'audio/mpeg'
|
cherrypy.response.headers['Content-Type'] = 'audio/mpeg'
|
||||||
#if "media_length" in meta:
|
#if "media_length" in meta:
|
||||||
|
@ -416,7 +414,7 @@ class PysonicApi(object):
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def getCoverArt_view(self, id, **kwargs):
|
def getCoverArt_view(self, id, **kwargs):
|
||||||
cover = self.library.get_cover(id)
|
cover = self.library.get_cover(id)
|
||||||
fpath = "library/" + cover["path"]
|
fpath = cover["_fullpath"]
|
||||||
type2ct = {
|
type2ct = {
|
||||||
'jpg': 'image/jpeg',
|
'jpg': 'image/jpeg',
|
||||||
'png': 'image/png',
|
'png': 'image/png',
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import logging
|
import logging
|
||||||
from hashlib import sha512
|
from hashlib import sha512
|
||||||
|
@ -75,6 +73,7 @@ class PysonicDatabase(object):
|
||||||
UNIQUE (artistid, dir));""",
|
UNIQUE (artistid, dir));""",
|
||||||
"""CREATE TABLE 'songs' (
|
"""CREATE TABLE 'songs' (
|
||||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
'library' INTEGER,
|
||||||
'albumid' BOOLEAN,
|
'albumid' BOOLEAN,
|
||||||
'file' TEXT UNIQUE, -- path from the library root
|
'file' TEXT UNIQUE, -- path from the library root
|
||||||
'size' INTEGER NOT NULL DEFAULT -1,
|
'size' INTEGER NOT NULL DEFAULT -1,
|
||||||
|
@ -88,6 +87,7 @@ class PysonicDatabase(object):
|
||||||
)""",
|
)""",
|
||||||
"""CREATE TABLE 'covers' (
|
"""CREATE TABLE 'covers' (
|
||||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
'library' INTEGER,
|
||||||
'type' TEXT,
|
'type' TEXT,
|
||||||
'size' TEXT,
|
'size' TEXT,
|
||||||
'path' TEXT UNIQUE);""",
|
'path' TEXT UNIQUE);""",
|
||||||
|
@ -113,7 +113,6 @@ class PysonicDatabase(object):
|
||||||
if len(cursor.fetchall()) == 0:
|
if len(cursor.fetchall()) == 0:
|
||||||
logging.warning("Initializing database")
|
logging.warning("Initializing database")
|
||||||
for query in queries:
|
for query in queries:
|
||||||
print(query)
|
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
cursor.execute("COMMIT")
|
cursor.execute("COMMIT")
|
||||||
else:
|
else:
|
||||||
|
@ -140,9 +139,17 @@ class PysonicDatabase(object):
|
||||||
raise DuplicateRootException("Root '{}' already exists".format(path))
|
raise DuplicateRootException("Root '{}' already exists".format(path))
|
||||||
|
|
||||||
@readcursor
|
@readcursor
|
||||||
def get_libraries(self, cursor):
|
def get_libraries(self, cursor, id=None):
|
||||||
libs = []
|
libs = []
|
||||||
cursor.execute("SELECT * FROM libraries")
|
q = "SELECT * FROM libraries"
|
||||||
|
params = []
|
||||||
|
conditions = []
|
||||||
|
if id:
|
||||||
|
conditions.append("id = ?")
|
||||||
|
params.append(id)
|
||||||
|
if conditions:
|
||||||
|
q += " WHERE " + " AND ".join(conditions)
|
||||||
|
cursor.execute(q, params)
|
||||||
for row in cursor:
|
for row in cursor:
|
||||||
libs.append(row)
|
libs.append(row)
|
||||||
return libs
|
return libs
|
||||||
|
@ -164,8 +171,6 @@ class PysonicDatabase(object):
|
||||||
q += " WHERE " + " AND ".join(conditions)
|
q += " WHERE " + " AND ".join(conditions)
|
||||||
if sortby:
|
if sortby:
|
||||||
q += " ORDER BY {} {}".format(sortby, order.upper() if order else "ASC")
|
q += " ORDER BY {} {}".format(sortby, order.upper() if order else "ASC")
|
||||||
print(q)
|
|
||||||
print(params)
|
|
||||||
cursor.execute(q, params)
|
cursor.execute(q, params)
|
||||||
for row in cursor:
|
for row in cursor:
|
||||||
artists.append(row)
|
artists.append(row)
|
||||||
|
|
|
@ -35,8 +35,8 @@ class PysonicLibrary(object):
|
||||||
self.get_libraries = self.db.get_libraries
|
self.get_libraries = self.db.get_libraries
|
||||||
self.get_artists = self.db.get_artists
|
self.get_artists = self.db.get_artists
|
||||||
self.get_albums = self.db.get_albums
|
self.get_albums = self.db.get_albums
|
||||||
self.get_song = self.db.get_song
|
# self.get_song = self.db.get_song
|
||||||
self.get_cover = self.db.get_cover
|
# self.get_cover = self.db.get_cover
|
||||||
|
|
||||||
self.scanner = PysonicFilesystemScanner(self)
|
self.scanner = PysonicFilesystemScanner(self)
|
||||||
logging.info("library ready")
|
logging.info("library ready")
|
||||||
|
@ -76,12 +76,17 @@ class PysonicLibrary(object):
|
||||||
"largeImageUrl": "",
|
"largeImageUrl": "",
|
||||||
"similarArtists": []}
|
"similarArtists": []}
|
||||||
|
|
||||||
# def get_cover(self, cover_id):
|
def get_cover(self, cover_id):
|
||||||
# cover = self.db.get_cover(cover_id)
|
cover = self.db.get_cover(cover_id)
|
||||||
|
library = self.db.get_libraries(cover["library"])[0]
|
||||||
|
cover['_fullpath'] = os.path.join(library["path"], cover["path"])
|
||||||
|
return cover
|
||||||
|
|
||||||
|
def get_song(self, song_id):
|
||||||
|
song = self.db.get_song(song_id)
|
||||||
|
library = self.db.get_libraries(song["library"])[0]
|
||||||
|
song['_fullpath'] = os.path.join(library["path"], song["file"])
|
||||||
|
return song
|
||||||
|
|
||||||
# #@memoize
|
# #@memoize
|
||||||
# def get_libraries(self):
|
# def get_libraries(self):
|
||||||
|
|
|
@ -136,9 +136,10 @@ class PysonicFilesystemScanner(object):
|
||||||
|
|
||||||
if not cursor.fetchall():
|
if not cursor.fetchall():
|
||||||
# We leave most fields blank now and return later
|
# We leave most fields blank now and return later
|
||||||
cursor.execute("INSERT INTO songs (albumid, file, size, title) "
|
cursor.execute("INSERT INTO songs (library, albumid, file, size, title) "
|
||||||
"VALUES (?, ?, ?, ?)",
|
"VALUES (?, ?, ?, ?, ?)",
|
||||||
(album_id,
|
(pid,
|
||||||
|
album_id,
|
||||||
fpath,
|
fpath,
|
||||||
os.stat(os.path.join(root, fpath)).st_size,
|
os.stat(os.path.join(root, fpath)).st_size,
|
||||||
file, ))
|
file, ))
|
||||||
|
@ -153,7 +154,7 @@ class PysonicFilesystemScanner(object):
|
||||||
cursor.execute("SELECT id FROM covers WHERE path=?", (fpath, ))
|
cursor.execute("SELECT id FROM covers WHERE path=?", (fpath, ))
|
||||||
if not cursor.fetchall():
|
if not cursor.fetchall():
|
||||||
# We leave most fields blank now and return later
|
# We leave most fields blank now and return later
|
||||||
cursor.execute("INSERT INTO covers (path) VALUES (?);", (fpath, ))
|
cursor.execute("INSERT INTO covers (library, path) VALUES (?, ?);", (pid, fpath, ))
|
||||||
cursor.execute("UPDATE albums SET coverid=? WHERE id=?", (cursor.lastrowid, album_id))
|
cursor.execute("UPDATE albums SET coverid=? WHERE id=?", (cursor.lastrowid, album_id))
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue