1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 17:06:17 +00:00

Converting api:media retreival

This commit is contained in:
spl0k 2014-03-30 17:53:54 +02:00
parent ce7aa7ed71
commit 09ffacd49c

View File

@ -27,12 +27,10 @@ import codecs
from xml.etree import ElementTree from xml.etree import ElementTree
import config, scanner import config, scanner
from web import app from web import app, store
from db import Track, Album, Artist, Folder, User, ClientPrefs, now, session from db import Track, Album, Artist, Folder, User, ClientPrefs, now
from . import get_entity from . import get_entity
from sqlalchemy import func
def prepare_transcoding_cmdline(base_cmdline, input_file, input_format, output_format, output_bitrate): def prepare_transcoding_cmdline(base_cmdline, input_file, input_format, output_format, output_bitrate):
if not base_cmdline: if not base_cmdline:
return None return None
@ -57,10 +55,10 @@ def stream_media():
dst_mimetype = res.content_type dst_mimetype = res.content_type
if client: if client:
prefs = ClientPrefs.query.get((request.user.id, client)) prefs = store.get(ClientPrefs, (request.user.id, client))
if not prefs: if not prefs:
prefs = ClientPrefs(user_id = request.user.id, client_name = client) prefs = ClientPrefs(user_id = request.user.id, client_name = client)
session.add(prefs) store.add(prefs)
if prefs.format: if prefs.format:
dst_suffix = prefs.format dst_suffix = prefs.format
@ -117,7 +115,7 @@ def stream_media():
res.last_play = now() res.last_play = now()
request.user.last_play = res request.user.last_play = res
request.user.last_play_date = now() request.user.last_play_date = now()
session.commit() store.commit()
return response return response
@ -170,7 +168,7 @@ def lyrics():
if not title: if not title:
return request.error_formatter(10, 'Missing title parameter') 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: for track in query:
lyrics_path = os.path.splitext(track.path)[0] + '.txt' lyrics_path = os.path.splitext(track.path)[0] + '.txt'
if os.path.exists(lyrics_path): if os.path.exists(lyrics_path):