Эта библиотека удобна для API-сервисов, потому что функция download возвращает MP4-байты в памяти, а не только путь к файлу.
download
from fastapi import FastAPI, HTTPException from fastapi.responses import Response from yt_shorts_downloader import download from yt_shorts_downloader.exceptions import YtShortsDownloaderError app = FastAPI() @app.get('/download') def download_short(url: str) -> Response: try: video = download(url, 'cookies.txt') except YtShortsDownloaderError as exc: raise HTTPException(status_code=400, detail=str(exc)) from exc return Response( content=video.content, media_type=video.media_type, headers={ 'Content-Disposition': f'attachment; filename="{video.filename}"', }, )
str(exc)
Deleting the wiki page "FastAPI Integration" cannot be undone. Continue?