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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -31,13 +31,13 @@ def get_input_path(video_file, video_url, temp_dir):
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")
@@ -60,7 +60,7 @@ def create_master_playlist(output_paths, temp_dir):
60
  f.write(f"{path.name}\n")
61
  return master_playlist_path
62
 
63
- def convert_video(video_file, quality, aspect_ratio, video_url):
64
  standard_resolutions = [4320, 2160, 1440, 1080, 720, 480, 360, 240, 144] # 8K, 4K, 2K, Full HD, HD, SD in pixels
65
 
66
  with tempfile.TemporaryDirectory() as temp_dir:
@@ -113,9 +113,10 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
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
@@ -158,19 +159,20 @@ def main():
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,
172
  live=False,
173
- ).launch()
174
 
175
  if __name__ == "__main__":
176
  main()
 
31
  else:
32
  raise ValueError("No input was provided.")
33
 
34
+ def upload_to_ftp(server, port, username, password, source_file, destination_file):
35
  """Uploads a file to an FTP server."""
36
  with FTP(server, username, password) as ftp:
37
+ ftp.connect(server, int(port)) # add this line to specify the port
38
  with open(source_file, 'rb') as f:
39
  ftp.storbinary(f'STOR {destination_file}', f)
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")
 
60
  f.write(f"{path.name}\n")
61
  return master_playlist_path
62
 
63
+ def convert_video(video_file, quality, aspect_ratio, video_url, ftp_server, ftp_username, ftp_password, ftp_path, upload):
64
  standard_resolutions = [4320, 2160, 1440, 1080, 720, 480, 360, 240, 144] # 8K, 4K, 2K, Full HD, HD, SD in pixels
65
 
66
  with tempfile.TemporaryDirectory() as temp_dir:
 
113
  if upload:
114
  ftp_files = []
115
  for path in [master_playlist_copy_path] + output_copy_paths:
116
+ source_file = path # This should be the full local path of the file
117
+ destination_file = ftp_path + "/" + path.name # This should be the desired remote path of the file
118
+ upload_to_ftp(ftp_server, ftp_username, ftp_password, source_file, destination_file)
119
+ ftp_files.append(destination_file)
120
  return ftp_files
121
  else:
122
  return [master_playlist_copy_path] + output_copy_paths
 
159
  video_url = gr.inputs.Textbox(label="Video URL")
160
 
161
  ftp_server = gr.inputs.Textbox(label="FTP Server")
162
+ ftp_port = gr.inputs.Textbox(label="FTP Port", placeholder="21")
163
  ftp_username = gr.inputs.Textbox(label="FTP Username")
164
+ ftp_password = gr.inputs.Textbox(label="FTP Password", type="text")
165
  ftp_path = gr.inputs.Textbox(label="FTP Path")
166
  upload = gr.inputs.Checkbox(label="Upload to FTP server", default=False)
167
 
168
  gr.Interface(
169
  convert_video,
170
  inputs=[video_file, quality, aspect_ratio, video_url, ftp_server, ftp_username, ftp_password, ftp_path, upload],
171
+ outputs=[gr.outputs.Textbox(), gr.outputs.File(), gr.outputs.Markdown()],
172
  output_processor=process_output,
173
  allow_flagging=False,
174
  live=False,
175
+ ).launch())
176
 
177
  if __name__ == "__main__":
178
  main()