Spaces:
Runtime error
Runtime error
File size: 1,756 Bytes
66ca64a 367be45 66ca64a 367be45 09f5da5 66ca64a 367be45 66ca64a f02b1de 66ca64a f02b1de 66ca64a f02b1de 66ca64a 367be45 f02b1de |
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 |
import os
import yt_dlp
from .. import helpers
def get(request, check = "huh"):
url = helpers.getFromRequest(request, "url")
if not url: return {"status": "error", "details": { "error_code": 101, "error_details": "No link provided" }}, 400
bitrate = helpers.getFromRequest(request, "bitrate")
if not bitrate: bitrate = "64k"
quality = helpers.getFromRequest(request, "quality")
if not quality or quality.lower() not in ['best', 'worst']: quality = 'worst'
else: quality = quality.lower()
urlcode = url.partition('?v=')[2]
if not urlcode: urlcode = "NPRNRQh2fAo"
config = helpers.configFile()
if os.path.exists(f"{config['static-path']}/{check}/{urlcode}.ogg"):
return {"status": "pass", 'done-or-not': True, 'ytdlp-code': 0, 'urlcode': urlcode, "path": f"{config['static-path']}/{check}/{urlcode}.ogg", "quality": quality, "bitrate": bitrate}
if os.path.exists(f"{config['temp-path']}/{urlcode}.ogg"):
return {"status": "pass", 'done-or-not': False, 'ytdlp-code': 0, 'urlcode': urlcode, "path": f"{config['temp-path']}/{urlcode}.ogg", "quality": quality, "bitrate": bitrate}
ydl_opts = {
'format': f'ogg/{quality}audio/{quality}',
'outtmpl': f"{config['temp-path']}/{urlcode}.ogg",
'progress_hooks': [helpers.thisIsHook],
}
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
error_code = ydl.download(url)
except Exception as e: return {"status": "error", "details": {"error_code": 102, "error_details": str(e)}}, 400
return {"status": "pass", 'done-or-not': False, 'ytdlp-code': error_code, 'urlcode': urlcode, "path": f"{config['temp-path']}/{urlcode}.ogg", "quality": quality, "bitrate": bitrate} |