1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-10-18 08:52:17 +00:00

Add ListenBrainz documentation and tests

This commit is contained in:
Iván Ávalos 2024-03-18 22:58:03 -06:00
parent a39f2fb16a
commit 0f49dfb3ac
No known key found for this signature in database
GPG Key ID: AC47C0E4F348CE33
6 changed files with 81 additions and 1 deletions

View File

@ -14,6 +14,7 @@ Current supported features are:
* cover art * cover art
* starred tracks/albums and ratings * starred tracks/albums and ratings
* [Last.fm][lastfm] scrobbling * [Last.fm][lastfm] scrobbling
* [ListenBrainz][listenbrainz] scrobbling
* Jukebox mode * Jukebox mode
Supysonic currently targets the version 1.12.0 of the Subsonic API. For more Supysonic currently targets the version 1.12.0 of the Subsonic API. For more
@ -21,6 +22,7 @@ details, go check the [API implementation status][docs-api].
[subsonic]: http://www.subsonic.org/ [subsonic]: http://www.subsonic.org/
[lastfm]: https://www.last.fm/ [lastfm]: https://www.last.fm/
[listenbrainz]: https://listenbrainz.org/
[docs-api]: https://supysonic.readthedocs.io/en/latest/api.html [docs-api]: https://supysonic.readthedocs.io/en/latest/api.html
## Documentation ## Documentation
@ -72,6 +74,6 @@ And there's also the tests (which require `lxml` to run):
$ python -m unittest tests.net.suite $ python -m unittest tests.net.suite
The last command runs a few tests that make HTTP requests to remote third-party The last command runs a few tests that make HTTP requests to remote third-party
services (namely Last.fm and ChartLyrics). services (namely Last.fm, ListenBrainz and ChartLyrics).
[flask]: https://flask.palletsprojects.com/ [flask]: https://flask.palletsprojects.com/

View File

@ -74,6 +74,11 @@ log_rotate = yes
;api_key = ;api_key =
;secret = ;secret =
[listenbrainz]
; root URL of the ListenBrainz API.
; Defaults: https://api.listenbrainz.org/
;api_url =
[transcoding] [transcoding]
; Programs used to convert from one format/bitrate to another. Defaults: none ; Programs used to convert from one format/bitrate to another. Defaults: none
transcoder_mp3_mp3 = lame --quiet --mp3input -b %outrate %srcpath - transcoder_mp3_mp3 = lame --quiet --mp3input -b %outrate %srcpath -

View File

@ -12,10 +12,12 @@ Current supported features are:
* cover art * cover art
* starred tracks/albums and ratings * starred tracks/albums and ratings
* `Last.FM`__ scrobbling * `Last.FM`__ scrobbling
* `ListenBrainz`__ scrobbling
* Jukebox mode * Jukebox mode
__ http://www.subsonic.org/ __ http://www.subsonic.org/
__ https://www.last.fm/ __ https://www.last.fm/
__ https://listenbrainz.org/
.. rubric:: User's guide .. rubric:: User's guide

View File

@ -293,6 +293,35 @@ Sample configuration::
;api_key = ;api_key =
;secret = ;secret =
.. _conf-listenbrainz:
``[listenbrainz]`` section
--------------------------
This section allows a custom ListenBrainz instance to be configured
for scrobbling. ListenBrainz is a music scrobbling service with social
features, similar to LastFM, but it is open source and
self-hostable. Supysonic can configured with any ListenBrainz
instance, but it connects to the official instance by default.
In order to connect to ListenBrainz, each user requires an user token
that can be obtained from their ListenBrainz profile (more information
in the API docs). This token has to be configured per profile using
the web UI.
The ListenBrainz API documentation can be found here:
https://listenbrainz.readthedocs.io/en/latest/users/api/index.html
``api_url``
root URL of the ListenBrainz API for the instance
Sample configuration::
[listenbrainz]
; root URL of the ListenBrainz API.
; Defaults: https://api.listenbrainz.org/
;api_url =
.. _conf-transcoding: .. _conf-transcoding:
``[transcoding]`` section ``[transcoding]`` section

View File

@ -255,6 +255,22 @@ class UserTestCase(FrontendTestBase):
rv = self.client.get("/user/me/lastfm/unlink", follow_redirects=True) rv = self.client.get("/user/me/lastfm/unlink", follow_redirects=True)
self.assertIn("Unlinked", rv.data) self.assertIn("Unlinked", rv.data)
def test_listenbrainz_link(self):
self._login("alice", "Alic3")
rv = self.client.get("/user/me/listenbrainz/link", follow_redirects=True)
self.assertIn("Missing ListenBrainz auth token", rv.data)
# # Testing this requires an HTTP request!
# rv = self.client.get(
# "/user/me/listenbrainz/link",
# query_string={"token": "abcdef"},
# follow_redirects=True,
# )
# self.assertIn("Error: ", rv.data)
def test_listenbrainz_unlink(self):
self._login("alice", "Alic3")
rv = self.client.get("/user/me/listenbrainz/unlink", follow_redirects=True)
self.assertIn("Unlinked", rv.data)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()

View File

@ -0,0 +1,26 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2017-2018 Alban 'spl0k' Féron
# Copyright (C) 2024 Iván Ávalos
#
# Distributed under terms of the GNU AGPLv3 license.
import logging
import unittest
from supysonic.listenbrainz import ListenBrainz
class ListenBrainzTestCase(unittest.TestCase):
"""Basic test of unauthenticated ListenBrainz API method"""
def test_request(self):
logging.getLogger("supysonic.listenbrainz").addHandler(logging.NullHandler())
listenbrainz = ListenBrainz({"api_url": "https://api.listenbrainz.org/"}, None)
user = "aavalos"
rv = listenbrainz._ListenBrainz__api_request(False, "/1/search/users/?search_term={0}".format(user), token="123")
self.assertIsInstance(rv, dict)
if __name__ == "__main__":
unittest.main()