Jeffgold commited on
Commit
d7f009b
·
1 Parent(s): b14e2a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -97,6 +97,12 @@ def upload_file_to_s3(file_path, s3_path):
97
  file.write(file_content)
98
 
99
  def convert_video(video_file, quality, aspect_ratio, video_url):
 
 
 
 
 
 
100
  input_path = get_input_path(video_file, video_url)
101
 
102
  video = VideoFileClip(str(input_path))
@@ -128,16 +134,17 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
128
  master_playlist_path = create_master_playlist(output_paths, Path(input_path).stem)
129
  output_paths.append(master_playlist_path)
130
 
131
- server_ip = get_ip_address()
132
  output_links = []
133
  for path in output_paths:
134
- output_links.append(f'<a href="http://{server_ip}:8000{path}" target="_blank">Download {Path(path).stem}</a>')
135
- print("Read local file")
136
- upload_file_to_s3(path, f"s3://{AWS_S3_BUCKET}/{Path(path).stem}")
137
 
138
  # upload ts files to s3
139
  for path in output_dir.glob(f"{Path(input_path).stem}_*p_*.ts"):
140
- upload_file_to_s3(path, f"s3://{AWS_S3_BUCKET}/{Path(path).stem}")
 
 
141
 
142
  output_html = "<br>".join(output_links)
143
  return output_html
 
97
  file.write(file_content)
98
 
99
  def convert_video(video_file, quality, aspect_ratio, video_url):
100
+
101
+ def convert_video(video_file, quality, aspect_ratio, video_url):
102
+ # Ensure either a file or a URL is provided
103
+ if not video_file and not video_url:
104
+ raise ValueError("Please provide either a video file or a video URL.")
105
+
106
  input_path = get_input_path(video_file, video_url)
107
 
108
  video = VideoFileClip(str(input_path))
 
134
  master_playlist_path = create_master_playlist(output_paths, Path(input_path).stem)
135
  output_paths.append(master_playlist_path)
136
 
 
137
  output_links = []
138
  for path in output_paths:
139
+ s3_path = f"s3://{AWS_S3_BUCKET}/{Path(input_path).stem}/{Path(path).stem}"
140
+ upload_file_to_s3(path, s3_path)
141
+ output_links.append(f'<a href="https://s3-us-east-1.amazonaws.com/{AWS_S3_BUCKET}/{Path(input_path).stem}/{Path(path).stem}" target="_blank">Download {Path(path).stem}</a>')
142
 
143
  # upload ts files to s3
144
  for path in output_dir.glob(f"{Path(input_path).stem}_*p_*.ts"):
145
+ s3_path = f"s3://{AWS_S3_BUCKET}/{Path(input_path).stem}/{Path(path).stem.split('_')[1]}/{Path(path).stem}"
146
+ upload_file_to_s3(path, s3_path)
147
+ output_links.append(f'<a href="https://s3-us-east-1.amazonaws.com/{AWS_S3_BUCKET}/{Path(input_path).stem}/{Path(path).stem.split('_')[1]}/{Path(path).stem}" target="_blank">Download {Path(path).stem}</a>')
148
 
149
  output_html = "<br>".join(output_links)
150
  return output_html