Verified Commit f397c609 authored by Jeff's avatar Jeff
Browse files
parents a74c1494 a84cb902
Pipeline #13261 passed with stages
in 6 minutes
......@@ -855,8 +855,7 @@ class Upload(models.Model):
if not input:
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):
......@@ -105,7 +105,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):
audio = pydub.AudioSegment.from_file(input, format=input_format)
return transcode_audio(audio, output, output_format, **kwargs)
import os
import pathlib
import pytest
import tempfile
from import utils
......@@ -28,6 +29,7 @@ def test_guess_mimetype_try_using_extension_if_fail(wrong, factories, mocker):
("sample.flac", {"bitrate": 1608000, "length": 0.001}),
("test.mp3", {"bitrate": 8000, "length": 267.70285714285717}),
("test.ogg", {"bitrate": 112000, "length": 1}),
("test.opus", {"bitrate": 0, "length": 1}), # This Opus file lacks a bitrate
def test_get_audio_file_data(name, expected):
......@@ -109,3 +111,22 @@ def test_get_dirs_and_files(path, expected, tmpdir):
(root_path / "System" / "file.ogg").touch()
assert utils.browse_dir(root_path, path) == expected
"name, expected",
("sample.flac", {"bitrate": 128000, "length": 0}),
("test.mp3", {"bitrate": 16000, "length": 268}),
("test.ogg", {"bitrate": 128000, "length": 1}),
("test.opus", {"bitrate": 128000, "length": 1}),
def test_transcode_file(name, expected):
path = pathlib.Path(os.path.join(DATA_DIR, name))
with tempfile.NamedTemporaryFile() as dest:
utils.transcode_file(path, pathlib.Path(
with open(, "rb") as f:
result = {k: round(v) for k, v in utils.get_audio_file_data(f).items()}
assert result == expected
Changed audio format detection to happen via sniffing and not file extensions (#1274)
......@@ -39,10 +39,10 @@
<translate translate-context="Content/Notifications/Paragraph">We noticed you've been here for a while. If Funkwhale is useful to you, we could use your help to make it even better!</translate>
<a href="" _target="blank" rel="noopener" class="ui primary inverted button">
<a href="" target="_blank" rel="noopener" class="ui primary inverted button">
<translate translate-context="Content/Notifications/Button.Label/Verb">Donate</translate>
<a href="" _target="blank" rel="noopener" class="ui secondary inverted button">
<a href="" target="_blank" rel="noopener" class="ui secondary inverted button">
<translate translate-context="Content/Notifications/Button.Label/Verb">Discover other ways to help</translate>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment