diff --git a/supysonic/api/browse.py b/supysonic/api/browse.py index 9da8a25..21ae316 100644 --- a/supysonic/api/browse.py +++ b/supysonic/api/browse.py @@ -96,7 +96,7 @@ def show_directory(): @api.route('/getGenres.view', methods = [ 'GET', 'POST' ]) def list_genres(): return request.formatter('genres', dict( - genre = [ dict(_value_ = genre) for genre in select(t.genre for t in Track if t.genre) ] + genre = [ dict(value = genre) for genre in select(t.genre for t in Track if t.genre) ] )) @api.route('/getArtists.view', methods = [ 'GET', 'POST' ]) diff --git a/supysonic/api/formatters.py b/supysonic/api/formatters.py index 779a87f..59241b0 100644 --- a/supysonic/api/formatters.py +++ b/supysonic/api/formatters.py @@ -99,7 +99,7 @@ class XMLFormatter(BaseFormatter): raise TypeError('Dictionary keys must be strings') for name, value in dictionary.items(): - if name == '_value_': + if name == 'value': elem.text = self.__value_tostring(value) elif isinstance(value, dict): subelem = ElementTree.SubElement(elem, name) diff --git a/supysonic/api/media.py b/supysonic/api/media.py index e1ab163..3749d36 100644 --- a/supysonic/api/media.py +++ b/supysonic/api/media.py @@ -224,7 +224,7 @@ def lyrics(): return request.formatter('lyrics', dict( artist = track.album.artist.name, title = track.title, - _value_ = lyrics + value = lyrics )) try: @@ -236,7 +236,7 @@ def lyrics(): return request.formatter('lyrics', dict( artist = root.find('cl:LyricArtist', namespaces = ns).text, title = root.find('cl:LyricSong', namespaces = ns).text, - _value_ = root.find('cl:Lyric', namespaces = ns).text + value = root.find('cl:Lyric', namespaces = ns).text )) except requests.exceptions.RequestException as e: # pragma: nocover logger.warning('Error while requesting the ChartLyrics API: ' + str(e)) diff --git a/tests/api/test_media.py b/tests/api/test_media.py index 142ca80..6348e70 100644 --- a/tests/api/test_media.py +++ b/tests/api/test_media.py @@ -8,6 +8,7 @@ # # Distributed under terms of the GNU AGPLv3 license. +import flask.json import os.path import requests import uuid @@ -171,6 +172,12 @@ class MediaTestCase(ApiTestBase): # ChartLyrics rv, child = self._make_request('getLyrics', { 'artist': 'The Clash', 'title': 'London Calling' }, tag = 'lyrics') self.assertIn('live by the river', child.text) + # ChartLyrics, JSON format + args = { 'u': 'alice', 'p': 'Alic3', 'c': 'tests', 'f': 'json', 'artist': 'The Clash', 'title': 'London Calling' } + rv = self.client.get('/rest/getLyrics.view', query_string = args) + json = flask.json.loads(rv.data) + self.assertIn('value', json['subsonic-response']['lyrics']) + self.assertIn('live by the river', json['subsonic-response']['lyrics']['value']) # Local file rv, child = self._make_request('getLyrics', { 'artist': 'artist', 'title': '23bytes' }, tag = 'lyrics') diff --git a/tests/api/test_response_helper.py b/tests/api/test_response_helper.py index fec69c2..360eede 100644 --- a/tests/api/test_response_helper.py +++ b/tests/api/test_response_helper.py @@ -192,7 +192,7 @@ class ResponseHelperXMLTestCase(TestBase, UnwrapperMixin.create_from(XMLFormatte def test_nesting(self): resp = self.process_and_extract({ 'dict': { - 'value': 'hey look! a string', + 'somevalue': 'hey look! a string', 'list': [ 1, 2, 3 ], 'emptyList': [], 'subdict': { 'a': 'A' } @@ -210,7 +210,7 @@ class ResponseHelperXMLTestCase(TestBase, UnwrapperMixin.create_from(XMLFormatte lists = resp.findall('./list') self.assertIsNotNone(d) - self.assertAttributesMatchDict(d, { 'value': 'hey look! a string' }) + self.assertAttributesMatchDict(d, { 'somevalue': 'hey look! a string' }) self.assertEqual(len(d.findall('./list')), 3) self.assertEqual(len(d.findall('./emptyList')), 0) self.assertIsNotNone(d.find('./subdict'))