From 165839be0735ad356a773c85f6f2615ac4106a8c Mon Sep 17 00:00:00 2001 From: clerie Date: Sun, 21 Sep 2025 17:18:08 +0200 Subject: [PATCH] pkgs/convert-flac-dir-to-mp3: Use tmpfile for ffmpeg so we don't have broken files laying around --- .../convert-flac-dir-to-mp3.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkgs/convert-flac-dir-to-mp3/convert-flac-dir-to-mp3.py b/pkgs/convert-flac-dir-to-mp3/convert-flac-dir-to-mp3.py index fd7cc5a..3fab28a 100644 --- a/pkgs/convert-flac-dir-to-mp3/convert-flac-dir-to-mp3.py +++ b/pkgs/convert-flac-dir-to-mp3/convert-flac-dir-to-mp3.py @@ -91,6 +91,19 @@ if __name__ == "__main__": shutil.copy(from_path / filepath, to_path / filepath) elif filepath.suffix == ".mp3" and replace_suffix(filepath, ".flac") in relative_from_filepaths: # Convert from flac - ffmpeg_flac_to_mp3(from_path / replace_suffix(filepath, ".flac"), to_path / filepath) + print("") + print(f"Converting {to_path / filepath}…") + + # Tempfile for ffmpeg + tmpfilepath = filepath.with_name(".~" + filepath.name) + (to_path / tmpfilepath).unlink(missing_ok=True) + + print(f"Using tempfile for ffmpeg {to_path / tmpfilepath}…") + + # Convert + ffmpeg_flac_to_mp3(from_path / replace_suffix(filepath, ".flac"), to_path / tmpfilepath) + + # Rename tempfile + (to_path / tmpfilepath).rename(to_path / filepath) else: raise Exception("Unable to figure out how to get {to_path / filepath} from {from_path}")