1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-23 01:16:18 +00:00

Fixed getNowPlaying

This commit is contained in:
spl0k 2014-07-27 15:05:00 +02:00
parent 0bd788b74d
commit dd79c4d750

View File

@ -21,6 +21,7 @@
from flask import request from flask import request
from storm.expr import Desc, Avg, Min, Max from storm.expr import Desc, Avg, Min, Max
from storm.info import ClassAlias from storm.info import ClassAlias
from datetime import timedelta
import random import random
import uuid import uuid
@ -165,15 +166,14 @@ 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():
# TODO test this, test this, test this query = store.find(User, Track.id == User.last_play_id)
query = store.find(User, Track.id == User.last_play_id, ((Track.duration * 2) + User.last_play_date) < now())
return request.formatter({ return request.formatter({
'nowPlaying': { 'nowPlaying': {
'entry': [ dict( 'entry': [ dict(
u.last_play.as_subsonic_child(request.user).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 if u.last_play_date + timedelta(seconds = u.last_play.duration * 2) > now() ]
} }
}) })