funapi / routes /osuApi /findSong.py
imperialwool's picture
removing signature and supporting only post
367be45
raw
history blame
1.07 kB
from .. import helpers
from requests import get
from random import randint as rand
def findSong(request):
query = helpers.getFromRequest(request, "query")
if not query: return {"status": "error", "details": { "error_code": 133, "error_details": "No query" }}, 400
tryment = get("https://api.chimu.moe/v1/search", params={"query": query})
if int(tryment.status_code) not in [404, 403]:
res = []
counter = 0
for chunk in tryment.json()['data']:
res.append({
"beatmapId": chunk['SetId'],
"artist": chunk['Artist'],
"title": chunk['Title'],
"creator": chunk['Creator'],
"source": chunk['Source'],
"tags": chunk['Tags']
})
counter += 1
if counter >= rand(3,7): break
return {"status": "pass", "details": {"code": int(tryment.status_code), "result": res}}
else:
return {"status": "error", "details": {"code": int(tryment.status_code), "answer": tryment.text}}, 400