File size: 1,151 Bytes
66ca64a
 
 
 
 
367be45
 
 
66ca64a
f02b1de
66ca64a
f02b1de
66ca64a
367be45
 
66ca64a
367be45
f0b744f
 
367be45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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