TMU (Too Many Updates)

This commit is contained in:
Geoffrey Frogeye 2019-10-17 12:44:30 +02:00
parent 392dfed89a
commit 789f26d925
12 changed files with 147 additions and 76 deletions

View file

@ -3,11 +3,13 @@
# Normalisation is done at the default of each program,
# which is usually -89.0 dB
import os
import coloredlogs
import logging
import r128gain
import os
import sys
import typing
import coloredlogs
import r128gain
coloredlogs.install(level='DEBUG', fmt='%(levelname)s %(message)s')
log = logging.getLogger()
@ -18,51 +20,49 @@ log = logging.getLogger()
FORCE = '-f' in sys.argv
if FORCE:
sys.argv.remove('-f')
SOURCE_FOLDER = os.path.realpath(sys.argv[1]) if len(sys.argv) >= 2 else os.path.join(os.path.expanduser("~"), "Musiques")
if len(sys.argv) >= 2:
SOURCE_FOLDER = os.path.realpath(sys.argv[1])
else:
SOURCE_FOLDER = os.path.join(os.path.expanduser("~"), "Musiques")
def isMusic(f):
def isMusic(f: str) -> bool:
ext = os.path.splitext(f)[1][1:].lower()
return ext in r128gain.AUDIO_EXTENSIONS
# Get album paths
log.info("Listing albums and tracks")
albums = set()
singleFiles = set()
albums = list()
singleFiles = list()
for root, dirs, files in os.walk(SOURCE_FOLDER):
folder_has_music = False
for f in files:
if isMusic(f):
folder_has_music = True
fullPath = os.path.join(root, f)
singleFiles.append(fullPath)
relRoot = os.path.relpath(root, SOURCE_FOLDER)
if folder_has_music:
albums.append(root)
head, tail = os.path.split(relRoot)
# 1 component in the path: save files path as single
if not len(head):
for f in files:
if isMusic(f):
fullPath = os.path.join(root, f)
singleFiles.add(fullPath)
head, tail = os.path.split(head)
if len(head):
continue
# 2 components in the path: save album path
albums.add(root)
# log.info("Processing single files")
# r128gain.process(singleFiles, album_gain=False,
# skip_tagged=not FORCE, report=True)
log.info("Processing single files")
# r128gain.process(list(singleFiles), album_gain=False, skip_tagged=not FORCE, report=True)
for album in albums:
albumName = os.path.relpath(album, SOURCE_FOLDER)
log.info("Processing album {}".format(albumName))
musicFiles = set()
for root, dirs, files in os.walk(album):
for f in files:
if isMusic(f):
fullPath = os.path.join(root, f)
musicFiles.add(fullPath)
musicFiles = list()
for f in os.listdir(album):
if isMusic(f):
fullPath = os.path.join(album, f)
musicFiles.append(fullPath)
# print(musicFiles)
if not len(musicFiles):
if not musicFiles:
continue
r128gain.process(list(musicFiles), album_gain=True, skip_tagged=not FORCE, report=True)
r128gain.process(musicFiles, album_gain=True,
skip_tagged=not FORCE, report=True)
print("==============================")