From 09ffacd49c8999555b0b34262001a2c610800a74 Mon Sep 17 00:00:00 2001 From: spl0k Date: Sun, 30 Mar 2014 17:53:54 +0200 Subject: [PATCH] Converting api:media retreival --- api/media.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/api/media.py b/api/media.py index 3ff1be2..8457cb5 100644 --- a/api/media.py +++ b/api/media.py @@ -27,12 +27,10 @@ import codecs from xml.etree import ElementTree import config, scanner -from web import app -from db import Track, Album, Artist, Folder, User, ClientPrefs, now, session +from web import app, store +from db import Track, Album, Artist, Folder, User, ClientPrefs, now from . import get_entity -from sqlalchemy import func - def prepare_transcoding_cmdline(base_cmdline, input_file, input_format, output_format, output_bitrate): if not base_cmdline: return None @@ -57,10 +55,10 @@ def stream_media(): dst_mimetype = res.content_type if client: - prefs = ClientPrefs.query.get((request.user.id, client)) + prefs = store.get(ClientPrefs, (request.user.id, client)) if not prefs: prefs = ClientPrefs(user_id = request.user.id, client_name = client) - session.add(prefs) + store.add(prefs) if prefs.format: dst_suffix = prefs.format @@ -117,7 +115,7 @@ def stream_media(): res.last_play = now() request.user.last_play = res request.user.last_play_date = now() - session.commit() + store.commit() return response @@ -170,7 +168,7 @@ def lyrics(): if not title: return request.error_formatter(10, 'Missing title parameter') - query = Track.query.join(Album, Artist).filter(func.lower(Track.title) == title.lower() and func.lower(Artist.name) == artist.lower()) + query = store.find(Track, Album.id == Track.album_id, Artist.id == Album.artist_id, Track.title.like(title), Artist.name.like(artist)) for track in query: lyrics_path = os.path.splitext(track.path)[0] + '.txt' if os.path.exists(lyrics_path):