sudo-soldier commited on
Commit
fe3623b
·
verified ·
1 Parent(s): f5d080d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -6,10 +6,10 @@ import pyperclip
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
 
@@ -24,10 +24,15 @@ 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
  process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
32
  stdout, stderr = process.communicate()
33
 
@@ -94,29 +99,32 @@ def clear_input():
94
  """Clear the input and output"""
95
  return "", ""
96
 
97
- # Create the Gradio interface
98
  with gr.Blocks() as iface:
99
- # Input for URL
100
  url_input = gr.Textbox(label="Enter YouTube URL", placeholder="Paste URL here")
 
 
 
101
 
102
- # Output for status
103
  status_output = gr.Textbox(label="Status", interactive=False)
104
 
105
- # Buttons for actions
106
  download_button = gr.Button("Download Video")
107
  android_button = gr.Button("Create Android Ringtone")
108
  iphone_button = gr.Button("Create iPhone Ringtone")
109
  paste_button = gr.Button("Paste URL from Clipboard")
110
  clear_button = gr.Button("Clear")
111
 
112
- # Button click actions
113
- download_button.click(download_video, inputs=url_input, outputs=status_output)
114
  android_button.click(android_download, outputs=status_output)
115
  iphone_button.click(iphone_download, outputs=status_output)
116
  paste_button.click(paste_from_clipboard, outputs=url_input)
117
  clear_button.click(clear_input, outputs=[url_input, status_output])
118
 
119
- # Launch the interface
120
  iface.launch(share=True)
121
 
122
 
 
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
 
 
24
  except Exception as e:
25
  return f"Failed to create readme.txt: {str(e)}"
26
 
27
+ def download_video(url, cookies_path=None):
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 cookies_path:
34
+ command.extend(['--cookies', cookies_path])
35
+
36
  process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
37
  stdout, stderr = process.communicate()
38
 
 
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=[url_input, cookies_input], outputs=status_output)
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