mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
Started implementing getAlbumList.view
This commit is contained in:
parent
f938e34b0a
commit
004ad255b3
@ -1,11 +1,14 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
from flask import request
|
from flask import request
|
||||||
from web import app
|
from sqlalchemy import desc
|
||||||
from db import Track
|
from sqlalchemy.orm import aliased
|
||||||
import random
|
import random
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from web import app
|
||||||
|
from db import Track, Folder
|
||||||
|
|
||||||
@app.route('/rest/getRandomSongs.view', methods = [ 'GET', 'POST' ])
|
@app.route('/rest/getRandomSongs.view', methods = [ 'GET', 'POST' ])
|
||||||
def rand_songs():
|
def rand_songs():
|
||||||
size = request.args.get('size', '10')
|
size = request.args.get('size', '10')
|
||||||
@ -39,3 +42,44 @@ def rand_songs():
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@app.route('/rest/getAlbumList.view', methods = [ 'GET', 'POST' ])
|
||||||
|
def album_list():
|
||||||
|
ltype, size, offset = map(request.args.get, [ 'type', 'size', 'offset' ])
|
||||||
|
try:
|
||||||
|
size = int(size) if size else 10
|
||||||
|
offset = int(offset) if offset else 0
|
||||||
|
except:
|
||||||
|
return request.error_formatter(0, 'Invalid parameter format')
|
||||||
|
|
||||||
|
query = Folder.query.filter(Folder.tracks.any())
|
||||||
|
if ltype == 'random':
|
||||||
|
albums = query.all()
|
||||||
|
return request.formatter({
|
||||||
|
'albumList': {
|
||||||
|
'album': [ random.choice(albums).as_subsonic_child() for x in xrange(size) ]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
elif ltype == 'newest':
|
||||||
|
query = query.order_by(desc(Folder.created))
|
||||||
|
elif ltype == 'highest':
|
||||||
|
return request.error_formatter(0, 'Not implemented')
|
||||||
|
elif ltype == 'frequent':
|
||||||
|
return request.error_formatter(0, 'Not implemented')
|
||||||
|
elif ltype == 'recent':
|
||||||
|
return request.error_formatter(0, 'Not implemented')
|
||||||
|
elif ltype == 'starred':
|
||||||
|
return request.error_formatter(0, 'Not implemented')
|
||||||
|
elif ltype == 'alphabeticalByName':
|
||||||
|
query = query.order_by(Folder.name)
|
||||||
|
elif ltype == 'alphabeticalByArtist':
|
||||||
|
parent = aliased(Folder)
|
||||||
|
query = query.join(parent, Folder.parent).order_by(parent.name).order_by(Folder.name)
|
||||||
|
else:
|
||||||
|
return request.error_formatter(0, 'Unknown search type')
|
||||||
|
|
||||||
|
return request.formatter({
|
||||||
|
'albumList': {
|
||||||
|
'album': [ f.as_subsonic_child() for f in query.limit(size).offset(offset) ]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user