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

API: improved client preference passing

This commit is contained in:
spl0k 2018-03-10 18:35:00 +01:00
parent 9fd18a0d71
commit adb4e7e89b
4 changed files with 14 additions and 12 deletions

View File

@ -67,11 +67,9 @@ def authorize():
def get_client_prefs():
client = request.values['c']
try:
ClientPrefs[request.user, client]
request.client = ClientPrefs[request.user, client]
except ObjectNotFound:
ClientPrefs(user = request.user, client_name = client)
request.client = client
request.client = ClientPrefs(user = request.user, client_name = client)
def get_entity(cls, param = 'id'):
eid = request.values[param]

View File

@ -48,7 +48,7 @@ def stream_media():
dst_bitrate = res.bitrate
dst_mimetype = res.content_type
prefs = ClientPrefs.get(lambda p: p.user.id == request.user.id and p.client_name == request.client)
prefs = request.client
if prefs.format:
dst_suffix = prefs.format
if prefs.bitrate and prefs.bitrate < dst_bitrate:

View File

@ -172,7 +172,7 @@ class Track(db.Entity):
stars = Set(lambda: StarredTrack)
ratings = Set(lambda: RatingTrack)
def as_subsonic_child(self, user, client):
def as_subsonic_child(self, user, prefs):
info = dict(
id = str(self.id),
parent = str(self.folder.id),
@ -216,7 +216,6 @@ class Track(db.Entity):
if avgRating:
info['averageRating'] = avgRating
prefs = ClientPrefs.get(lambda p: p.user.id == user.id and p.client_name == client)
if prefs is not None and prefs.format is not None and prefs.format != self.suffix():
info['transcodedSuffix'] = prefs.format
info['transcodedContentType'] = mimetypes.guess_type('dummyname.' + prefs.format, False)[0] or 'application/octet-stream'

View File

@ -60,7 +60,8 @@ class AnnotationTestCase(ApiTestBase):
self._make_request('star', { 'id': str(self.albumid) }, error = 70, skip_xsd = True)
self._make_request('star', { 'id': str(self.trackid) }, skip_post = True)
with db_session:
self.assertIn('starred', Track[self.trackid].as_subsonic_child(self.user, 'tests'))
prefs = ClientPrefs.get(lambda p: p.user.name == 'alice' and p.client_name == 'tests')
self.assertIn('starred', Track[self.trackid].as_subsonic_child(self.user, prefs))
self._make_request('star', { 'id': str(self.trackid) }, error = 0, skip_xsd = True)
self._make_request('star', { 'id': str(self.folderid) }, skip_post = True)
@ -94,7 +95,8 @@ class AnnotationTestCase(ApiTestBase):
self._make_request('unstar', { 'id': str(self.trackid) }, skip_post = True)
with db_session:
self.assertNotIn('starred', Track[self.trackid].as_subsonic_child(self.user, 'tests'))
prefs = ClientPrefs.get(lambda p: p.user.name == 'alice' and p.client_name == 'tests')
self.assertNotIn('starred', Track[self.trackid].as_subsonic_child(self.user, prefs))
self._make_request('unstar', { 'id': str(self.folderid) }, skip_post = True)
with db_session:
@ -121,16 +123,19 @@ class AnnotationTestCase(ApiTestBase):
self._make_request('setRating', { 'id': str(self.trackid), 'rating': 6 }, error = 0)
with db_session:
self.assertNotIn('userRating', Track[self.trackid].as_subsonic_child(self.user, 'tests'))
prefs = ClientPrefs.get(lambda p: p.user.name == 'alice' and p.client_name == 'tests')
self.assertNotIn('userRating', Track[self.trackid].as_subsonic_child(self.user, prefs))
for i in range(1, 6):
self._make_request('setRating', { 'id': str(self.trackid), 'rating': i }, skip_post = True)
with db_session:
self.assertEqual(Track[self.trackid].as_subsonic_child(self.user, 'tests')['userRating'], i)
prefs = ClientPrefs.get(lambda p: p.user.name == 'alice' and p.client_name == 'tests')
self.assertEqual(Track[self.trackid].as_subsonic_child(self.user, prefs)['userRating'], i)
self._make_request('setRating', { 'id': str(self.trackid), 'rating': 0 }, skip_post = True)
with db_session:
self.assertNotIn('userRating', Track[self.trackid].as_subsonic_child(self.user, 'tests'))
prefs = ClientPrefs.get(lambda p: p.user.name == 'alice' and p.client_name == 'tests')
self.assertNotIn('userRating', Track[self.trackid].as_subsonic_child(self.user, prefs))
self.assertNotIn('userRating', Folder[self.folderid].as_subsonic_child(self.user))
for i in range(1, 6):