mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-23 01:16:18 +00:00
API: improved client preference passing
This commit is contained in:
parent
9fd18a0d71
commit
adb4e7e89b
@ -67,11 +67,9 @@ def authorize():
|
|||||||
def get_client_prefs():
|
def get_client_prefs():
|
||||||
client = request.values['c']
|
client = request.values['c']
|
||||||
try:
|
try:
|
||||||
ClientPrefs[request.user, client]
|
request.client = ClientPrefs[request.user, client]
|
||||||
except ObjectNotFound:
|
except ObjectNotFound:
|
||||||
ClientPrefs(user = request.user, client_name = client)
|
request.client = ClientPrefs(user = request.user, client_name = client)
|
||||||
|
|
||||||
request.client = client
|
|
||||||
|
|
||||||
def get_entity(cls, param = 'id'):
|
def get_entity(cls, param = 'id'):
|
||||||
eid = request.values[param]
|
eid = request.values[param]
|
||||||
|
@ -48,7 +48,7 @@ def stream_media():
|
|||||||
dst_bitrate = res.bitrate
|
dst_bitrate = res.bitrate
|
||||||
dst_mimetype = res.content_type
|
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:
|
if prefs.format:
|
||||||
dst_suffix = prefs.format
|
dst_suffix = prefs.format
|
||||||
if prefs.bitrate and prefs.bitrate < dst_bitrate:
|
if prefs.bitrate and prefs.bitrate < dst_bitrate:
|
||||||
|
@ -172,7 +172,7 @@ class Track(db.Entity):
|
|||||||
stars = Set(lambda: StarredTrack)
|
stars = Set(lambda: StarredTrack)
|
||||||
ratings = Set(lambda: RatingTrack)
|
ratings = Set(lambda: RatingTrack)
|
||||||
|
|
||||||
def as_subsonic_child(self, user, client):
|
def as_subsonic_child(self, user, prefs):
|
||||||
info = dict(
|
info = dict(
|
||||||
id = str(self.id),
|
id = str(self.id),
|
||||||
parent = str(self.folder.id),
|
parent = str(self.folder.id),
|
||||||
@ -216,7 +216,6 @@ class Track(db.Entity):
|
|||||||
if avgRating:
|
if avgRating:
|
||||||
info['averageRating'] = 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():
|
if prefs is not None and prefs.format is not None and prefs.format != self.suffix():
|
||||||
info['transcodedSuffix'] = prefs.format
|
info['transcodedSuffix'] = prefs.format
|
||||||
info['transcodedContentType'] = mimetypes.guess_type('dummyname.' + prefs.format, False)[0] or 'application/octet-stream'
|
info['transcodedContentType'] = mimetypes.guess_type('dummyname.' + prefs.format, False)[0] or 'application/octet-stream'
|
||||||
|
@ -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.albumid) }, error = 70, skip_xsd = True)
|
||||||
self._make_request('star', { 'id': str(self.trackid) }, skip_post = True)
|
self._make_request('star', { 'id': str(self.trackid) }, skip_post = True)
|
||||||
with db_session:
|
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.trackid) }, error = 0, skip_xsd = True)
|
||||||
|
|
||||||
self._make_request('star', { 'id': str(self.folderid) }, skip_post = 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)
|
self._make_request('unstar', { 'id': str(self.trackid) }, skip_post = True)
|
||||||
with db_session:
|
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)
|
self._make_request('unstar', { 'id': str(self.folderid) }, skip_post = True)
|
||||||
with db_session:
|
with db_session:
|
||||||
@ -121,16 +123,19 @@ class AnnotationTestCase(ApiTestBase):
|
|||||||
self._make_request('setRating', { 'id': str(self.trackid), 'rating': 6 }, error = 0)
|
self._make_request('setRating', { 'id': str(self.trackid), 'rating': 6 }, error = 0)
|
||||||
|
|
||||||
with db_session:
|
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):
|
for i in range(1, 6):
|
||||||
self._make_request('setRating', { 'id': str(self.trackid), 'rating': i }, skip_post = True)
|
self._make_request('setRating', { 'id': str(self.trackid), 'rating': i }, skip_post = True)
|
||||||
with db_session:
|
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)
|
self._make_request('setRating', { 'id': str(self.trackid), 'rating': 0 }, skip_post = True)
|
||||||
with db_session:
|
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))
|
self.assertNotIn('userRating', Folder[self.folderid].as_subsonic_child(self.user))
|
||||||
for i in range(1, 6):
|
for i in range(1, 6):
|
||||||
|
Loading…
Reference in New Issue
Block a user