Skip to content

Commit

Permalink
Run the project through an up-to-date black
Browse files Browse the repository at this point in the history
  • Loading branch information
spl0k committed May 19, 2024
1 parent f12e403 commit df51cab
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 49 deletions.
8 changes: 5 additions & 3 deletions supysonic/api/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ def __remove_empty_lists(self, d):
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
]

Expand Down
16 changes: 10 additions & 6 deletions supysonic/api/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
},
Expand All @@ -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]
],
},
Expand Down
8 changes: 5 additions & 3 deletions supysonic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions supysonic/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,11 @@ def as_subsonic_playlist(self, user):
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),
Expand Down
56 changes: 31 additions & 25 deletions supysonic/listenbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

logger = logging.getLogger(__name__)


class ListenBrainz:
def __init__(self, config, user):
if config["api_url"] is not None:
Expand All @@ -39,7 +40,6 @@ def link_account(self, token):
else:
return False, f"Error: {res['message']}"


def unlink_account(self):
self.__user.listenbrainz_session = None
self.__user.listenbrainz_status = True
Expand All @@ -54,17 +54,19 @@ def now_playing(self, track):
"/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):
Expand All @@ -76,18 +78,20 @@ def scrobble(self, track, ts):
"/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):
Expand All @@ -103,18 +107,20 @@ def __api_request(self, write, route, token, **kwargs):
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", "")
Expand Down
8 changes: 4 additions & 4 deletions supysonic/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def __init__(self, *args, **kwargs):
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)

Expand Down
6 changes: 2 additions & 4 deletions supysonic/server/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ def __init__(
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()
Expand Down
1 change: 1 addition & 0 deletions tests/frontend/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,6 @@ def test_listenbrainz_unlink(self):
rv = self.client.get("/user/me/listenbrainz/unlink", follow_redirects=True)
self.assertIn("Unlinked", rv.data)


if __name__ == "__main__":
unittest.main()
6 changes: 5 additions & 1 deletion tests/net/test_listenbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ..frontend.frontendtestbase import FrontendTestBase


class ListenBrainzTestCase(unittest.TestCase):
"""Basic test of unauthenticated ListenBrainz API method"""

Expand All @@ -21,9 +22,12 @@ def test_request(self):
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")
Expand Down

0 comments on commit df51cab

Please sign in to comment.