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