From 3eee7416eaec4e0c0e142d82608775b0bc0ea911 Mon Sep 17 00:00:00 2001 From: Alban Date: Fri, 7 Jun 2013 20:35:21 +0200 Subject: [PATCH] Implemented ''frequent'' and ''recent'' types of ''getAlbumList.view'' --- api/albums_songs.py | 6 +++--- api/media.py | 6 +++++- db.py | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/api/albums_songs.py b/api/albums_songs.py index 110ec5d..ad2a763 100755 --- a/api/albums_songs.py +++ b/api/albums_songs.py @@ -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': diff --git a/api/media.py b/api/media.py index 96bde9b..2af667c 100755 --- a/api/media.py +++ b/api/media.py @@ -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) } diff --git a/db.py b/db.py index 6088e10..ef0a35e 100755 --- a/db.py +++ b/db.py @@ -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'))