mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
Implemented getMusicDirectory.view
This commit is contained in:
parent
e022f09db8
commit
584f1cf90c
@ -79,7 +79,31 @@ 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.album.artist.name + t.album.name + str(t.disc) + str(t.number) + t.title ) ]
|
'child': [ c.as_subsonic_child() for c in sorted(childs, key = lambda t: t.sort_key()) ]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@app.route('/rest/getMusicDirectory.view')
|
||||||
|
def show_directory():
|
||||||
|
did = request.args.get('id')
|
||||||
|
if not did:
|
||||||
|
return request.error_formatter(10, 'Missing directory id')
|
||||||
|
try:
|
||||||
|
fid = uuid.UUID(did)
|
||||||
|
except:
|
||||||
|
return request.error_formatter(0, 'Invalid directory id')
|
||||||
|
|
||||||
|
folder = Folder.query.get(fid)
|
||||||
|
if not folder:
|
||||||
|
return request.error_formatter(70, 'Directory not found')
|
||||||
|
|
||||||
|
directory = {
|
||||||
|
'id': str(folder.id),
|
||||||
|
'name': folder.name,
|
||||||
|
'child': [ f.as_subsonic_child() for f in sorted(folder.children, key = lambda c: c.name) ] + [ t.as_subsonic_child() for t in sorted(folder.tracks, key = lambda t: t.sort_key()) ]
|
||||||
|
}
|
||||||
|
if not folder.root:
|
||||||
|
directory['parent'] = str(folder.parent_id)
|
||||||
|
|
||||||
|
return request.formatter({ 'directory': directory })
|
||||||
|
|
||||||
|
15
db.py
15
db.py
@ -67,6 +67,18 @@ 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):
|
||||||
|
info = {
|
||||||
|
'id': str(self.id),
|
||||||
|
'isDir': True,
|
||||||
|
'title': self.name,
|
||||||
|
}
|
||||||
|
if not self.root:
|
||||||
|
info['parent'] = str(self.parent_id)
|
||||||
|
info['artist'] = self.parent.name
|
||||||
|
|
||||||
|
return info
|
||||||
|
|
||||||
class Artist(Base):
|
class Artist(Base):
|
||||||
__tablename__ = 'artist'
|
__tablename__ = 'artist'
|
||||||
|
|
||||||
@ -144,6 +156,9 @@ class Track(Base):
|
|||||||
ret = '%02i:%s' % (self.duration / 3600, ret)
|
ret = '%02i:%s' % (self.duration / 3600, ret)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def sort_key(self):
|
||||||
|
return self.album.artist.name + self.album.name + ("%02i" % self.disc) + ("%02i" % self.number) + self.title
|
||||||
|
|
||||||
def init_db():
|
def init_db():
|
||||||
Base.metadata.create_all(bind = engine)
|
Base.metadata.create_all(bind = engine)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user