pkgs/convert-flac-dir-to-mp3: Use tmpfile for ffmpeg so we don't have broken files laying around
This commit is contained in:
@@ -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}")
|
||||
|
Reference in New Issue
Block a user