Skip to content

Instantly share code, notes, and snippets.

@aliakseis
Created March 6, 2025 13:45
Show Gist options
  • Save aliakseis/cd370f1b82694e33a17706cba569a622 to your computer and use it in GitHub Desktop.
Save aliakseis/cd370f1b82694e33a17706cba569a622 to your computer and use it in GitHub Desktop.
Asyncio
import asyncio
import yt_dlp
def progress_hook(d):
if d['status'] == 'downloading':
print(f"Downloaded {d['downloaded_bytes']} bytes of {d['total_bytes']} bytes")
async def download_video(url):
ydl_opts = {
'format': 'best',
'outtmpl': '%(title)s.%(ext)s',
'progress_hooks': [progress_hook],
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
await asyncio.to_thread(ydl.download, [url])
async def main():
url = 'https://www.youtube.com/watch?v=qwerttyuiop'
await download_video(url)
# Run the main function
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment