mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Raise ExternalError for 400+ response in funkwhale
This commit is contained in:
parent
2a5a8a32c6
commit
4a2dc9c73e
7 changed files with 17 additions and 1 deletions
|
@ -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"
|
||||
|
|
|
@ -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.")
|
||||
|
|
|
@ -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.")
|
||||
|
|
|
@ -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"]))
|
||||
|
|
|
@ -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.")
|
||||
|
|
|
@ -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.")
|
||||
|
|
|
@ -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"]))
|
||||
|
|
Loading…
Reference in a new issue