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