From 7ff425cb2fe1102af0564797270e89edb169d794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Fri, 29 Dec 2023 11:25:27 +0100 Subject: [PATCH] ytdlqueue: add --- ytdlqueue.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 ytdlqueue.py diff --git a/ytdlqueue.py b/ytdlqueue.py new file mode 100644 index 0000000..84e46ed --- /dev/null +++ b/ytdlqueue.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import subprocess +import sys +import time +from queue import Queue +from threading import Thread + +# Queue to hold the URLs +download_queue = Queue() + +def download_video(url): + """ + Function to download a video using youtube-dl. + """ + try: + print(f"Downloading {url}...") + subprocess.run(["yt-dlp", url], check=True) + print(f"Finished downloading {url}") + except subprocess.CalledProcessError as e: + print(f"Failed to download {url}: {e}") + +def worker(): + """ + Worker function to process items in the queue. + """ + while True: + url = download_queue.get() + download_video(url) + download_queue.task_done() + +def main(): + # Start the worker thread + thread = Thread(target=worker) + thread.daemon = True + thread.start() + + print("Enter URLs to download. Type 'exit' to quit.") + while True: + url = input("URL: ").strip() + if url.lower() == 'exit': + break + download_queue.put(url) + + # Wait for all downloads to finish + download_queue.join() + +if __name__ == "__main__": + main() +