Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,13 +6,16 @@ import pyperclip
|
|
6 |
|
7 |
logging.basicConfig(level=logging.INFO)
|
8 |
|
9 |
-
|
10 |
DOWNLOAD_FOLDER = './output'
|
11 |
|
12 |
-
|
13 |
if not os.path.exists(DOWNLOAD_FOLDER):
|
14 |
os.makedirs(DOWNLOAD_FOLDER)
|
15 |
|
|
|
|
|
|
|
16 |
def create_readme():
|
17 |
"""Creates a readme.txt file with the specified text"""
|
18 |
readme_path = os.path.join(DOWNLOAD_FOLDER, 'readme.txt')
|
@@ -24,14 +27,16 @@ def create_readme():
|
|
24 |
except Exception as e:
|
25 |
return f"Failed to create readme.txt: {str(e)}"
|
26 |
|
27 |
-
def download_video(url
|
28 |
try:
|
29 |
output_path = os.path.join(DOWNLOAD_FOLDER, '%(title)s.mp4')
|
30 |
command = ['yt-dlp', '-f', 'mp4', '-o', output_path, url]
|
31 |
|
32 |
-
|
33 |
-
if
|
34 |
-
command.extend(['--cookies',
|
|
|
|
|
35 |
|
36 |
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
37 |
stdout, stderr = process.communicate()
|
@@ -99,32 +104,29 @@ def clear_input():
|
|
99 |
"""Clear the input and output"""
|
100 |
return "", ""
|
101 |
|
102 |
-
|
103 |
with gr.Blocks() as iface:
|
104 |
-
|
105 |
url_input = gr.Textbox(label="Enter YouTube URL", placeholder="Paste URL here")
|
106 |
-
|
107 |
-
|
108 |
-
cookies_input = gr.Textbox(label="Cookies File Path", placeholder="Enter path to cookies.txt (optional)")
|
109 |
|
110 |
-
|
111 |
status_output = gr.Textbox(label="Status", interactive=False)
|
112 |
|
113 |
-
|
114 |
download_button = gr.Button("Download Video")
|
115 |
android_button = gr.Button("Create Android Ringtone")
|
116 |
iphone_button = gr.Button("Create iPhone Ringtone")
|
117 |
paste_button = gr.Button("Paste URL from Clipboard")
|
118 |
clear_button = gr.Button("Clear")
|
119 |
|
120 |
-
|
121 |
-
download_button.click(download_video, inputs=
|
122 |
android_button.click(android_download, outputs=status_output)
|
123 |
iphone_button.click(iphone_download, outputs=status_output)
|
124 |
paste_button.click(paste_from_clipboard, outputs=url_input)
|
125 |
clear_button.click(clear_input, outputs=[url_input, status_output])
|
126 |
|
127 |
-
|
128 |
iface.launch(share=True)
|
129 |
|
130 |
|
@@ -132,7 +134,3 @@ iface.launch(share=True)
|
|
132 |
|
133 |
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
6 |
|
7 |
logging.basicConfig(level=logging.INFO)
|
8 |
|
9 |
+
# Use the current working directory (Hugging Face compatible)
|
10 |
DOWNLOAD_FOLDER = './output'
|
11 |
|
12 |
+
# Ensure the directory exists
|
13 |
if not os.path.exists(DOWNLOAD_FOLDER):
|
14 |
os.makedirs(DOWNLOAD_FOLDER)
|
15 |
|
16 |
+
# Specify the path for the cookies file (assuming it's in the same directory as this script)
|
17 |
+
COOKIES_PATH = './cookies.txt'
|
18 |
+
|
19 |
def create_readme():
|
20 |
"""Creates a readme.txt file with the specified text"""
|
21 |
readme_path = os.path.join(DOWNLOAD_FOLDER, 'readme.txt')
|
|
|
27 |
except Exception as e:
|
28 |
return f"Failed to create readme.txt: {str(e)}"
|
29 |
|
30 |
+
def download_video(url):
|
31 |
try:
|
32 |
output_path = os.path.join(DOWNLOAD_FOLDER, '%(title)s.mp4')
|
33 |
command = ['yt-dlp', '-f', 'mp4', '-o', output_path, url]
|
34 |
|
35 |
+
# Add cookies to the yt-dlp command
|
36 |
+
if os.path.exists(COOKIES_PATH):
|
37 |
+
command.extend(['--cookies', COOKIES_PATH])
|
38 |
+
else:
|
39 |
+
return f"Error: Cookies file {COOKIES_PATH} not found."
|
40 |
|
41 |
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
42 |
stdout, stderr = process.communicate()
|
|
|
104 |
"""Clear the input and output"""
|
105 |
return "", ""
|
106 |
|
107 |
+
# Create the Gradio interface
|
108 |
with gr.Blocks() as iface:
|
109 |
+
# Input for URL
|
110 |
url_input = gr.Textbox(label="Enter YouTube URL", placeholder="Paste URL here")
|
|
|
|
|
|
|
111 |
|
112 |
+
# Output for status
|
113 |
status_output = gr.Textbox(label="Status", interactive=False)
|
114 |
|
115 |
+
# Buttons for actions
|
116 |
download_button = gr.Button("Download Video")
|
117 |
android_button = gr.Button("Create Android Ringtone")
|
118 |
iphone_button = gr.Button("Create iPhone Ringtone")
|
119 |
paste_button = gr.Button("Paste URL from Clipboard")
|
120 |
clear_button = gr.Button("Clear")
|
121 |
|
122 |
+
# Button click actions
|
123 |
+
download_button.click(download_video, inputs=url_input, outputs=status_output)
|
124 |
android_button.click(android_download, outputs=status_output)
|
125 |
iphone_button.click(iphone_download, outputs=status_output)
|
126 |
paste_button.click(paste_from_clipboard, outputs=url_input)
|
127 |
clear_button.click(clear_input, outputs=[url_input, status_output])
|
128 |
|
129 |
+
# Launch the interface
|
130 |
iface.launch(share=True)
|
131 |
|
132 |
|
|
|
134 |
|
135 |
|
136 |
|
|
|
|
|
|
|
|