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() +