RandomPersonRR commited on
Commit
d7ae8bc
·
verified ·
1 Parent(s): 7100b64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -109,14 +109,14 @@ async def convert_stream(
109
  try:
110
  # SOURCE
111
  if use_youtube:
112
- yield None, None, None, "Starting YouTube download..."
113
  out_uuid = uuid.uuid4().hex
114
  out_template = str(UPLOAD_FOLDER / f"{out_uuid}.%(ext)s")
115
  ytdlp_cmd = ["yt-dlp", "-f", "b", "-o", out_template, youtube_url]
116
  stdout, stderr, rc = await run_command_capture(ytdlp_cmd)
117
  files = list(UPLOAD_FOLDER.glob(f"{out_uuid}.*"))
118
  if not files:
119
- yield None, None, None, "Failed to download YouTube video."
120
  return
121
  input_path = files[0]
122
  temp_files.append(input_path)
@@ -134,12 +134,12 @@ async def convert_stream(
134
  wav_tmp = CONVERTED_FOLDER / f"{uuid.uuid4().hex}.wav"
135
 
136
  # Step1: generate WAV
137
- yield None, None, None, "Generating WAV for AAC..."
138
  ffmpeg_wav_cmd = ["ffmpeg", "-y", "-i", str(input_path), "-ac", "1", "-ar", "8000", str(wav_tmp)]
139
  await run_command_capture(ffmpeg_wav_cmd)
140
 
141
  # Step2: fdkaac
142
- yield None, None, None, "Encoding AAC via fdkaac..."
143
  fdkaac_cmd = [
144
  "./fdkaac", "-b", "1k", "-C", "-f", "2", "-G", "1", "-w", "8000",
145
  "-o", str(out_audio), str(wav_tmp)
@@ -149,13 +149,13 @@ async def convert_stream(
149
  try: wav_tmp.unlink()
150
  except: pass
151
 
152
- yield None, str(out_audio), str(out_audio), "AAC conversion complete!"
153
  return
154
 
155
  # FULL VIDEO
156
  out_audio = CONVERTED_FOLDER / f"{uuid.uuid4().hex}.m4a"
157
  # Step1: encode audio
158
- yield None, None, None, "Encoding audio track..."
159
  if use_mp3:
160
  out_audio = CONVERTED_FOLDER / f"{uuid.uuid4().hex}.mp3"
161
  ffmpeg_audio_cmd = ["ffmpeg", "-y", "-i", str(input_path), "-ac", "1", "-ar", "24k",
@@ -174,7 +174,7 @@ async def convert_stream(
174
 
175
  # Step2: encode video
176
  out_video = CONVERTED_FOLDER / f"{uuid.uuid4().hex}.mp4"
177
- yield None, None, None, "Encoding video track..."
178
  ffmpeg_video_cmd = ["ffmpeg", "-y", "-hwaccel", ACCEL, "-i", str(input_path)]
179
  if downscale: ffmpeg_video_cmd += ["-vf", "scale=-2:144"]
180
  if custom_bitrate and video_bitrate: ffmpeg_video_cmd += ["-b:v", f"{int(video_bitrate)}k"]
@@ -185,7 +185,7 @@ async def convert_stream(
185
 
186
  # Step3: merge
187
  merged_out = CONVERTED_FOLDER / f"{uuid.uuid4().hex}.mp4"
188
- yield None, None, None, "Merging audio & video..."
189
  merge_cmd = ["ffmpeg", "-y", "-i", str(out_video), "-i", str(out_audio), "-c", "copy", str(merged_out)]
190
  stdout, stderr, rc = await run_command_capture(merge_cmd)
191
  if rc != 0:
@@ -197,7 +197,7 @@ async def convert_stream(
197
  try: f.unlink()
198
  except: pass
199
 
200
- yield str(merged_out), str(merged_out), str(merged_out), "Conversion complete!"
201
  return
202
 
203
  finally:
 
109
  try:
110
  # SOURCE
111
  if use_youtube:
112
+ yield None, None, "Starting YouTube download..."
113
  out_uuid = uuid.uuid4().hex
114
  out_template = str(UPLOAD_FOLDER / f"{out_uuid}.%(ext)s")
115
  ytdlp_cmd = ["yt-dlp", "-f", "b", "-o", out_template, youtube_url]
116
  stdout, stderr, rc = await run_command_capture(ytdlp_cmd)
117
  files = list(UPLOAD_FOLDER.glob(f"{out_uuid}.*"))
118
  if not files:
119
+ yield None, None, "Failed to download YouTube video."
120
  return
121
  input_path = files[0]
122
  temp_files.append(input_path)
 
134
  wav_tmp = CONVERTED_FOLDER / f"{uuid.uuid4().hex}.wav"
135
 
136
  # Step1: generate WAV
137
+ yield None, None, "Generating WAV for AAC..."
138
  ffmpeg_wav_cmd = ["ffmpeg", "-y", "-i", str(input_path), "-ac", "1", "-ar", "8000", str(wav_tmp)]
139
  await run_command_capture(ffmpeg_wav_cmd)
140
 
141
  # Step2: fdkaac
142
+ yield None, None, "Encoding AAC via fdkaac..."
143
  fdkaac_cmd = [
144
  "./fdkaac", "-b", "1k", "-C", "-f", "2", "-G", "1", "-w", "8000",
145
  "-o", str(out_audio), str(wav_tmp)
 
149
  try: wav_tmp.unlink()
150
  except: pass
151
 
152
+ yield str(out_audio), str(out_audio), "AAC conversion complete!"
153
  return
154
 
155
  # FULL VIDEO
156
  out_audio = CONVERTED_FOLDER / f"{uuid.uuid4().hex}.m4a"
157
  # Step1: encode audio
158
+ yield None, None, "Encoding audio track..."
159
  if use_mp3:
160
  out_audio = CONVERTED_FOLDER / f"{uuid.uuid4().hex}.mp3"
161
  ffmpeg_audio_cmd = ["ffmpeg", "-y", "-i", str(input_path), "-ac", "1", "-ar", "24k",
 
174
 
175
  # Step2: encode video
176
  out_video = CONVERTED_FOLDER / f"{uuid.uuid4().hex}.mp4"
177
+ yield None, None, "Encoding video track..."
178
  ffmpeg_video_cmd = ["ffmpeg", "-y", "-hwaccel", ACCEL, "-i", str(input_path)]
179
  if downscale: ffmpeg_video_cmd += ["-vf", "scale=-2:144"]
180
  if custom_bitrate and video_bitrate: ffmpeg_video_cmd += ["-b:v", f"{int(video_bitrate)}k"]
 
185
 
186
  # Step3: merge
187
  merged_out = CONVERTED_FOLDER / f"{uuid.uuid4().hex}.mp4"
188
+ yield None, None, "Merging audio & video..."
189
  merge_cmd = ["ffmpeg", "-y", "-i", str(out_video), "-i", str(out_audio), "-c", "copy", str(merged_out)]
190
  stdout, stderr, rc = await run_command_capture(merge_cmd)
191
  if rc != 0:
 
197
  try: f.unlink()
198
  except: pass
199
 
200
+ yield str(merged_out), str(merged_out), "Conversion complete!"
201
  return
202
 
203
  finally: