Skip to content
Permalink
Browse files

fix handling of temporary file

  • Loading branch information
slhck committed Jan 26, 2018
1 parent f1c13aa commit 756dc6bf0069650998da546fd4ce49d7b0f73692
Showing with 15 additions and 8 deletions.
  1. +7 −0 HISTORY.md
  2. +8 −8 ffmpeg_normalize/_media_file.py
@@ -1,6 +1,13 @@
# History

1.0.3 (2018-01-26)
------------------

- Always streamcopy when detecting streams to avoid initializing encoder
- Fix handling of temporary file names

1.0.2 (2018-01-25)
------------------

- Fix bug with target level for Peak/RMS

@@ -211,13 +211,13 @@ def _second_pass(self):
run_command(cmd, dry=True)
return

# make a temporary output file
# create a temporary output file name
output_file_suffix = os.path.splitext(self.output_file)[1]
temp_file = tempfile.NamedTemporaryFile(
suffix=output_file_suffix,
delete=False
temp_file_name = os.path.join(
tempfile.gettempdir(),
next(tempfile._get_candidate_names()) + output_file_suffix
)
cmd.append(temp_file.name)
cmd.append(temp_file_name)

# run the actual command
try:
@@ -228,13 +228,13 @@ def _second_pass(self):
# move file from TMP to output file
logger.debug(
"Moving temporary file from {} to {}"
.format(temp_file.name, self.output_file)
.format(temp_file_name, self.output_file)
)
shutil.move(temp_file.name, self.output_file)
shutil.move(temp_file_name, self.output_file)
except Exception as e:
logger.error("Error while running command {}!".format(cmd))
# remove dangling temporary file
os.remove(temp_file.name)
os.remove(temp_file_name)
raise e

logger.debug("Normalization finished")

0 comments on commit 756dc6b

Please sign in to comment.
You can’t perform that action at this time.