Jeffgold commited on
Commit
8c8c808
·
1 Parent(s): f3b763e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -7,7 +7,7 @@ from moviepy.editor import VideoFileClip
7
  import gradio as gr
8
  import requests
9
  from urllib.parse import urlparse
10
-
11
 
12
  logging.basicConfig(level=logging.INFO)
13
 
@@ -31,6 +31,13 @@ def get_input_path(video_file, video_url, temp_dir):
31
  else:
32
  raise ValueError("No input was provided.")
33
 
 
 
 
 
 
 
 
34
  def get_output_path(input_path, temp_dir, res):
35
  """Returns the path to the output file, creating it if necessary."""
36
  output_path = temp_dir / (Path(input_path).stem + f"_{res}.m3u8")
@@ -103,6 +110,16 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
103
 
104
  output_paths.append(output_path) # Append the output_path to output_paths
105
 
 
 
 
 
 
 
 
 
 
 
106
  if not output_paths:
107
  return "The video is smaller than the smallest standard resolution."
108
 
@@ -140,9 +157,15 @@ def main():
140
  label="Aspect Ratio", default="16:9")
141
  video_url = gr.inputs.Textbox(label="Video URL")
142
 
 
 
 
 
 
 
143
  gr.Interface(
144
  convert_video,
145
- inputs=[video_file, quality, aspect_ratio, video_url],
146
  outputs=gr.outputs.Textbox(),
147
  output_processor=process_output,
148
  allow_flagging=False,
 
7
  import gradio as gr
8
  import requests
9
  from urllib.parse import urlparse
10
+ from ftplib import FTP
11
 
12
  logging.basicConfig(level=logging.INFO)
13
 
 
31
  else:
32
  raise ValueError("No input was provided.")
33
 
34
+ def upload_to_ftp(server, username, password, source_file, destination_file):
35
+ """Uploads a file to an FTP server."""
36
+ with FTP(server, username, password) as ftp:
37
+ with open(source_file, 'rb') as f:
38
+ ftp.storbinary(f'STOR {destination_file}', f)
39
+
40
+
41
  def get_output_path(input_path, temp_dir, res):
42
  """Returns the path to the output file, creating it if necessary."""
43
  output_path = temp_dir / (Path(input_path).stem + f"_{res}.m3u8")
 
110
 
111
  output_paths.append(output_path) # Append the output_path to output_paths
112
 
113
+ if upload:
114
+ ftp_files = []
115
+ for path in [master_playlist_copy_path] + output_copy_paths:
116
+ destination = ftp_path + "/" + path.name
117
+ upload_to_ftp(ftp_server, ftp_username, ftp_password, path, destination)
118
+ ftp_files.append(destination)
119
+ return ftp_files
120
+ else:
121
+ return [master_playlist_copy_path] + output_copy_paths
122
+
123
  if not output_paths:
124
  return "The video is smaller than the smallest standard resolution."
125
 
 
157
  label="Aspect Ratio", default="16:9")
158
  video_url = gr.inputs.Textbox(label="Video URL")
159
 
160
+ ftp_server = gr.inputs.Textbox(label="FTP Server")
161
+ ftp_username = gr.inputs.Textbox(label="FTP Username")
162
+ ftp_password = gr.inputs.Textbox(label="FTP Password", type="password")
163
+ ftp_path = gr.inputs.Textbox(label="FTP Path")
164
+ upload = gr.inputs.Checkbox(label="Upload to FTP server", default=False)
165
+
166
  gr.Interface(
167
  convert_video,
168
+ inputs=[video_file, quality, aspect_ratio, video_url, ftp_server, ftp_username, ftp_password, ftp_path, upload],
169
  outputs=gr.outputs.Textbox(),
170
  output_processor=process_output,
171
  allow_flagging=False,