parent
1a4f842f1f
commit
69fb10fcd9
@ -14,11 +14,13 @@ from mutagen.mp3 import MP3
|
||||
from pydub import AudioSegment, effects
|
||||
from tinytag import TinyTag
|
||||
|
||||
# Globals (I know)
|
||||
messages = []
|
||||
|
||||
def main():
|
||||
"Main loop"
|
||||
|
||||
INFO("Starting")
|
||||
DEBUG("Starting")
|
||||
|
||||
# Parse command line
|
||||
p = argparse.ArgumentParser()
|
||||
@ -36,25 +38,25 @@ def main():
|
||||
|
||||
# Run as required
|
||||
if args.update:
|
||||
INFO("Updating database")
|
||||
DEBUG("Updating database")
|
||||
with Session() as session:
|
||||
update_db(session)
|
||||
elif args.full_update:
|
||||
INFO("Full update of database")
|
||||
DEBUG("Full update of database")
|
||||
with Session() as session:
|
||||
full_update_db(session)
|
||||
elif args.fname:
|
||||
fname = os.path.realpath(args.fname)
|
||||
with Session() as session:
|
||||
create_track_from_file(session, fname, verbose=True)
|
||||
create_track_from_file(session, fname, interactive=True)
|
||||
|
||||
else:
|
||||
INFO("No action specified")
|
||||
|
||||
INFO("Finished")
|
||||
DEBUG("Finished")
|
||||
|
||||
|
||||
def create_track_from_file(session, path, verbose=False):
|
||||
def create_track_from_file(session, path, interactive=False):
|
||||
"""
|
||||
Create track in database from passed path, or update database entry
|
||||
if path already in database.
|
||||
@ -62,7 +64,7 @@ def create_track_from_file(session, path, verbose=False):
|
||||
Return track.
|
||||
"""
|
||||
|
||||
if verbose:
|
||||
if interactive:
|
||||
str = f"Importing {path}"
|
||||
INFO(str)
|
||||
INFO("-" * len(str))
|
||||
@ -70,7 +72,7 @@ def create_track_from_file(session, path, verbose=False):
|
||||
t = get_music_info(path)
|
||||
title = t['title']
|
||||
artist = t['artist']
|
||||
if verbose:
|
||||
if interactive:
|
||||
INFO(f" Title: \"{title}\"")
|
||||
INFO(f" Artist: \"{artist}\"")
|
||||
# Check for duplicate
|
||||
@ -90,7 +92,7 @@ def create_track_from_file(session, path, verbose=False):
|
||||
track.duration = int(round(
|
||||
t['duration'], Config.MILLISECOND_SIGFIGS) * 1000)
|
||||
|
||||
if verbose:
|
||||
if interactive:
|
||||
INFO("Parse for start, fade and silence...")
|
||||
audio = get_audio_segment(path)
|
||||
track.start_gap = leading_silence(audio)
|
||||
@ -102,7 +104,7 @@ def create_track_from_file(session, path, verbose=False):
|
||||
session.commit()
|
||||
|
||||
if Config.NORMALISE_ON_IMPORT:
|
||||
if verbose:
|
||||
if interactive:
|
||||
INFO("Normalise...")
|
||||
# Check type
|
||||
ftype = os.path.splitext(path)[1][1:]
|
||||
@ -329,8 +331,7 @@ def update_db(session):
|
||||
# is filename in database?
|
||||
track = Tracks.get_track_from_filename(session, os.path.basename(path))
|
||||
if not track:
|
||||
INFO(f"songdb.update_db: Adding to database: {path}")
|
||||
create_track_from_file(session, path)
|
||||
messages.append(f"Track missing from database: {path}")
|
||||
else:
|
||||
# Check track info matches found track
|
||||
t = get_music_info(path)
|
||||
@ -345,7 +346,7 @@ def update_db(session):
|
||||
for path in list(db_paths - os_paths):
|
||||
# Manage tracks listed in database but where path is invalid
|
||||
track = Tracks.get_track_from_path(session, path)
|
||||
INFO(f"songdb.update_db(): remove from database: {path=} {track=}")
|
||||
messages.append(f"Remove from database: {path=} {track=}")
|
||||
|
||||
# Remove references from Playdates
|
||||
Playdates.remove_track(session, track.id)
|
||||
@ -364,6 +365,12 @@ def update_db(session):
|
||||
# Remove Track entry pointing to invalid path
|
||||
Tracks.remove_path(session, path)
|
||||
|
||||
# Output messages (so if running via cron, these will get sent to
|
||||
# user)
|
||||
if messages:
|
||||
print("Messages")
|
||||
print("\n".join(messages))
|
||||
|
||||
|
||||
def update_meta(session, track, artist=None, title=None):
|
||||
"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user