v2 tidy/refactor

This commit is contained in:
Keith Edmunds 2022-02-15 08:30:00 +00:00
parent b00f70ff4b
commit ab9955b88a
5 changed files with 28 additions and 25 deletions

View File

@ -7,20 +7,22 @@ class Config(object):
COLOUR_CURRENT_HEADER = "#d4edda" COLOUR_CURRENT_HEADER = "#d4edda"
COLOUR_CURRENT_PLAYLIST = "#7eca8f" COLOUR_CURRENT_PLAYLIST = "#7eca8f"
COLOUR_CURRENT_TAB = "#248f24" COLOUR_CURRENT_TAB = "#248f24"
COLOUR_ODD_PLAYLIST = "#f2f2f2"
COLOUR_ENDING_TIMER = "#dc3545" COLOUR_ENDING_TIMER = "#dc3545"
COLOUR_EVEN_PLAYLIST = "#d9d9d9" COLOUR_EVEN_PLAYLIST = "#d9d9d9"
COLOUR_LONG_START = "#dc3545" COLOUR_LONG_START = "#dc3545"
COLOUR_NORMAL_TAB = "#000000"
COLOUR_NEXT_HEADER = "#fff3cd" COLOUR_NEXT_HEADER = "#fff3cd"
COLOUR_NEXT_PLAYLIST = "#ffc107" COLOUR_NEXT_PLAYLIST = "#ffc107"
COLOUR_NEXT_TAB = "#b38600" COLOUR_NEXT_TAB = "#b38600"
COLOUR_NORMAL_TAB = "#000000"
COLOUR_NOTES_PLAYLIST = "#b8daff" COLOUR_NOTES_PLAYLIST = "#b8daff"
COLOUR_ODD_PLAYLIST = "#f2f2f2"
COLOUR_PREVIOUS_HEADER = "#f8d7da" COLOUR_PREVIOUS_HEADER = "#f8d7da"
COLOUR_UNREADABLE = "#dc3545" COLOUR_UNREADABLE = "#dc3545"
COLOUR_WARNING_TIMER = "#ffc107" COLOUR_WARNING_TIMER = "#ffc107"
DBFS_FADE = -12 DBFS_FADE = -12
DBFS_SILENCE = -50 DBFS_SILENCE = -50
DEFAULT_IMPORT_DIRECTORY = "/home/kae/Nextcloud/tmp"
DEFAULT_OUTPUT_DIRECTORY = "/home/kae/music/Singles"
DISPLAY_SQL = False DISPLAY_SQL = False
ERRORS_TO = ['kae@midnighthax.com'] ERRORS_TO = ['kae@midnighthax.com']
FADE_STEPS = 20 FADE_STEPS = 20

View File

@ -508,7 +508,7 @@ class Tracks(Base):
@staticmethod @staticmethod
def remove_by_path(session, path): def remove_by_path(session, path):
"Remove track with passed path from database" """Remove track with passed path from database"""
DEBUG(f"Tracks.remove_path({path=})") DEBUG(f"Tracks.remove_path({path=})")

View File

@ -30,7 +30,7 @@ from config import Config
from models import (db_init, Notes, Playdates, Playlists, PlaylistTracks, from models import (db_init, Notes, Playdates, Playlists, PlaylistTracks,
Session, Settings, Tracks) Session, Settings, Tracks)
from playlists import PlaylistTab from playlists import PlaylistTab
from songdb import create_track_from_file from utilities import create_track_from_file
from ui.dlg_search_database_ui import Ui_Dialog from ui.dlg_search_database_ui import Ui_Dialog
from ui.dlg_SelectPlaylist_ui import Ui_dlgSelectPlaylist from ui.dlg_SelectPlaylist_ui import Ui_dlgSelectPlaylist
from ui.main_window_ui import Ui_MainWindow from ui.main_window_ui import Ui_MainWindow

View File

@ -20,9 +20,15 @@ from datetime import datetime, timedelta
from helpers import get_relative_date, open_in_audacity from helpers import get_relative_date, open_in_audacity
from log import DEBUG, ERROR from log import DEBUG, ERROR
from models import ( from models import (
Notes, Playdates, Playlists, PlaylistTracks, Session, Settings, Tracks, NoteColours Notes,
Playdates,
Playlists,
Session,
Settings,
Tracks,
NoteColours
) )
from songdb import create_track_from_file, update_meta from utilities import create_track_from_file, update_meta
class PlaylistTab(QTableWidget): class PlaylistTab(QTableWidget):

