Временно переделал downloader и youtube

возможно потребуется перенести yt-dlp в консоль, и работать через stdout
This commit is contained in:
Viner Abubakirov
2026-02-18 20:54:28 +05:00
parent 0cf412ea1e
commit cfc068e857
3 changed files with 55 additions and 21 deletions

View File

@@ -4,24 +4,31 @@ from app.utils.uploader import ChunkUploadBackend
class HttpStreamingDownloader:
def __init__(self, backend: ChunkUploadBackend, chunk_size: int = 1024**2):
def __init__(self, backend: ChunkUploadBackend):
self.backend = backend
self.chunk_size = chunk_size
def download(self, url: str, filename: str, headers: dict = {}):
def download(
self,
url: str,
filename: str,
headers: dict = {},
chunk_size: int = 1024**2,
):
self.backend.start(filename)
# http = httpx.Client(http2=True)
http = httpx
http = httpx.Client(http2=True)
try:
print("Try to download")
with http.stream("GET", url, timeout=20, headers=headers) as response:
response.raise_for_status()
total = int(response.headers.get("Content-Length", 0))
with tqdm(total=total, unit="B", unit_scale=True, desc=filename) as pbar:
for chunk in response.iter_bytes(self.chunk_size):
with tqdm(
total=total, unit="B", unit_scale=True, desc=filename
) as pbar:
for chunk in response.iter_bytes(chunk_size):
if chunk:
self.backend.upload_chunk(chunk)
pbar.update(len(chunk)) # обновляем прогресс по размеру чанка
# обновляем прогресс по размеру чанка
pbar.update(len(chunk))
self.backend.finish()
except: