mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-23 01:16:18 +00:00
MySQL support
This commit is contained in:
parent
811bbbe81f
commit
f3eed12e1b
@ -123,8 +123,11 @@ def album_list_id3():
|
|||||||
|
|
||||||
@app.route('/rest/getNowPlaying.view', methods = [ 'GET', 'POST' ])
|
@app.route('/rest/getNowPlaying.view', methods = [ 'GET', 'POST' ])
|
||||||
def now_playing():
|
def now_playing():
|
||||||
# SQLite specific
|
if engine.name == 'sqlite':
|
||||||
query = User.query.join(Track).filter(func.strftime('%s', now()) - func.strftime('%s', User.last_play_date) < Track.duration * 2)
|
query = User.query.join(Track).filter(func.strftime('%s', now()) - func.strftime('%s', User.last_play_date) < Track.duration * 2)
|
||||||
|
else:
|
||||||
|
query = User.query.join(Track).filter(func.timediff(func.now(), User.last_play_date) < Track.duration * 2)
|
||||||
|
|
||||||
return request.formatter({
|
return request.formatter({
|
||||||
'nowPlaying': {
|
'nowPlaying': {
|
||||||
'entry': [ dict(
|
'entry': [ dict(
|
||||||
|
28
db.py
28
db.py
@ -7,8 +7,8 @@ from sqlalchemy import Integer, String, Boolean, DateTime
|
|||||||
from sqlalchemy.orm import scoped_session, sessionmaker, relationship, backref
|
from sqlalchemy.orm import scoped_session, sessionmaker, relationship, backref
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
|
||||||
from sqlalchemy.types import TypeDecorator
|
from sqlalchemy.types import TypeDecorator, BINARY
|
||||||
from sqlalchemy.types import BINARY
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
|
|
||||||
import uuid, datetime, time
|
import uuid, datetime, time
|
||||||
import os.path
|
import os.path
|
||||||
@ -52,8 +52,8 @@ class User(Base):
|
|||||||
__tablename__ = 'user'
|
__tablename__ = 'user'
|
||||||
|
|
||||||
id = UUID.gen_id_column()
|
id = UUID.gen_id_column()
|
||||||
name = Column(String, unique = True)
|
name = Column(String(64), unique = True)
|
||||||
mail = Column(String)
|
mail = Column(String(256))
|
||||||
password = Column(String(40))
|
password = Column(String(40))
|
||||||
salt = Column(String(6))
|
salt = Column(String(6))
|
||||||
admin = Column(Boolean, default = False)
|
admin = Column(Boolean, default = False)
|
||||||
@ -87,8 +87,8 @@ class Folder(Base):
|
|||||||
|
|
||||||
id = UUID.gen_id_column()
|
id = UUID.gen_id_column()
|
||||||
root = Column(Boolean, default = False)
|
root = Column(Boolean, default = False)
|
||||||
name = Column(String)
|
name = Column(String(256))
|
||||||
path = Column(String, unique = True)
|
path = Column(String(4096)) # should be unique, but mysql don't like such large columns
|
||||||
created = Column(DateTime, default = now)
|
created = Column(DateTime, default = now)
|
||||||
has_cover_art = Column(Boolean, default = False)
|
has_cover_art = Column(Boolean, default = False)
|
||||||
last_scan = Column(Integer, default = 0)
|
last_scan = Column(Integer, default = 0)
|
||||||
@ -127,7 +127,7 @@ class Artist(Base):
|
|||||||
__tablename__ = 'artist'
|
__tablename__ = 'artist'
|
||||||
|
|
||||||
id = UUID.gen_id_column()
|
id = UUID.gen_id_column()
|
||||||
name = Column(String, unique = True)
|
name = Column(String(256), unique = True)
|
||||||
albums = relationship('Album', backref = 'artist')
|
albums = relationship('Album', backref = 'artist')
|
||||||
|
|
||||||
def as_subsonic_artist(self, user):
|
def as_subsonic_artist(self, user):
|
||||||
@ -148,7 +148,7 @@ class Album(Base):
|
|||||||
__tablename__ = 'album'
|
__tablename__ = 'album'
|
||||||
|
|
||||||
id = UUID.gen_id_column()
|
id = UUID.gen_id_column()
|
||||||
name = Column(String)
|
name = Column(String(256))
|
||||||
artist_id = Column(UUID, ForeignKey('artist.id'))
|
artist_id = Column(UUID, ForeignKey('artist.id'))
|
||||||
tracks = relationship('Track', backref = 'album')
|
tracks = relationship('Track', backref = 'album')
|
||||||
|
|
||||||
@ -181,14 +181,14 @@ class Track(Base):
|
|||||||
id = UUID.gen_id_column()
|
id = UUID.gen_id_column()
|
||||||
disc = Column(Integer)
|
disc = Column(Integer)
|
||||||
number = Column(Integer)
|
number = Column(Integer)
|
||||||
title = Column(String)
|
title = Column(String(256))
|
||||||
year = Column(Integer, nullable = True)
|
year = Column(Integer, nullable = True)
|
||||||
genre = Column(String, nullable = True)
|
genre = Column(String(256), nullable = True)
|
||||||
duration = Column(Integer)
|
duration = Column(Integer)
|
||||||
album_id = Column(UUID, ForeignKey('album.id'))
|
album_id = Column(UUID, ForeignKey('album.id'))
|
||||||
bitrate = Column(Integer)
|
bitrate = Column(Integer)
|
||||||
|
|
||||||
path = Column(String, unique = True)
|
path = Column(String(4096)) # should be unique, but mysql don't like such large columns
|
||||||
created = Column(DateTime, default = now)
|
created = Column(DateTime, default = now)
|
||||||
last_modification = Column(Integer)
|
last_modification = Column(Integer)
|
||||||
|
|
||||||
@ -321,7 +321,7 @@ class ChatMessage(Base):
|
|||||||
id = UUID.gen_id_column()
|
id = UUID.gen_id_column()
|
||||||
user_id = Column(UUID, ForeignKey('user.id'))
|
user_id = Column(UUID, ForeignKey('user.id'))
|
||||||
time = Column(Integer, default = lambda: int(time.time()))
|
time = Column(Integer, default = lambda: int(time.time()))
|
||||||
message = Column(String)
|
message = Column(String(512))
|
||||||
|
|
||||||
user = relationship('User')
|
user = relationship('User')
|
||||||
|
|
||||||
@ -342,8 +342,8 @@ class Playlist(Base):
|
|||||||
|
|
||||||
id = UUID.gen_id_column()
|
id = UUID.gen_id_column()
|
||||||
user_id = Column(UUID, ForeignKey('user.id'))
|
user_id = Column(UUID, ForeignKey('user.id'))
|
||||||
name = Column(String)
|
name = Column(String(256))
|
||||||
comment = Column(String, nullable = True)
|
comment = Column(String(256), nullable = True)
|
||||||
public = Column(Boolean, default = False)
|
public = Column(Boolean, default = False)
|
||||||
created = Column(DateTime, default = now)
|
created = Column(DateTime, default = now)
|
||||||
|
|
||||||
|
2
main.py
2
main.py
@ -14,5 +14,5 @@ if __name__ == '__main__':
|
|||||||
from web import app
|
from web import app
|
||||||
|
|
||||||
db.init_db()
|
db.init_db()
|
||||||
app.run(debug = True)
|
app.run(host = '0.0.0.0', debug = True)
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class Scanner:
|
|||||||
return al
|
return al
|
||||||
|
|
||||||
def __find_artist(self, artist):
|
def __find_artist(self, artist):
|
||||||
ar = filter(lambda a: a.name == artist, self.__artists)
|
ar = filter(lambda a: a.name.lower() == artist.lower(), self.__artists)
|
||||||
if ar:
|
if ar:
|
||||||
return ar[0]
|
return ar[0]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user