Jeffgold commited on
Commit
1cec1d6
·
1 Parent(s): d6ab5d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -71,7 +71,7 @@ def get_input_path(video_file, video_url):
71
  raise ValueError("No input was provided.")
72
 
73
  def get_output_path(input_path, res):
74
- output_path = output_dir / (Path(input_path).stem + f"_{res}p.m3u8")
75
  return output_path
76
 
77
  def create_master_playlist(output_paths, input_filename):
@@ -84,8 +84,8 @@ def create_master_playlist(output_paths, input_filename):
84
  # read the .m3u8 file and replace relative links with absolute links
85
  with open(path, 'r') as playlist_file:
86
  content = playlist_file.readlines()
87
- # replace .ts extension with complete URL pointing to the TS segments on S3
88
- content = [f"https://{AWS_S3_BUCKET}.s3.amazonaws.com/{quote_plus(input_filename)}/{res}/{quote_plus(line.rstrip())}\n" if line.endswith('.ts\n') else line for line in content]
89
  f.writelines(content)
90
  return master_playlist_path
91
 
@@ -132,23 +132,20 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
132
  master_playlist_path = create_master_playlist(output_paths, Path(input_path).stem)
133
  output_paths.append(master_playlist_path)
134
 
135
- output_links = []
136
  for path in output_paths:
137
- res_folder = Path(path).stem.split("_")[1] if "_" in Path(path).stem else ""
138
- s3_path = f"s3://{AWS_S3_BUCKET}/{quote_plus(Path(input_path).stem)}/{res_folder}/{quote_plus(Path(path).name)}"
139
  upload_file_to_s3(path, s3_path)
140
- output_links.append(f'<a href="https://{AWS_S3_BUCKET}.s3.amazonaws.com/{quote_plus(Path(input_path).stem)}/{res_folder}/{quote_plus(Path(path).name)}" target="_blank">Download {Path(path).stem}</a>')
141
 
142
  # upload ts files to s3
143
  for path in output_dir.glob(f"{Path(input_path).stem}_*p_*.ts"):
144
- res_folder = Path(path).stem.split("_")[1]
145
- s3_path = f"s3://{AWS_S3_BUCKET}/{quote_plus(Path(input_path).stem)}/{res_folder}/{quote_plus(Path(path).name)}"
146
  upload_file_to_s3(path, s3_path)
147
 
148
  output_html = "<br>".join(output_links)
149
  return output_html
150
 
151
-
152
  video_file = gr.inputs.File(label="Your video file")
153
  quality = gr.inputs.Slider(minimum=1, maximum=50, label="Quality (1:Speed - 50:Quality)")
154
  aspect_ratio = gr.inputs.Dropdown(["16:9", "4:3", "1:1", "3:4", "9:16", "1:1", "2:1", "1:2"], label="Aspect Ratio", default="16:9")
 
71
  raise ValueError("No input was provided.")
72
 
73
  def get_output_path(input_path, res):
74
+ output_path = output_dir / f"{Path(input_path).stem}_{res}p.m3u8"
75
  return output_path
76
 
77
  def create_master_playlist(output_paths, input_filename):
 
84
  # read the .m3u8 file and replace relative links with absolute links
85
  with open(path, 'r') as playlist_file:
86
  content = playlist_file.readlines()
87
+ content = [line.replace('.ts', f'.ts\n') if line.endswith('.ts\n') else line for line in content]
88
+ content = [f"{quote_plus(line.rstrip())}\n" if line.endswith('.ts\n') else line for line in content]
89
  f.writelines(content)
90
  return master_playlist_path
91
 
 
132
  master_playlist_path = create_master_playlist(output_paths, Path(input_path).stem)
133
  output_paths.append(master_playlist_path)
134
 
135
+ output_links = []
136
  for path in output_paths:
137
+ s3_path = f"s3://{AWS_S3_BUCKET}/{Path(input_path).stem}/{Path(path).name}"
 
138
  upload_file_to_s3(path, s3_path)
139
+ output_links.append(f'<a href="https://{AWS_S3_BUCKET}.s3.amazonaws.com/{Path(input_path).stem}/{quote_plus(Path(path).name)}" target="_blank">Download {Path(path).stem}</a>')
140
 
141
  # upload ts files to s3
142
  for path in output_dir.glob(f"{Path(input_path).stem}_*p_*.ts"):
143
+ s3_path = f"s3://{AWS_S3_BUCKET}/{Path(input_path).stem}/{Path(path).name}"
 
144
  upload_file_to_s3(path, s3_path)
145
 
146
  output_html = "<br>".join(output_links)
147
  return output_html
148
 
 
149
  video_file = gr.inputs.File(label="Your video file")
150
  quality = gr.inputs.Slider(minimum=1, maximum=50, label="Quality (1:Speed - 50:Quality)")
151
  aspect_ratio = gr.inputs.Dropdown(["16:9", "4:3", "1:1", "3:4", "9:16", "1:1", "2:1", "1:2"], label="Aspect Ratio", default="16:9")