View File

@ -5,10 +5,10 @@ import os
import shutil import shutil
import tempfile import tempfile
from config import Config from app.config import Config
from helpers import show_warning from app.helpers import show_warning
from log import DEBUG, INFO from app.log import DEBUG, INFO
from models import Notes, Playdates, PlaylistTracks, Session, Tracks from app.models import Notes, Playdates, Session, Tracks
from mutagen.flac import FLAC from mutagen.flac import FLAC
from mutagen.mp3 import MP3 from mutagen.mp3 import MP3
from pydub import AudioSegment, effects from pydub import AudioSegment, effects
@ -18,18 +18,13 @@ messages = []
def main(): def main():
"Main loop" """Main loop"""
DEBUG("Starting") DEBUG("Starting")
print("needs refactoring")
import sys
sys.exit(1)
# Parse command line
p = argparse.ArgumentParser() p = argparse.ArgumentParser()
# Only allow one option to be specified # Only allow one option to be specified
group = p.add_mutually_exclusive_group() group = p.add_mutually_exclusive_group()
group.add_argument('-u', '--update', group.add_argument('-u', '--update',
action="store_true", dest="update", action="store_true", dest="update",
default=False, help="Update database") default=False, help="Update database")
@ -68,9 +63,9 @@ def create_track_from_file(session, path, interactive=False):
""" """
if interactive: if interactive:
str = f"Importing {path}" msg = f"Importing {path}"
INFO(str) INFO(msg)
INFO("-" * len(str)) INFO("-" * len(msg))
INFO("Get track info...") INFO("Get track info...")
t = get_music_info(path) t = get_music_info(path)
title = t['title'] title = t['title']
@ -122,7 +117,7 @@ def create_track_from_file(session, path, interactive=False):
fd, temp_path = tempfile.mkstemp() fd, temp_path = tempfile.mkstemp()
shutil.copyfile(path, temp_path) shutil.copyfile(path, temp_path)
except Exception as err: except Exception as err:
DEBUG(f"songdb.create_track_from_file({path}): err1: {str(err)}") DEBUG(f"songdb.create_track_from_file({path}): err1: {repr(err)}")
return return
# Overwrite original file with normalised output # Overwrite original file with normalised output
@ -145,7 +140,7 @@ def create_track_from_file(session, path, interactive=False):
dst[tag] = src[tag] dst[tag] = src[tag]
dst.save() dst.save()
except Exception as err: except Exception as err:
DEBUG(f"songdb.create_track_from_file({path}): err2: {str(err)}") DEBUG(f"songdb.create_track_from_file({path}): err2: {repr(err)}")
# Restore original file # Restore original file
shutil.copyfile(path, temp_path) shutil.copyfile(path, temp_path)
finally: finally:
@ -156,7 +151,7 @@ def create_track_from_file(session, path, interactive=False):
def full_update_db(session): def full_update_db(session):
"Rescan all entries in database" """Rescan all entries in database"""
def log(msg): def log(msg):
INFO(f"full_update_db(): {msg}") INFO(f"full_update_db(): {msg}")
@ -279,12 +274,12 @@ def update_db(session):
f"File removed: {track.title=}, {track.artist=}, " f"File removed: {track.title=}, {track.artist=}, "
f"{track.path=}" f"{track.path=}"
) )
for pt in [a.playlist.name for a in track.playlists] for playlist in [a.playlist for a in track.playlists]:
# Create note # Create note
Notes.add_note(session, pt.playlist_id, pt.row, note_txt) Notes(session, playlist.id, pt.row, note_txt)
# TODO: this needs to call playlist.add_note() now # TODO: this needs to call playlist.add_note() now
# Remove playlist entry # Remove playlist entry
PlaylistTracks.remove_track(session, pt.playlist_id, pt.row) playlist.remove_track(session, pt.row)
# Remove Track entry pointing to invalid path # Remove Track entry pointing to invalid path
Tracks.remove_by_path(session, path) Tracks.remove_by_path(session, path)