mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-23 01:16:18 +00:00
Added starred info to responses
This commit is contained in:
parent
20e09a6321
commit
b4e3b22089
@ -38,7 +38,7 @@ def rand_songs():
|
|||||||
|
|
||||||
return request.formatter({
|
return request.formatter({
|
||||||
'randomSongs': {
|
'randomSongs': {
|
||||||
'song': [ random.choice(tracks).as_subsonic_child() for x in xrange(size) ]
|
'song': [ random.choice(tracks).as_subsonic_child(request.user) for x in xrange(size) ]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ def album_list():
|
|||||||
albums = query.all()
|
albums = query.all()
|
||||||
return request.formatter({
|
return request.formatter({
|
||||||
'albumList': {
|
'albumList': {
|
||||||
'album': [ random.choice(albums).as_subsonic_child() for x in xrange(size) ]
|
'album': [ random.choice(albums).as_subsonic_child(request.user) for x in xrange(size) ]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
elif ltype == 'newest':
|
elif ltype == 'newest':
|
||||||
@ -79,7 +79,7 @@ def album_list():
|
|||||||
|
|
||||||
return request.formatter({
|
return request.formatter({
|
||||||
'albumList': {
|
'albumList': {
|
||||||
'album': [ f.as_subsonic_child() for f in query.limit(size).offset(offset) ]
|
'album': [ f.as_subsonic_child(request.user) for f in query.limit(size).offset(offset) ]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ def album_list_id3():
|
|||||||
albums = query.all()
|
albums = query.all()
|
||||||
return request.formatter({
|
return request.formatter({
|
||||||
'albumList2': {
|
'albumList2': {
|
||||||
'album': [ random.choice(albums).as_subsonic_album() for x in xrange(size) ]
|
'album': [ random.choice(albums).as_subsonic_album(request.user) for x in xrange(size) ]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
elif ltype == 'newest':
|
elif ltype == 'newest':
|
||||||
@ -117,7 +117,7 @@ def album_list_id3():
|
|||||||
|
|
||||||
return request.formatter({
|
return request.formatter({
|
||||||
'albumList2': {
|
'albumList2': {
|
||||||
'album': [ f.as_subsonic_album() for f in query.limit(size).offset(offset) ]
|
'album': [ f.as_subsonic_album(request.user) for f in query.limit(size).offset(offset) ]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ def now_playing():
|
|||||||
return request.formatter({
|
return request.formatter({
|
||||||
'nowPlaying': {
|
'nowPlaying': {
|
||||||
'entry': [ dict(
|
'entry': [ dict(
|
||||||
u.last_play.as_subsonic_child().items() +
|
u.last_play.as_subsonic_child(request.user).items() +
|
||||||
{ 'username': u.name, 'minutesAgo': (now() - u.last_play_date).seconds / 60, 'playerId': 0 }.items()
|
{ 'username': u.name, 'minutesAgo': (now() - u.last_play_date).seconds / 60, 'playerId': 0 }.items()
|
||||||
) for u in query ]
|
) for u in query ]
|
||||||
}
|
}
|
||||||
@ -139,8 +139,8 @@ def get_starred():
|
|||||||
return request.formatter({
|
return request.formatter({
|
||||||
'starred': {
|
'starred': {
|
||||||
'artist': [ { 'id': sf.starred.name, 'name': sf.starred_id } for sf in StarredFolder.query.join(User).join(Folder).filter(User.name == request.username).filter(~ Folder.tracks.any()) ],
|
'artist': [ { 'id': sf.starred.name, 'name': sf.starred_id } for sf in StarredFolder.query.join(User).join(Folder).filter(User.name == request.username).filter(~ Folder.tracks.any()) ],
|
||||||
'album': [ sf.starred.as_subsonic_child() for sf in StarredFolder.query.join(User).join(Folder).filter(User.name == request.username).filter(Folder.tracks.any()) ],
|
'album': [ sf.starred.as_subsonic_child(request.user) for sf in StarredFolder.query.join(User).join(Folder).filter(User.name == request.username).filter(Folder.tracks.any()) ],
|
||||||
'song': [ st.starred.as_subsonic_child() for st in StarredTrack.query.join(User).filter(User.name == request.username) ]
|
'song': [ st.starred.as_subsonic_child(request.user) for st in StarredTrack.query.join(User).filter(User.name == request.username) ]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -148,9 +148,9 @@ def get_starred():
|
|||||||
def get_starred_id3():
|
def get_starred_id3():
|
||||||
return request.formatter({
|
return request.formatter({
|
||||||
'starred2': {
|
'starred2': {
|
||||||
'artist': [ sa.starred.as_subsonic_artist() for sa in StarredArtist.query.join(User).filter(User.name == request.username) ],
|
'artist': [ sa.starred.as_subsonic_artist(request.user) for sa in StarredArtist.query.join(User).filter(User.name == request.username) ],
|
||||||
'album': [ sa.starred.as_subsonic_album() for sa in StarredAlbum.query.join(User).filter(User.name == request.username) ],
|
'album': [ sa.starred.as_subsonic_album(request.user) for sa in StarredAlbum.query.join(User).filter(User.name == request.username) ],
|
||||||
'song': [ st.starred.as_subsonic_child() for st in StarredTrack.query.join(User).filter(User.name == request.username) ]
|
'song': [ st.starred.as_subsonic_child(request.user) for st in StarredTrack.query.join(User).filter(User.name == request.username) ]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ def list_indexes():
|
|||||||
'name': a.name
|
'name': a.name
|
||||||
} for a in sorted(v, key = lambda a: a.name.lower()) ]
|
} for a in sorted(v, key = lambda a: a.name.lower()) ]
|
||||||
} for k, v in sorted(indexes.iteritems()) ],
|
} for k, v in sorted(indexes.iteritems()) ],
|
||||||
'child': [ c.as_subsonic_child() for c in sorted(childs, key = lambda t: t.sort_key()) ]
|
'child': [ c.as_subsonic_child(request.user) for c in sorted(childs, key = lambda t: t.sort_key()) ]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ def show_directory():
|
|||||||
directory = {
|
directory = {
|
||||||
'id': str(res.id),
|
'id': str(res.id),
|
||||||
'name': res.name,
|
'name': res.name,
|
||||||
'child': [ f.as_subsonic_child() for f in sorted(res.children, key = lambda c: c.name.lower()) ] + [ t.as_subsonic_child() for t in sorted(res.tracks, key = lambda t: t.sort_key()) ]
|
'child': [ f.as_subsonic_child(request.user) for f in sorted(res.children, key = lambda c: c.name.lower()) ] + [ t.as_subsonic_child(request.user) for t in sorted(res.tracks, key = lambda t: t.sort_key()) ]
|
||||||
}
|
}
|
||||||
if not res.root:
|
if not res.root:
|
||||||
directory['parent'] = str(res.parent_id)
|
directory['parent'] = str(res.parent_id)
|
||||||
@ -120,7 +120,7 @@ def list_artists():
|
|||||||
'artists': {
|
'artists': {
|
||||||
'index': [ {
|
'index': [ {
|
||||||
'name': k,
|
'name': k,
|
||||||
'artist': [ a.as_subsonic_artist() for a in sorted(v, key = lambda a: a.name.lower()) ]
|
'artist': [ a.as_subsonic_artist(request.user) for a in sorted(v, key = lambda a: a.name.lower()) ]
|
||||||
} for k, v in sorted(indexes.iteritems()) ]
|
} for k, v in sorted(indexes.iteritems()) ]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -131,8 +131,8 @@ def artist_info():
|
|||||||
if not status:
|
if not status:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
info = res.as_subsonic_artist()
|
info = res.as_subsonic_artist(request.user)
|
||||||
info['album'] = [ a.as_subsonic_album() for a in sorted(res.albums, key = lambda a: a.sort_key()) ]
|
info['album'] = [ a.as_subsonic_album(request.user) for a in sorted(res.albums, key = lambda a: a.sort_key()) ]
|
||||||
|
|
||||||
return request.formatter({ 'artist': info })
|
return request.formatter({ 'artist': info })
|
||||||
|
|
||||||
@ -142,8 +142,8 @@ def album_info():
|
|||||||
if not status:
|
if not status:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
info = res.as_subsonic_album()
|
info = res.as_subsonic_album(request.user)
|
||||||
info['song'] = [ t.as_subsonic_child() for t in sorted(res.tracks, key = lambda t: t.sort_key()) ]
|
info['song'] = [ t.as_subsonic_child(request.user) for t in sorted(res.tracks, key = lambda t: t.sort_key()) ]
|
||||||
|
|
||||||
return request.formatter({ 'album': info })
|
return request.formatter({ 'album': info })
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ def track_info():
|
|||||||
if not status:
|
if not status:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
return request.formatter({ 'song': res.as_subsonic_child() })
|
return request.formatter({ 'song': res.as_subsonic_child(request.user) })
|
||||||
|
|
||||||
@app.route('/rest/getVideos.view', methods = [ 'GET', 'POST' ])
|
@app.route('/rest/getVideos.view', methods = [ 'GET', 'POST' ])
|
||||||
def list_videos():
|
def list_videos():
|
||||||
|
31
db.py
31
db.py
@ -78,7 +78,7 @@ class Folder(Base):
|
|||||||
parent_id = Column(UUID, ForeignKey('folder.id'), nullable = True)
|
parent_id = Column(UUID, ForeignKey('folder.id'), nullable = True)
|
||||||
children = relationship('Folder', backref = backref('parent', remote_side = [ id ]))
|
children = relationship('Folder', backref = backref('parent', remote_side = [ id ]))
|
||||||
|
|
||||||
def as_subsonic_child(self):
|
def as_subsonic_child(self, user):
|
||||||
info = {
|
info = {
|
||||||
'id': str(self.id),
|
'id': str(self.id),
|
||||||
'isDir': True,
|
'isDir': True,
|
||||||
@ -92,6 +92,10 @@ class Folder(Base):
|
|||||||
if self.has_cover_art:
|
if self.has_cover_art:
|
||||||
info['coverArt'] = str(self.id)
|
info['coverArt'] = str(self.id)
|
||||||
|
|
||||||
|
starred = StarredFolder.query.filter(StarredFolder.starred_id == self.id).filter(StarredFolder.user_id == user.id).first()
|
||||||
|
if starred:
|
||||||
|
info['starred'] = starred.date.isoformat()
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
class Artist(Base):
|
class Artist(Base):
|
||||||
@ -101,15 +105,20 @@ class Artist(Base):
|
|||||||
name = Column(String, unique = True)
|
name = Column(String, unique = True)
|
||||||
albums = relationship('Album', backref = 'artist')
|
albums = relationship('Album', backref = 'artist')
|
||||||
|
|
||||||
def as_subsonic_artist(self):
|
def as_subsonic_artist(self, user):
|
||||||
return {
|
info = {
|
||||||
'id': str(self.id),
|
'id': str(self.id),
|
||||||
'name': self.name,
|
'name': self.name,
|
||||||
# coverArt
|
# coverArt
|
||||||
'albumCount': len(self.albums)
|
'albumCount': len(self.albums)
|
||||||
# starred
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
starred = StarredArtist.query.filter(StarredArtist.starred_id == self.id).filter(StarredArtist.user_id == user.id).first()
|
||||||
|
if starred:
|
||||||
|
info['starred'] = starred.date.isoformat()
|
||||||
|
|
||||||
|
return info
|
||||||
|
|
||||||
class Album(Base):
|
class Album(Base):
|
||||||
__tablename__ = 'album'
|
__tablename__ = 'album'
|
||||||
|
|
||||||
@ -118,7 +127,7 @@ class Album(Base):
|
|||||||
artist_id = Column(UUID, ForeignKey('artist.id'))
|
artist_id = Column(UUID, ForeignKey('artist.id'))
|
||||||
tracks = relationship('Track', backref = 'album')
|
tracks = relationship('Track', backref = 'album')
|
||||||
|
|
||||||
def as_subsonic_album(self):
|
def as_subsonic_album(self, user):
|
||||||
info = {
|
info = {
|
||||||
'id': str(self.id),
|
'id': str(self.id),
|
||||||
'name': self.name,
|
'name': self.name,
|
||||||
@ -127,11 +136,14 @@ class Album(Base):
|
|||||||
'songCount': len(self.tracks),
|
'songCount': len(self.tracks),
|
||||||
'duration': sum(map(lambda t: t.duration, self.tracks)),
|
'duration': sum(map(lambda t: t.duration, self.tracks)),
|
||||||
'created': min(map(lambda t: t.created, self.tracks)).isoformat()
|
'created': min(map(lambda t: t.created, self.tracks)).isoformat()
|
||||||
# starred
|
|
||||||
}
|
}
|
||||||
if self.tracks[0].folder.has_cover_art:
|
if self.tracks[0].folder.has_cover_art:
|
||||||
info['coverArt'] = str(self.tracks[0].folder_id)
|
info['coverArt'] = str(self.tracks[0].folder_id)
|
||||||
|
|
||||||
|
starred = StarredAlbum.query.filter(StarredAlbum.starred_id == self.id).filter(StarredAlbum.user_id == user.id).first()
|
||||||
|
if starred:
|
||||||
|
info['starred'] = starred.date.isoformat()
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def sort_key(self):
|
def sort_key(self):
|
||||||
@ -163,7 +175,7 @@ class Track(Base):
|
|||||||
folder_id = Column(UUID, ForeignKey('folder.id'))
|
folder_id = Column(UUID, ForeignKey('folder.id'))
|
||||||
folder = relationship('Folder', primaryjoin = Folder.id == folder_id, backref = 'tracks')
|
folder = relationship('Folder', primaryjoin = Folder.id == folder_id, backref = 'tracks')
|
||||||
|
|
||||||
def as_subsonic_child(self):
|
def as_subsonic_child(self, user):
|
||||||
info = {
|
info = {
|
||||||
'id': str(self.id),
|
'id': str(self.id),
|
||||||
'parent': str(self.folder.id),
|
'parent': str(self.folder.id),
|
||||||
@ -193,11 +205,14 @@ class Track(Base):
|
|||||||
if self.folder.has_cover_art:
|
if self.folder.has_cover_art:
|
||||||
info['coverArt'] = str(self.folder_id)
|
info['coverArt'] = str(self.folder_id)
|
||||||
|
|
||||||
|
starred = StarredTrack.query.filter(StarredTrack.starred_id == self.id).filter(StarredTrack.user_id == user.id).first()
|
||||||
|
if starred:
|
||||||
|
info['starred'] = starred.date.isoformat()
|
||||||
|
|
||||||
# transcodedContentType
|
# transcodedContentType
|
||||||
# transcodedSuffix
|
# transcodedSuffix
|
||||||
# userRating
|
# userRating
|
||||||
# averageRating
|
# averageRating
|
||||||
# starred
|
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user