funapi / routes /osuApi /getFull.py
imperialwool's picture
removing signature and supporting only post
367be45
raw
history blame
2.68 kB
import os
import ffmpeg
from .. import helpers
from .findSong import *
from requests import get
from random import randint as rand
def getFull(request):
beatmapId = helpers.getFromRequest(request, "beatmapId")
query = helpers.getFromRequest(request, "query")
config = helpers.configFile()
if beatmapId != None:
if os.path.exists(f"{config['full-path']}/{beatmapId}.ogg"):
return {"status": "pass", "details": {"code": 200, "result": f"{config['url']}/static/full/{beatmapId}.ogg"}}
tryment = get(f"https://kitsu.moe/api/audio/{beatmapId}", allow_redirects=True)
if int(tryment.status_code) not in [404, 403, 429]:
open(f"{config['temp-path']}/{beatmapId}.mp3", "wb").write(tryment.content)
audio_input = ffmpeg.input(f"{config['temp-path']}/{beatmapId}.mp3")
audio_output = ffmpeg.output(audio_input, f"{config['full-path']}/{beatmapId}.ogg", audio_bitrate="96K")
ffmpeg.run(audio_output)
helpers.deleteAudio(f"temp/{beatmapId}.ogg")
return {"status": "pass", "details": {"code": int(tryment.status_code), "result": f"{config['url']}/static/full/{beatmapId}.ogg"}}
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
beatmapId = fffff['details']['result'][rand(0,len(fffff['details']['result'])-1)]['beatmapId']
if os.path.exists(f"{config['full-path']}/{beatmapId}.ogg"):
return {"status": "pass", "details": {"code": 200, "result": f"{config['url']}/static/full/{beatmapId}.ogg"}}
tryment = get(f"https://kitsu.moe/api/audio/{beatmapId}", allow_redirects=True)
if int(tryment.status_code) not in [404, 403, 429]:
open(f"{config['temp-path']}/{beatmapId}.mp3", "wb").write(tryment.content)
audio_input = ffmpeg.input(f"{config['temp-path']}/{beatmapId}.mp3")
audio_output = ffmpeg.output(audio_input, f"{config['full-path']}/{beatmapId}.ogg", audio_bitrate="96K")
ffmpeg.run(audio_output)
helpers.deleteAudio(f"temp/{beatmapId}.ogg")
return {"status": "pass", "details": {"code": int(tryment.status_code), "name": f"{beatmapId}.ogg", "result": f"{config['url']}/static/full/{beatmapId}.ogg"}}
else:
return {"status": "error", "details": {"code": int(tryment.status_code), "answer": tryment.text}}, 400
return {"status": "error", "details": { "error_code": 133, "error_details": "No details for finding preview" }}, 400