ytdlqueue: add

This commit is contained in:
Lukáš Kucharczyk 2023-12-29 11:25:27 +01:00
parent 523f959ad3
commit 7ff425cb2f
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 50 additions and 0 deletions

50
ytdlqueue.py Normal file
View File

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