diff --git a/app/helpers.py b/app/helpers.py index 4828365..36e2a37 100644 --- a/app/helpers.py +++ b/app/helpers.py @@ -6,6 +6,7 @@ import tempfile from mutagen.flac import FLAC # type: ignore from mutagen.mp3 import MP3 # type: ignore from pydub import effects +from pydub.utils import mediainfo from config import Config from datetime import datetime @@ -202,6 +203,7 @@ def normalise_track(path): f"File type {ftype} not implemented" ) + bitrate = mediainfo(path)['bit_rate'] audio = get_audio_segment(path) if not audio: return @@ -221,7 +223,8 @@ def normalise_track(path): # Overwrite original file with normalised output normalised = effects.normalize(audio) try: - normalised.export(path, format=os.path.splitext(path)[1][1:]) + normalised.export(path, format=os.path.splitext(path)[1][1:], + bitrate=bitrate) # Fix up permssions and ownership os.chown(path, stats.st_uid, stats.st_gid) os.chmod(path, stats.st_mode)