Spaces:
Running
Running
File size: 2,677 Bytes
66ca64a 367be45 66ca64a f02b1de 66ca64a f02b1de 66ca64a f02b1de 66ca64a f02b1de 66ca64a 367be45 66ca64a f0b744f f02b1de 66ca64a f02b1de 66ca64a f02b1de f0b744f 66ca64a 367be45 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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 |