Fix conversion conflicts when both input and output filenames are same (#459)

* Workaround conversion conflicts by appending '.temp' to input filename

* Fix tests

* Add a test and some minor changes

* Update CHANGES.md
This commit is contained in:
Ritiek Malhotra
2019-01-02 18:54:27 +00:00
committed by GitHub
parent 1cf421960c
commit 53dd292b55
6 changed files with 78 additions and 28 deletions

View File

@@ -112,6 +112,7 @@ class TestDownload:
class TestFFmpeg:
def test_convert_from_webm_to_mp3(self, filename_fixture, monkeypatch):
monkeypatch.setattr("os.remove", lambda x: None)
expect_command = "ffmpeg -y -i {0}.webm -codec:a libmp3lame -ar 44100 -b:a 192k -vn {0}.mp3".format(os.path.join(const.args.folder, filename_fixture))
_, command = convert.song(
filename_fixture + ".webm", filename_fixture + ".mp3", const.args.folder
@@ -119,6 +120,7 @@ class TestFFmpeg:
assert ' '.join(command) == expect_command
def test_convert_from_webm_to_m4a(self, filename_fixture, monkeypatch):
monkeypatch.setattr("os.remove", lambda x: None)
expect_command = "ffmpeg -y -i {0}.webm -cutoff 20000 -codec:a aac -ar 44100 -b:a 192k -vn {0}.m4a".format(os.path.join(const.args.folder, filename_fixture))
_, command = convert.song(
filename_fixture + ".webm", filename_fixture + ".m4a", const.args.folder
@@ -126,6 +128,7 @@ class TestFFmpeg:
assert ' '.join(command) == expect_command
def test_convert_from_m4a_to_mp3(self, filename_fixture, monkeypatch):
monkeypatch.setattr("os.remove", lambda x: None)
expect_command = "ffmpeg -y -i {0}.m4a -codec:v copy -codec:a libmp3lame -ar 44100 -b:a 192k -vn {0}.mp3".format(os.path.join(const.args.folder, filename_fixture))
_, command = convert.song(
filename_fixture + ".m4a", filename_fixture + ".mp3", const.args.folder
@@ -133,6 +136,7 @@ class TestFFmpeg:
assert ' '.join(command) == expect_command
def test_convert_from_m4a_to_webm(self, filename_fixture, monkeypatch):
monkeypatch.setattr("os.remove", lambda x: None)
expect_command = "ffmpeg -y -i {0}.m4a -codec:a libopus -vbr on -b:a 192k -vn {0}.webm".format(os.path.join(const.args.folder, filename_fixture))
_, command = convert.song(
filename_fixture + ".m4a", filename_fixture + ".webm", const.args.folder
@@ -140,15 +144,24 @@ class TestFFmpeg:
assert ' '.join(command) == expect_command
def test_convert_from_m4a_to_flac(self, filename_fixture, monkeypatch):
monkeypatch.setattr("os.remove", lambda x: None)
expect_command = "ffmpeg -y -i {0}.m4a -codec:a flac -ar 44100 -b:a 192k -vn {0}.flac".format(os.path.join(const.args.folder, filename_fixture))
_, command = convert.song(
filename_fixture + ".m4a", filename_fixture + ".flac", const.args.folder
)
assert ' '.join(command) == expect_command
def test_correct_container_for_m4a(self, filename_fixture, monkeypatch):
expect_command = "ffmpeg -y -i {0}.m4a.temp -acodec copy -b:a 192k -vn {0}.m4a".format(os.path.join(const.args.folder, filename_fixture))
_, command = convert.song(
filename_fixture + ".m4a", filename_fixture + ".m4a", const.args.folder
)
assert ' '.join(command) == expect_command
class TestAvconv:
def test_convert_from_m4a_to_mp3(self, filename_fixture):
def test_convert_from_m4a_to_mp3(self, filename_fixture, monkeypatch):
monkeypatch.setattr("os.remove", lambda x: None)
expect_command = "avconv -loglevel debug -i {0}.m4a -ab 192k {0}.mp3 -y".format(os.path.join(const.args.folder, filename_fixture))
_, command = convert.song(
filename_fixture + ".m4a", filename_fixture + ".mp3", const.args.folder, avconv=True