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")
|
codec = stream.get("codec_name")
|
||||||
channels = stream.get("channels", 2)
|
channels = stream.get("channels", 2)
|
||||||
language = stream.get("tags", {}).get("language", "und")
|
language = stream.get("tags", {}).get("language", "und")
|
||||||
|
|
||||||
|
# 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 {}
|
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_id = mkv_track.get("id", -1)
|
||||||
track_title = mkv_track.get("properties", {}).get("track_name", "")
|
track_title = mkv_track.get("properties", {}).get("track_name", "")
|
||||||
track_delay = 0
|
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)]
|
mkvmerge_args = ["mkvmerge", "-o", str(intermediate_output_file), str(created_encoded_video_path)]
|
||||||
|
|
||||||
for file_info in processed_audio_files:
|
for file_info in processed_audio_files:
|
||||||
sync_switch = ["--sync", f"0:{file_info['Delay']}"] if file_info["Delay"] else []
|
mkvmerge_args.extend(["--language", f"0:{file_info['Language']}"])
|
||||||
mkvmerge_args += [
|
if file_info['Title']: # Only add track name if it exists
|
||||||
"--language", f"0:{file_info['Language']}",
|
mkvmerge_args.extend(["--track-name", f"0:{file_info['Title']}"])
|
||||||
"--track-name", f"0:{file_info['Title']}"
|
if file_info['Delay']:
|
||||||
] + sync_switch + [str(file_info["Path"])]
|
mkvmerge_args.extend(["--sync", f"0:{file_info['Delay']}"])
|
||||||
|
mkvmerge_args.append(str(file_info["Path"]))
|
||||||
|
|
||||||
source_copy_args = ["--no-video"]
|
source_copy_args = ["--no-video"]
|
||||||
|
|
||||||
@@ -274,23 +282,26 @@ def main(no_downmix=False):
|
|||||||
print(f"An error occurred while processing '{file_path.name}': {e}", file=sys.stderr)
|
print(f"An error occurred while processing '{file_path.name}': {e}", file=sys.stderr)
|
||||||
finally:
|
finally:
|
||||||
print("--- Starting Cleanup ---")
|
print("--- Starting Cleanup ---")
|
||||||
print(" - Cleaning up disposable audio temporary directory...")
|
|
||||||
if audio_temp_dir and Path(audio_temp_dir).exists():
|
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)
|
shutil.rmtree(audio_temp_dir, ignore_errors=True)
|
||||||
|
|
||||||
print(" - Cleaning up intermediate output file (if any)...")
|
if intermediate_output_file.exists():
|
||||||
intermediate_output_file.unlink(missing_ok=True)
|
print(" - Cleaning up intermediate output file...")
|
||||||
|
intermediate_output_file.unlink()
|
||||||
|
|
||||||
print(" - Cleaning up persistent video temporary files...")
|
print(" - Cleaning up persistent video temporary files...")
|
||||||
if created_ut_video_path and created_ut_video_path.exists():
|
if created_ut_video_path and created_ut_video_path.exists():
|
||||||
print(f" Deleting UT video file: {created_ut_video_path}")
|
print(f" - Deleting UT video file: {created_ut_video_path}")
|
||||||
created_ut_video_path.unlink(missing_ok=True)
|
created_ut_video_path.unlink()
|
||||||
if created_encoded_video_path and created_encoded_video_path.exists():
|
if created_encoded_video_path and created_encoded_video_path.exists():
|
||||||
print(f" Deleting encoded video temp file: {created_encoded_video_path}")
|
print(f" - Deleting encoded video temp file: {created_encoded_video_path}")
|
||||||
created_encoded_video_path.unlink(missing_ok=True)
|
created_encoded_video_path.unlink()
|
||||||
|
|
||||||
|
alabama_dirs = list(current_dir.glob('.alabamatemp-*'))
|
||||||
|
if alabama_dirs:
|
||||||
print(" - Cleaning up AlabamaEncoder temporary directories...")
|
print(" - Cleaning up AlabamaEncoder temporary directories...")
|
||||||
for temp_dir_alabama in current_dir.glob('.alabamatemp-*'):
|
for temp_dir_alabama in alabama_dirs:
|
||||||
if temp_dir_alabama.is_dir():
|
if temp_dir_alabama.is_dir():
|
||||||
shutil.rmtree(temp_dir_alabama, ignore_errors=True)
|
shutil.rmtree(temp_dir_alabama, ignore_errors=True)
|
||||||
print("--- Finished Cleanup ---")
|
print("--- Finished Cleanup ---")
|
||||||
|
|||||||
Reference in New Issue
Block a user