Нужно асинхронно скачать видео
import asyncio
import aiofiles
from aiohttp import ClientSession
async def main():
session = ClientSession()
file_path = "video.mp4"
url = "https://rr3---sn-ap4xjxaa-3c2e.googlevideo.com/videoplayback?expire=1665583187&ei=83NGY6W2I9C91gKArK6IAQ&ip=46.96.167.234&id=o-ADON-FqU8-wK3yafCF77nd0aFd3TRDZ8-gmKtSz-jUWK&itag=140&source=youtube&requiressl=yes&mh=xS&mm=31%2C29&mn=sn-ap4xjxaa-3c2e%2Csn-3c27sn7l&ms=au%2Crdu&mv=m&mvi=3&pcm2cms=yes&pl=20&gcr=ua&initcwndbps=270000&vprv=1&mime=audio%2Fmp4&gir=yes&clen=3140460&dur=193.911&lmt=1582397768595649&mt=1665561202&fvip=7&keepalive=yes&fexp=24001373%2C24007246&c=ANDROID&txp=5531432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cgcr%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAK5_1NAxHqlNU_y7u38ArLVY6bPdYJZZRG7rDP_jzqyaAiEAuBlNXF8DUuJTzNL-PzeuMXe0_irBhHLCMKB3DIFl2os%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpcm2cms%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgfMrfO7jxfJT8eGkLfqY_9J3hxbEIgTRczgZfe9Jwsv0CIQDP4xlYm_9BFrpiSBiucg2gbnH6KUD3Hk2du0INgaUF5A%3D%3D"
async with ClientSession() as session:
async with session.get(url=url, ssl=False) as response:
async with aiofiles.open(file_path, 'wb') as f:
while True:
chunk = await response.content.read(1024*1024)
f.write(chunk)
if not chunk:
break
asyncio.run(main())
Сделал что-то такое, работает очень медленно.
Почему, и как сделать правильно?