Preserve bitrate when importing track

This commit is contained in:
Keith Edmunds 2022-09-30 18:54:23 +01:00
parent 1ce009ee73
commit 1da0668807

View File

@ -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)