Compare commits

..

2 Commits

Author SHA1 Message Date
exu
61917432c9 Remove bandwidth limit for music uploads 2024-03-24 19:31:01 +01:00
exu
01260fb1c1 Add function to copy metadata to normalized files 2024-03-24 19:30:45 +01:00
2 changed files with 29 additions and 1 deletions

View File

@ -20,7 +20,8 @@ rsync -uvr --progress --delete /mnt/storage/MediaLibrary/{Movies,other,Patreon,S
rsync -uvrL --progress --delete /home/exu/Musik /mnt/lan1nas1/
# transfer Music
rsync -uvr --progress --delete --bwlimit=2M -e "ssh -i $sshkeypath -p $port" /mnt/lan1nas1/Musik/ ${user}@${server}:/mnt/media/Musik/
#rsync -uvr --progress --delete --bwlimit=2M -e "ssh -i $sshkeypath -p $port" /mnt/lan1nas1/Musik/ ${user}@${server}:/mnt/media/Musik/
rsync -uvr --progress --delete -e "ssh -i $sshkeypath -p $port" /mnt/lan1nas1/Musik/ ${user}@${server}:/mnt/media/Musik/
# transfer Shows
rsync -uvr --progress --delete --bwlimit=2M -e "ssh -i $sshkeypath -p $port" /mnt/lan1nas1/Shows/ ${user}@${server}:/mnt/media/Shows/

View File

@ -35,6 +35,9 @@ import soundfile
# loudness normalization
import pyloudnorm
# file copy
import shutil
"""
Normalize loudness of all music files in a given directory and its subdirectories.
"""
@ -111,6 +114,28 @@ def ffmpeg_to_wav(inputfile: str, outputfile: str):
subprocess.run(ff.cmd, shell=True, capture_output=True)
def ffmpeg_copy_metadata(inputfile: str, outputfile: str):
"""
Copy all metadata from the input file to the output file.
A temporary file is used in an intermediate step
Parameters:
inputfile (str): Path to input file
outputfile (str): Path to output file
"""
# store output file as temporary file. FFMPEG can't work on files in-place
with tempfile.NamedTemporaryFile() as temp_audio:
shutil.copyfile(outputfile, temp_audio.name)
inputcmd = {inputfile: None, temp_audio.name: None}
outputcmd = {outputfile: "-map 1 -c copy -map_metadata 0"}
ff = ffmpy.FFmpeg(inputs=inputcmd, outputs=outputcmd, global_options=("-y"))
subprocess.run(ff.cmd, shell=True, capture_output=True)
def main(inputfile: str) -> Optional[list[Any]]:
"""
Main program loop
@ -147,12 +172,14 @@ def main(inputfile: str) -> Optional[list[Any]]:
outputfile: str = os.path.join(outputfolder, infile_noextension + ".flac")
# direct conversion start
loudnorm(inputfile=inputfile, outputfile=outputfile)
ffmpeg_copy_metadata(inputfile=inputfile, outputfile=outputfile)
print("Completed", inputfile)
case ".mp3" | ".m4a" | ".aac" | ".opus":
print("Working on", inputfile)
outputfile: str = os.path.join(outputfolder, infile_noextension + ".opus")
# conversion is started within the ffmpeg_to_wav function
ffmpeg_to_wav(inputfile=inputfile, outputfile=outputfile)
ffmpeg_copy_metadata(inputfile=inputfile, outputfile=outputfile)
print("Completed", inputfile)
case _:
print(