mirror of
https://github.com/spl0k/supysonic.git
synced 2025-01-02 22:36:18 +00:00
Run the project through an up-to-date black
This commit is contained in:
parent
f12e403c67
commit
df51cabb41
@ -42,9 +42,11 @@ class JSONBaseFormatter(BaseFormatter):
|
||||
keys_to_remove.append(key)
|
||||
else:
|
||||
d[key] = [
|
||||
self.__remove_empty_lists(item)
|
||||
if isinstance(item, dict)
|
||||
else item
|
||||
(
|
||||
self.__remove_empty_lists(item)
|
||||
if isinstance(item, dict)
|
||||
else item
|
||||
)
|
||||
for item in value
|
||||
]
|
||||
|
||||
|
@ -67,9 +67,11 @@ def old_search():
|
||||
"totalHits": folders.count() + tracks.count(),
|
||||
"offset": offset,
|
||||
"match": [
|
||||
r.as_subsonic_child(request.user)
|
||||
if isinstance(r, Folder)
|
||||
else r.as_subsonic_child(request.user, request.client)
|
||||
(
|
||||
r.as_subsonic_child(request.user)
|
||||
if isinstance(r, Folder)
|
||||
else r.as_subsonic_child(request.user, request.client)
|
||||
)
|
||||
for r in res
|
||||
],
|
||||
},
|
||||
@ -83,9 +85,11 @@ def old_search():
|
||||
"totalHits": query.count(),
|
||||
"offset": offset,
|
||||
"match": [
|
||||
r.as_subsonic_child(request.user)
|
||||
if isinstance(r, Folder)
|
||||
else r.as_subsonic_child(request.user, request.client)
|
||||
(
|
||||
r.as_subsonic_child(request.user)
|
||||
if isinstance(r, Folder)
|
||||
else r.as_subsonic_child(request.user, request.client)
|
||||
)
|
||||
for r in query[offset : offset + count]
|
||||
],
|
||||
},
|
||||
|
@ -41,9 +41,11 @@ class DefaultConfig:
|
||||
"online_lyrics": False,
|
||||
}
|
||||
DAEMON = {
|
||||
"socket": r"\\.\pipe\supysonic"
|
||||
if sys.platform == "win32"
|
||||
else os.path.join(tempdir, "supysonic.sock"),
|
||||
"socket": (
|
||||
r"\\.\pipe\supysonic"
|
||||
if sys.platform == "win32"
|
||||
else os.path.join(tempdir, "supysonic.sock")
|
||||
),
|
||||
"run_watcher": True,
|
||||
"wait_delay": 5,
|
||||
"jukebox_command": None,
|
||||
|
@ -539,9 +539,11 @@ class Playlist(_Model):
|
||||
tracks = self.get_tracks()
|
||||
info = {
|
||||
"id": str(self.id),
|
||||
"name": self.name
|
||||
if self.user.id == user.id
|
||||
else f"[{self.user.name}] {self.name}",
|
||||
"name": (
|
||||
self.name
|
||||
if self.user.id == user.id
|
||||
else f"[{self.user.name}] {self.name}"
|
||||
),
|
||||
"owner": self.user.name,
|
||||
"public": self.public,
|
||||
"songCount": len(tracks),
|
||||
|
@ -14,6 +14,7 @@ from urllib.parse import urljoin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ListenBrainz:
|
||||
def __init__(self, config, user):
|
||||
if config["api_url"] is not None:
|
||||
@ -39,7 +40,6 @@ class ListenBrainz:
|
||||
else:
|
||||
return False, f"Error: {res['message']}"
|
||||
|
||||
|
||||
def unlink_account(self):
|
||||
self.__user.listenbrainz_session = None
|
||||
self.__user.listenbrainz_status = True
|
||||
@ -54,17 +54,19 @@ class ListenBrainz:
|
||||
"/1/submit-listens",
|
||||
self.__user.listenbrainz_session,
|
||||
listen_type="playing_now",
|
||||
payload=[{
|
||||
"track_metadata": {
|
||||
"artist_name": track.album.artist.name,
|
||||
"track_name": track.title,
|
||||
"release_name": track.album.name,
|
||||
"additional_info": {
|
||||
"media_player": "Supysonic",
|
||||
"duration_ms": track.duration,
|
||||
payload=[
|
||||
{
|
||||
"track_metadata": {
|
||||
"artist_name": track.album.artist.name,
|
||||
"track_name": track.title,
|
||||
"release_name": track.album.name,
|
||||
"additional_info": {
|
||||
"media_player": "Supysonic",
|
||||
"duration_ms": track.duration,
|
||||
},
|
||||
},
|
||||
},
|
||||
}]
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
def scrobble(self, track, ts):
|
||||
@ -76,18 +78,20 @@ class ListenBrainz:
|
||||
"/1/submit-listens",
|
||||
self.__user.listenbrainz_session,
|
||||
listen_type="single",
|
||||
payload=[{
|
||||
"listened_at": ts,
|
||||
"track_metadata": {
|
||||
"artist_name": track.album.artist.name,
|
||||
"track_name": track.title,
|
||||
"release_name": track.album.name,
|
||||
"additional_info": {
|
||||
"media_player": "Supysonic",
|
||||
"duration_ms": track.duration,
|
||||
payload=[
|
||||
{
|
||||
"listened_at": ts,
|
||||
"track_metadata": {
|
||||
"artist_name": track.album.artist.name,
|
||||
"track_name": track.title,
|
||||
"release_name": track.album.name,
|
||||
"additional_info": {
|
||||
"media_player": "Supysonic",
|
||||
"duration_ms": track.duration,
|
||||
},
|
||||
},
|
||||
},
|
||||
}]
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
def __api_request(self, write, route, token, **kwargs):
|
||||
@ -103,18 +107,20 @@ class ListenBrainz:
|
||||
urljoin(self.__api_url, route),
|
||||
headers=headers,
|
||||
data=json.dumps(kwargs),
|
||||
timeout=5)
|
||||
timeout=5,
|
||||
)
|
||||
else:
|
||||
r = requests.get(
|
||||
urljoin(self.__api_url, route),
|
||||
headers=headers,
|
||||
data=json.dumps(kwargs),
|
||||
timeout=5)
|
||||
timeout=5,
|
||||
)
|
||||
|
||||
r.raise_for_status()
|
||||
except requests.HTTPError as e:
|
||||
status_code = e.response.status_code
|
||||
if status_code == 401: # Unauthorized
|
||||
if status_code == 401: # Unauthorized
|
||||
self.__user.listenbrainz_status = False
|
||||
self.__user.save()
|
||||
message = e.response.json().get("error", "")
|
||||
|
@ -27,10 +27,10 @@ class MutuallyExclusiveOption(Option):
|
||||
help = kwargs.get("help", "")
|
||||
if self.mutually_exclusive:
|
||||
ex_str = ", ".join(self.mutually_exclusive)
|
||||
kwargs[
|
||||
"help"
|
||||
] = "{} NOTE: This argument is mutually exclusive with arguments: [{}].".format(
|
||||
help, ex_str
|
||||
kwargs["help"] = (
|
||||
"{} NOTE: This argument is mutually exclusive with arguments: [{}].".format(
|
||||
help, ex_str
|
||||
)
|
||||
)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
@ -21,12 +21,10 @@ class BaseServer(metaclass=ABCMeta):
|
||||
self._threads = threads
|
||||
|
||||
@abstractmethod
|
||||
def _build_kwargs(self):
|
||||
...
|
||||
def _build_kwargs(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def _run(self, **kwargs):
|
||||
...
|
||||
def _run(self, **kwargs): ...
|
||||
|
||||
def _load_app(self):
|
||||
return create_application()
|
||||
|
@ -260,5 +260,6 @@ class UserTestCase(FrontendTestBase):
|
||||
rv = self.client.get("/user/me/listenbrainz/unlink", follow_redirects=True)
|
||||
self.assertIn("Unlinked", rv.data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@ -13,6 +13,7 @@ from supysonic.listenbrainz import ListenBrainz
|
||||
|
||||
from ..frontend.frontendtestbase import FrontendTestBase
|
||||
|
||||
|
||||
class ListenBrainzTestCase(unittest.TestCase):
|
||||
"""Basic test of unauthenticated ListenBrainz API method"""
|
||||
|
||||
@ -21,9 +22,12 @@ class ListenBrainzTestCase(unittest.TestCase):
|
||||
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")
|
||||
rv = listenbrainz._ListenBrainz__api_request(
|
||||
False, "/1/search/users/?search_term={0}".format(user), token="123"
|
||||
)
|
||||
self.assertIsInstance(rv, dict)
|
||||
|
||||
|
||||
class FrontendListenBrainzCase(FrontendTestBase):
|
||||
def test_listenbrainz_link(self):
|
||||
self._login("alice", "Alic3")
|
||||
|
Loading…
Reference in New Issue
Block a user