feat: download songs asyncronously
This commit is contained in:
parent
e984e70390
commit
2286d7a8d5
2 changed files with 7 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import asyncio
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import yt_dlp
|
import yt_dlp
|
||||||
|
@ -22,8 +23,11 @@ class DownloadService:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.ydl = yt_dlp.YoutubeDL(ydl_opts)
|
self.ydl = yt_dlp.YoutubeDL(ydl_opts)
|
||||||
|
|
||||||
def download(self, url: str) -> Track:
|
async def download(self, url: str) -> Track:
|
||||||
info = self.ydl.extract_info(url, download=True)
|
def extract():
|
||||||
|
return self.ydl.extract_info(url, download=True)
|
||||||
|
|
||||||
|
info = await asyncio.to_thread(extract)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
filepath = info["requested_downloads"][-1]["filepath"] # type: ignore
|
filepath = info["requested_downloads"][-1]["filepath"] # type: ignore
|
||||||
|
|
2
main.py
2
main.py
|
@ -128,7 +128,7 @@ def get_queue():
|
||||||
|
|
||||||
@app.post("/queue", tags=["queue"])
|
@app.post("/queue", tags=["queue"])
|
||||||
async def post_to_queue(url: str):
|
async def post_to_queue(url: str):
|
||||||
track = dl_service.download(url)
|
track = await dl_service.download(url)
|
||||||
await player.add_to_queue(track)
|
await player.add_to_queue(track)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue