Spaces:
Build error
Build error
File size: 2,280 Bytes
55afdee | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | import gradio as gr
import webbrowser
import threading
from process import *
from extra import *
install_miyuki()
# Load existing queue
download_queue = load_queue()
def open_browser():
webbrowser.open("http://127.0.0.1:7860")
def add_to_queue(video_url, quality):
if not video_url.startswith("http"):
return "Error: Please enter a valid URL."
if video_url in download_queue:
return "Warning: This URL is already in the queue."
download_queue[video_url] = {
"URL": video_url,
"Status": "Not Started",
"Log": ""
}
save_queue(download_queue)
return f"Added {video_url} to the queue."
def start_download():
for url, task in download_queue.items():
if task["Status"] == "Not Started":
status, log = download_file(url, "720")
download_queue[url]["Status"] = status
download_queue[url]["Log"] = log
save_queue(download_queue)
return "Downloads started."
def view_queue():
return [(url, data["Status"]) for url, data in download_queue.items()]
def check_status():
for url, task in download_queue.items():
if task["Status"] in ["Downloading", "Not Started"]:
status, log = check_task_status(url, task["Log"])
download_queue[url]["Status"] = status
download_queue[url]["Log"] = log
save_queue(download_queue)
return "Queue status updated."
with gr.Blocks() as app:
gr.Markdown("# Miyuki GUI Downloader")
with gr.Row():
video_url = gr.Textbox(label="Video URL")
quality = gr.Dropdown(["360", "480", "720"], label="Quality", value="360")
add_button = gr.Button("Add to Queue")
start_button = gr.Button("Start Download")
add_button.click(add_to_queue, inputs=[video_url, quality], outputs=None)
start_button.click(start_download, outputs=None)
check_button = gr.Button("Check Status")
check_button.click(check_status, outputs=None)
queue_list = gr.Dataframe(headers=["URL", "Status"], datatype=["str", "str"], label="Download Queue")
view_button = gr.Button("View Queue")
view_button.click(view_queue, outputs=queue_list)
threading.Thread(target=open_browser).start()
app.launch()
|