improvements by Gemini 2.5 Pro
This commit is contained in:
@@ -213,7 +213,14 @@ def main(no_downmix=False):
|
||||
codec = stream.get("codec_name")
|
||||
channels = stream.get("channels", 2)
|
||||
language = stream.get("tags", {}).get("language", "und")
|
||||
mkv_track = mkv_audio_tracks_list[audio_idx] if audio_idx < len(mkv_audio_tracks_list) else {}
|
||||
|
||||
# More robustly find the mkvmerge track by matching ffprobe's stream index
|
||||
# to mkvmerge's 'stream_id' property.
|
||||
mkv_track = next((t for t in mkv_info.get("tracks", []) if t.get("properties", {}).get("stream_id") == stream_index), None)
|
||||
if not mkv_track:
|
||||
# Fallback to the less reliable index-based method if stream_id isn't found
|
||||
mkv_track = mkv_audio_tracks_list[audio_idx] if audio_idx < len(mkv_audio_tracks_list) else {}
|
||||
|
||||
track_id = mkv_track.get("id", -1)
|
||||
track_title = mkv_track.get("properties", {}).get("track_name", "")
|
||||
track_delay = 0
|
||||
@@ -250,11 +257,12 @@ def main(no_downmix=False):
|
||||
mkvmerge_args = ["mkvmerge", "-o", str(intermediate_output_file), str(created_encoded_video_path)]
|
||||
|
||||
for file_info in processed_audio_files:
|
||||
sync_switch = ["--sync", f"0:{file_info['Delay']}"] if file_info["Delay"] else []
|
||||
mkvmerge_args += [
|
||||
"--language", f"0:{file_info['Language']}",
|
||||
"--track-name", f"0:{file_info['Title']}"
|
||||
] + sync_switch + [str(file_info["Path"])]
|
||||
mkvmerge_args.extend(["--language", f"0:{file_info['Language']}"])
|
||||
if file_info['Title']: # Only add track name if it exists
|
||||
mkvmerge_args.extend(["--track-name", f"0:{file_info['Title']}"])
|
||||
if file_info['Delay']:
|
||||
mkvmerge_args.extend(["--sync", f"0:{file_info['Delay']}"])
|
||||
mkvmerge_args.append(str(file_info["Path"]))
|
||||
|
||||
source_copy_args = ["--no-video"]
|
||||
|
||||
@@ -274,25 +282,28 @@ def main(no_downmix=False):
|
||||
print(f"An error occurred while processing '{file_path.name}': {e}", file=sys.stderr)
|
||||
finally:
|
||||
print("--- Starting Cleanup ---")
|
||||
print(" - Cleaning up disposable audio temporary directory...")
|
||||
if audio_temp_dir and Path(audio_temp_dir).exists():
|
||||
print(" - Cleaning up disposable audio temporary directory...")
|
||||
shutil.rmtree(audio_temp_dir, ignore_errors=True)
|
||||
|
||||
print(" - Cleaning up intermediate output file (if any)...")
|
||||
intermediate_output_file.unlink(missing_ok=True)
|
||||
if intermediate_output_file.exists():
|
||||
print(" - Cleaning up intermediate output file...")
|
||||
intermediate_output_file.unlink()
|
||||
|
||||
print(" - Cleaning up persistent video temporary files...")
|
||||
if created_ut_video_path and created_ut_video_path.exists():
|
||||
print(f" Deleting UT video file: {created_ut_video_path}")
|
||||
created_ut_video_path.unlink(missing_ok=True)
|
||||
print(f" - Deleting UT video file: {created_ut_video_path}")
|
||||
created_ut_video_path.unlink()
|
||||
if created_encoded_video_path and created_encoded_video_path.exists():
|
||||
print(f" Deleting encoded video temp file: {created_encoded_video_path}")
|
||||
created_encoded_video_path.unlink(missing_ok=True)
|
||||
print(f" - Deleting encoded video temp file: {created_encoded_video_path}")
|
||||
created_encoded_video_path.unlink()
|
||||
|
||||
print(" - Cleaning up AlabamaEncoder temporary directories...")
|
||||
for temp_dir_alabama in current_dir.glob('.alabamatemp-*'):
|
||||
if temp_dir_alabama.is_dir():
|
||||
shutil.rmtree(temp_dir_alabama, ignore_errors=True)
|
||||
alabama_dirs = list(current_dir.glob('.alabamatemp-*'))
|
||||
if alabama_dirs:
|
||||
print(" - Cleaning up AlabamaEncoder temporary directories...")
|
||||
for temp_dir_alabama in alabama_dirs:
|
||||
if temp_dir_alabama.is_dir():
|
||||
shutil.rmtree(temp_dir_alabama, ignore_errors=True)
|
||||
print("--- Finished Cleanup ---")
|
||||
|
||||
runtime = datetime.now() - date
|
||||
|
||||
Reference in New Issue
Block a user