from .. import helpers from .findSong import * from requests import get from random import randint as rand def getPreview(request): beatmapId = helpers.getFromRequest(request, "beatmapId") query = helpers.getFromRequest(request, "query") if beatmapId != None: tryment = get(f"https://b.ppy.sh/preview/{beatmapId}.mp3") if int(tryment.status_code) not in [404, 403]: return {"status": "pass", "details": {"code": int(tryment.status_code), "result": f"https://b.ppy.sh/preview/{beatmapId}.mp3"}} else: return {"status": "error", "details": {"code": int(tryment.status_code), "answer": tryment.text}}, 400 elif query != None: fffff = findSong(request) if fffff['status'] == "error": return fffff, 400 rBId = fffff['details']['result'][rand(0,len(fffff['details']['result'])-1)]['beatmapId'] return {"status": "pass", "details": {"code": fffff['details']['code'], "name": "{rBId}.mp3", "result": f"https://b.ppy.sh/preview/{rBId}.mp3"}} return {"status": "error", "details": { "error_code": 133, "error_details": "No details for finding preview" }}, 400