1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Raise ExternalError for 400+ response in funkwhale

This commit is contained in:
Steffo 2020-05-28 16:51:48 +02:00
parent 2a5a8a32c6
commit 4a2dc9c73e
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
7 changed files with 17 additions and 1 deletions

View file

@ -1,2 +1,2 @@
git commit -am "publish: %1"
git push && poetry build && poetry publish && hub release create "%1" -m "Royalnet %1"
git push && poetry build && poetry publish && hub release create "%1" -m "Royalnet %1" && sentry-cli releases deploys "%1" new --env production -n "GitHub %1"

View file

@ -23,6 +23,8 @@ class FunkwhaleCommand(PlayCommand):
async with aiohttp.ClientSession() as session:
async with session.get(self.config["Funkwhale"]["instance_url"] +
f"/api/v1/search?query={search}") as response:
if response.status >= 400:
raise rc.ExternalError(f"Request returned {response.status}")
j = await response.json()
if len(j["tracks"]) < 1:
raise rc.UserError("Nessun file audio trovato con il nome richiesto.")

View file

@ -23,6 +23,8 @@ class FunkwhalealbumCommand(PlayCommand):
async with aiohttp.ClientSession() as session:
async with session.get(self.config["Funkwhale"]["instance_url"] +
f"/api/v1/search?query={search}") as response:
if response.status >= 400:
raise rc.ExternalError(f"Request returned {response.status}")
j = await response.json()
if len(j["albums"]) < 1:
raise rc.UserError("Nessun file audio trovato con il nome richiesto.")

View file

@ -23,6 +23,8 @@ class FunkwhaleplaylistCommand(PlayCommand):
async with aiohttp.ClientSession() as session:
async with session.get(self.config["Funkwhale"]["instance_url"] +
f"/api/v1/playlists/?q={search}&ordering=-creation_date&playable=true") as response:
if response.status >= 400:
raise rc.ExternalError(f"Request returned {response.status}")
j = await response.json()
if len(j["results"]) < 1:
raise rc.UserError("Nessuna playlist trovata con il nome richiesto.")
@ -30,5 +32,7 @@ class FunkwhaleplaylistCommand(PlayCommand):
playlist_id = playlist["id"]
async with session.get(self.config["Funkwhale"]["instance_url"] +
f"/api/v1/playlists/{playlist_id}/tracks") as response:
if response.status >= 400:
raise rc.ExternalError(f"Request returned {response.status}")
j = await response.json()
return list(map(lambda t: f'{self.config["Funkwhale"]["instance_url"]}{t["track"]["listen_url"]}', j["results"]))

View file

@ -23,6 +23,8 @@ class LazyfunkwhaleCommand(LazyplayCommand):
async with aiohttp.ClientSession() as session:
async with session.get(self.config["Funkwhale"]["instance_url"] +
f"/api/v1/search?query={search}") as response:
if response.status >= 400:
raise rc.ExternalError(f"Request returned {response.status}")
j = await response.json()
if len(j["tracks"]) < 1:
raise rc.UserError("Nessun file audio trovato con il nome richiesto.")

View file

@ -23,6 +23,8 @@ class LazyfunkwhalealbumCommand(LazyplayCommand):
async with aiohttp.ClientSession() as session:
async with session.get(self.config["Funkwhale"]["instance_url"] +
f"/api/v1/search?query={search}") as response:
if response.status >= 400:
raise rc.ExternalError(f"Request returned {response.status}")
j = await response.json()
if len(j["albums"]) < 1:
raise rc.UserError("Nessun file audio trovato con il nome richiesto.")

View file

@ -21,6 +21,8 @@ class LazyfunkwhaleplaylistCommand(LazyplayCommand):
async with aiohttp.ClientSession() as session:
async with session.get(self.config["Funkwhale"]["instance_url"] +
f"/api/v1/playlists/?q={search}&ordering=-creation_date&playable=true") as response:
if response.status >= 400:
raise rc.ExternalError(f"Request returned {response.status}")
j = await response.json()
if len(j["results"]) < 1:
raise rc.UserError("Nessuna playlist trovata con il nome richiesto.")
@ -28,5 +30,7 @@ class LazyfunkwhaleplaylistCommand(LazyplayCommand):
playlist_id = playlist["id"]
async with session.get(self.config["Funkwhale"]["instance_url"] +
f"/api/v1/playlists/{playlist_id}/tracks") as response:
if response.status >= 400:
raise rc.ExternalError(f"Request returned {response.status}")
j = await response.json()
return list(map(lambda t: f'{self.config["Funkwhale"]["instance_url"]}{t["track"]["listen_url"]}', j["results"]))