Skip to content

Commit d3dc793

Browse files
authored
Final fix #379
1 parent 1d94c66 commit d3dc793

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

StreamingCommunity/Lib/Downloader/DASH/downloader.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Internal utilities
1313
from StreamingCommunity.Util.config_json import config_manager
1414
from StreamingCommunity.Util.os import internet_manager
15-
from ...FFmpeg import print_duration_table
15+
from ...FFmpeg import print_duration_table, join_audios, join_video
1616

1717

1818
# Logic class
@@ -174,25 +174,26 @@ def download_segments(self, clear=False):
174174

175175
def finalize_output(self):
176176

177-
# Use the original output path for the final file
177+
# Definenition of decrypted files
178+
video_file = os.path.join(self.decrypted_dir, "video.mp4")
179+
audio_file = os.path.join(self.decrypted_dir, "audio.mp4")
178180
output_file = self.original_output_path
179181

180182
# Set the output file path for status tracking
181183
self.output_file = output_file
182184
use_shortest = False
183185

184-
"""if os.path.exists(video_file) and os.path.exists(audio_file):
186+
if os.path.exists(video_file) and os.path.exists(audio_file):
185187
audio_tracks = [{"path": audio_file}]
186-
out_audio_path, use_shortest = join_audios(video_file, audio_tracks, output_file)
188+
_, use_shortest = join_audios(video_file, audio_tracks, output_file)
187189

188190
elif os.path.exists(video_file):
189-
out_video_path = join_video(video_file, output_file, codec=None)
190-
191+
_ = join_video(video_file, output_file, codec=None)
192+
191193
else:
192-
print("Video file missing, cannot export")
194+
console.print("[red]Video file missing, cannot export[/red]")
193195
return None
194-
"""
195-
196+
196197
# Handle failed sync case
197198
if use_shortest:
198199
new_filename = output_file.replace(".mp4", "_failed_sync.mp4")
@@ -204,18 +205,22 @@ def finalize_output(self):
204205
if os.path.exists(output_file):
205206
file_size = internet_manager.format_file_size(os.path.getsize(output_file))
206207
duration = print_duration_table(output_file, description=False, return_string=True)
208+
207209
panel_content = (
208210
f"[cyan]File size: [bold red]{file_size}[/bold red]\n"
209211
f"[cyan]Duration: [bold]{duration}[/bold]\n"
210212
f"[cyan]Output: [bold]{os.path.abspath(output_file)}[/bold]"
211213
)
212-
214+
213215
console.print(Panel(
214216
panel_content,
215217
title=f"{os.path.basename(output_file.replace('.mp4', ''))}",
216218
border_style="green"
217219
))
218220

221+
else:
222+
console.print(f"[red]Output file not found: {output_file}")
223+
219224
# Clean up: delete only the tmp directory, not the main directory
220225
if os.path.exists(self.tmp_dir):
221226
shutil.rmtree(self.tmp_dir, ignore_errors=True)
@@ -226,13 +231,12 @@ def finalize_output(self):
226231

227232
# Check if out_path is different from the actual output directory
228233
# and if it's empty, then it's safe to remove
229-
if (self.out_path != output_dir and
230-
os.path.exists(self.out_path) and
231-
not os.listdir(self.out_path)):
234+
if (self.out_path != output_dir and os.path.exists(self.out_path) and not os.listdir(self.out_path)):
232235
try:
233236
os.rmdir(self.out_path)
237+
234238
except Exception as e:
235-
print(f"[WARN] Cannot remove directory {self.out_path}: {e}")
239+
console.print(f"[red]Cannot remove directory {self.out_path}: {e}")
236240

237241
# Verify the final file exists before returning
238242
if os.path.exists(output_file):

0 commit comments

Comments
 (0)