feat: download songs asyncronously

This commit is contained in:
Radu C. Martin 2025-04-15 14:11:25 +02:00
parent e984e70390
commit 2286d7a8d5
2 changed files with 7 additions and 3 deletions

View file

@ -1,3 +1,4 @@
import asyncio
import sys
import yt_dlp
@ -22,8 +23,11 @@ class DownloadService:
def __init__(self) -> None:
self.ydl = yt_dlp.YoutubeDL(ydl_opts)
def download(self, url: str) -> Track:
info = self.ydl.extract_info(url, download=True)
async def download(self, url: str) -> Track:
def extract():
return self.ydl.extract_info(url, download=True)
info = await asyncio.to_thread(extract)
try:
filepath = info["requested_downloads"][-1]["filepath"] # type: ignore