1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-09 19:52:16 +00:00

Implemented ''frequent'' and ''recent'' types of ''getAlbumList.view''

This commit is contained in:
Alban 2013-06-07 20:35:21 +02:00
parent 3ccafda24e
commit 3eee7416ea
3 changed files with 11 additions and 4 deletions

View File

@ -1,7 +1,7 @@
# coding: utf-8
from flask import request
from sqlalchemy import desc
from sqlalchemy import desc, func
from sqlalchemy.orm import aliased
import random
import uuid
@ -64,9 +64,9 @@ def album_list():
elif ltype == 'highest':
return request.error_formatter(0, 'Not implemented')
elif ltype == 'frequent':
return request.error_formatter(0, 'Not implemented')
query = query.join(Track, Folder.tracks).group_by(Folder.id).order_by(desc(func.sum(Track.play_count) / func.count(Folder.tracks)))
elif ltype == 'recent':
return request.error_formatter(0, 'Not implemented')
query = query.join(Track, Folder.tracks).group_by(Folder.id).order_by(desc(func.max(Track.last_play)))
elif ltype == 'starred':
return request.error_formatter(0, 'Not implemented')
elif ltype == 'alphabeticalByName':

View File

@ -7,7 +7,7 @@ from time import time as now
import config
from web import app
from db import Track, Folder, User
from db import Track, Folder, User, now, session
from api import get_entity
from lastfm import LastFm
@ -33,6 +33,10 @@ def stream_media():
# TODO transcode
pass
res.play_count = res.play_count + 1
res.last_play = now()
session.commit()
if estimateContentLength == 'true':
return send_file(res.path), 200, { 'Content-Length': os.path.getsize(res.path) }

3
db.py
View File

@ -150,6 +150,9 @@ class Track(Base):
created = Column(DateTime, default = now)
last_modification = Column(Integer)
play_count = Column(Integer, default = 0)
last_play = Column(DateTime, nullable = True)
root_folder_id = Column(UUID, ForeignKey('folder.id'))
root_folder = relationship('Folder', primaryjoin = Folder.id == root_folder_id)
folder_id = Column(UUID, ForeignKey('folder.id'))