Created
March 6, 2025 13:45
-
-
Save aliakseis/cd370f1b82694e33a17706cba569a622 to your computer and use it in GitHub Desktop.
Asyncio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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