Spaces:
Running
Running
File size: 1,963 Bytes
a39dd78 66ca64a a39dd78 86d1f26 a39dd78 af98f80 86d1f26 a39dd78 66ca64a f02b1de a39dd78 66ca64a a39dd78 5000d91 a39dd78 66ca64a a39dd78 |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import os
import yt_dlp
from .. import helpers
def getFull(request):
error_code = None
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()
audioformat = helpers.getFromRequest(request, "extension")
if not audioformat or audioformat.lower() not in ['m4a', 'aac', 'mp3', 'ogg', 'opus', 'webm']:
audioformat = 'ogg'
else: audioformat = audioformat.lower()
urlcode = url.partition('?v=')[2]
if not urlcode: urlcode = "NPRNRQh2fAo"
config = helpers.configFile()
if os.path.exists(f"{config['full-path']}/{urlcode}.{audioformat}"):
return {
"status": "pass",
"details": {
"code": error_code,
"name":f"{urlcode}.{audioformat}",
"result": f"{config['url']}/static/full/{urlcode}.{audioformat}"
}
}
ydl_opts = {
'format': f'{audioformat}/{quality}audio/{quality}',
'outtmpl': f"{config['full-path']}/{urlcode}.{audioformat}",
'progress_hooks': [helpers.thisIsHook],
"extractor_args": {"youtube": {"player_client": ['ios']}},
}
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",
"details": {
"code": error_code,
"name":f"{urlcode}.{audioformat}",
"result": f"{config['url']}/static/full/{urlcode}.{audioformat}"
}
} |