From 9ac829fa306cad74b28b3670eeb64472c9ce971c Mon Sep 17 00:00:00 2001 From: Adam Novak <interfect@gmail.com> Date: Mon, 11 Jan 2021 21:04:46 -0800 Subject: [PATCH] Autodetect format when transcoding files --- api/funkwhale_api/music/models.py | 3 +-- api/funkwhale_api/music/utils.py | 2 +- changes/changelog.d/1274.bugfix | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 changes/changelog.d/1274.bugfix diff --git a/api/funkwhale_api/music/models.py b/api/funkwhale_api/music/models.py index f95a8bb3b..3e39e91e2 100644 --- a/api/funkwhale_api/music/models.py +++ b/api/funkwhale_api/music/models.py @@ -855,8 +855,7 @@ class Upload(models.Model): if not input: return - input_format = utils.MIMETYPE_TO_EXTENSION[self.mimetype] - audio = pydub.AudioSegment.from_file(input, format=input_format) + audio = pydub.AudioSegment.from_file(input) return audio def save(self, **kwargs): diff --git a/api/funkwhale_api/music/utils.py b/api/funkwhale_api/music/utils.py index 17b5b7292..8d0f05bd5 100644 --- a/api/funkwhale_api/music/utils.py +++ b/api/funkwhale_api/music/utils.py @@ -101,7 +101,7 @@ def get_actor_from_request(request): return actor -def transcode_file(input, output, input_format, output_format, **kwargs): +def transcode_file(input, output, input_format=None, output_format="mp3", **kwargs): with input.open("rb"): audio = pydub.AudioSegment.from_file(input, format=input_format) return transcode_audio(audio, output, output_format, **kwargs) diff --git a/changes/changelog.d/1274.bugfix b/changes/changelog.d/1274.bugfix new file mode 100644 index 000000000..8dfe061ac --- /dev/null +++ b/changes/changelog.d/1274.bugfix @@ -0,0 +1 @@ +Changed audio format detection to happen via sniffing and not file extensions (#1274) -- GitLab