From 01a449ffa60aefd57fefb9f8c38cca3d9e717873 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 10 Mar 2013 13:22:05 -0700 Subject: [PATCH] convert: auto (#212) now transcodes to /tmp This avoids naming conflicts in the source directory. In particular, when encoding MP3 -> MP3, the previous scheme would overwrite the original file (and hang ffmpeg waiting for input). This should also work in situations where the source directory is read-only. --- beetsplug/convert.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index 1a454388a..8105dbbc1 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -18,6 +18,7 @@ import logging import os import threading from subprocess import Popen +import tempfile from beets.plugins import BeetsPlugin from beets import ui, util @@ -48,8 +49,8 @@ def encode(source, dest): log.info(u'Started encoding {0}'.format(util.displayable_path(source))) opts = config['convert']['opts'].get(unicode).split(u' ') - encode = Popen([config['convert']['ffmpeg'].get(unicode), '-i', source] + - opts + [dest], + encode = Popen([config['convert']['ffmpeg'].get(unicode), '-i', + source, '-y'] + opts + [dest], close_fds=True, stderr=DEVNULL) encode.wait() if encode.returncode != 0: @@ -134,7 +135,8 @@ def convert_on_import(lib, item): library. """ if should_transcode(item): - dest = os.path.splitext(item.path)[0] + '.mp3' + fd, dest = tempfile.mkstemp('.mp3') + os.close(fd) _temp_files.append(dest) # Delete the transcode later. encode(item.path, dest) item.path = dest