diff --git a/app/config.py b/app/config.py index bdf2966..6a4194f 100644 --- a/app/config.py +++ b/app/config.py @@ -4,11 +4,9 @@ from typing import List, Optional class Config(object): - AUDACITY_COMMAND = "/usr/bin/audacity" AUDIO_SEGMENT_CHUNK_SIZE = 10 BITRATE_LOW_THRESHOLD = 192 BITRATE_OK_THRESHOLD = 300 - CHECK_AUDACITY_AT_STARTUP = True CART_DIRECTORY = "/home/kae/radio/CartTracks" CARTS_COUNT = 10 CARTS_HIDE = True @@ -21,19 +19,16 @@ class Config(object): COLOUR_CART_PROGRESSBAR = "#000000" COLOUR_CART_READY = "#ffc107" COLOUR_CART_UNCONFIGURED = "#f2f2f2" - COLOUR_CURRENT_HEADER = "#d4edda" COLOUR_CURRENT_PLAYLIST = "#7eca8f" COLOUR_CURRENT_TAB = "#248f24" COLOUR_ENDING_TIMER = "#dc3545" COLOUR_EVEN_PLAYLIST = "#d9d9d9" COLOUR_LONG_START = "#dc3545" - COLOUR_NEXT_HEADER = "#fff3cd" COLOUR_NEXT_PLAYLIST = "#ffc107" COLOUR_NEXT_TAB = "#b38600" COLOUR_NORMAL_TAB = "#000000" COLOUR_NOTES_PLAYLIST = "#b8daff" COLOUR_ODD_PLAYLIST = "#f2f2f2" - COLOUR_PREVIOUS_HEADER = "#f8d7da" COLOUR_UNREADABLE = "#dc3545" COLOUR_WARNING_TIMER = "#ffc107" COLUMN_NAME_ARTIST = "Artist" @@ -46,13 +41,10 @@ class Config(object): COLUMN_NAME_NOTES = "Notes" COLUMN_NAME_START_TIME = "Start" COLUMN_NAME_TITLE = "Title" - DBFS_FADE = -12 DBFS_SILENCE = -50 DEBUG_FUNCTIONS: List[Optional[str]] = [] DEBUG_MODULES: List[Optional[str]] = ['dbconfig'] DEFAULT_COLUMN_WIDTH = 200 - DEFAULT_IMPORT_DIRECTORY = "/home/kae/Nextcloud/tmp" - DEFAULT_OUTPUT_DIRECTORY = "/home/kae/music/Singles" DISPLAY_SQL = False ERRORS_FROM = ['noreply@midnighthax.com'] ERRORS_TO = ['kae@midnighthax.com'] @@ -78,7 +70,6 @@ class Config(object): ROOT = os.environ.get('ROOT') or "/home/kae/music" IMPORT_DESTINATION = os.path.join(ROOT, "Singles") SCROLL_TOP_MARGIN = 3 - TESTMODE = True TEXT_NO_TRACK_NO_NOTE = "[Section header]" TOD_TIME_FORMAT = "%H:%M:%S" TIMER_MS = 500 @@ -86,6 +77,3 @@ class Config(object): VOLUME_VLC_DEFAULT = 75 VOLUME_VLC_DROP3db = 65 WEB_ZOOM_FACTOR = 1.2 - - -config = Config diff --git a/app/helpers.py b/app/helpers.py index 7d5cf79..2c47c4c 100644 --- a/app/helpers.py +++ b/app/helpers.py @@ -235,7 +235,7 @@ def normalise_track(path): stats = os.stat(path) try: # Copy original file - fd, temp_path = tempfile.mkstemp() + _, temp_path = tempfile.mkstemp() shutil.copyfile(path, temp_path) except Exception as err: log.debug( diff --git a/app/log.py b/app/log.py index 8975176..c8ca86a 100644 --- a/app/log.py +++ b/app/log.py @@ -67,7 +67,7 @@ log.addHandler(stderr) log.addHandler(syslog) -def log_uncaught_exceptions(ex_cls, ex, tb): +def log_uncaught_exceptions(_ex_cls, ex, tb): from helpers import send_mail diff --git a/app/models.py b/app/models.py index c4fbc2b..9d40edf 100644 --- a/app/models.py +++ b/app/models.py @@ -1,17 +1,16 @@ #!/usr/bin/python3 -# + import os.path import re import stackprinter -# + from dbconfig import Session -# + from datetime import datetime from typing import List, Optional -# -# from pydub import AudioSegment + from sqlalchemy.ext.associationproxy import association_proxy -# from sqlalchemy.ext.declarative import declarative_base, DeclarativeMeta + from sqlalchemy import ( Boolean, Column, @@ -23,22 +22,16 @@ from sqlalchemy import ( Integer, select, String, - UniqueConstraint, update, ) -# from sqlalchemy.exc import IntegrityError + from sqlalchemy.orm import ( - backref, declarative_base, relationship, - RelationshipProperty ) -from sqlalchemy.orm.collections import attribute_mapped_collection from sqlalchemy.orm.exc import ( - # MultipleResultsFound, NoResultFound ) -# from config import Config from helpers import ( fade_point, @@ -48,7 +41,6 @@ from helpers import ( trailing_silence, ) from log import log -# Base = declarative_base() @@ -70,7 +62,7 @@ class Carts(Base): ) def __init__(self, session: Session, cart_number: int, name: str = None, - duration: int = None, path: str = None, + duration: int = None, path: str = None, enabled: bool = True) -> None: """Create new cart""" @@ -83,23 +75,6 @@ class Carts(Base): session.add(self) session.commit() - @classmethod - def get_or_create(cls, session: Session, cart_number: int) -> "Carts": - """ - Return cart with passed cart number, or create a record if - none exists. - """ - - try: - return ( - session.execute( - select(Carts) - .where(Carts.cart_number == cart_number) - ).scalar_one() - ) - except NoResultFound: - return Carts(session, cart_number) - class NoteColours(Base): __tablename__ = 'notecolours' @@ -470,19 +445,6 @@ class PlaylistRows(Base): # Delete won't take effect until commit() session.commit() - @staticmethod - def delete_rows(session: Session, ids: List[int]) -> None: - """ - Delete passed ids - """ - - session.execute( - delete(PlaylistRows) - .where(PlaylistRows.id.in_(ids)) - ) - # Delete won't take effect until commit() - session.commit() - @staticmethod def fixup_rownumbers(session: Session, playlist_id: int) -> None: """ @@ -501,19 +463,6 @@ class PlaylistRows(Base): # Ensure new row numbers are available to the caller session.commit() - @classmethod - def get_plr(session: Session, row_number: int, - playlist_id: int) -> "PlaylistRows": - """Return playlistrows object matching passed parameters""" - - return ( - select(PlaylistRows) - .where( - PlaylistRows.row_number == row_number, - PlaylistRows.playlist_id == playlist_id) - .limit(1) - ).first() - @staticmethod def get_track_plr(session: Session, track_id: int, playlist_id: int) -> Optional["PlaylistRows"]: diff --git a/app/music.py b/app/music.py index 2a0f77c..2ac337a 100644 --- a/app/music.py +++ b/app/music.py @@ -19,11 +19,8 @@ class Music: """ def __init__(self) -> None: - # self.current_track_start_time = None - # self.fading = 0 self.VLC = vlc.Instance() self.player = None - # self.track_path = None self.max_volume = Config.VOLUME_VLC_DEFAULT def fade(self) -> None: @@ -109,7 +106,6 @@ class Music: return None status = -1 - self.track_path = path if Config.COLON_IN_PATH_FIX: media = self.VLC.media_new_path(path) diff --git a/app/musicmuster.py b/app/musicmuster.py index f062a92..249fab8 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -42,7 +42,6 @@ from models import ( ) from config import Config from playlists import PlaylistTab -from sqlalchemy.orm.exc import DetachedInstanceError from ui.dlg_cart_ui import Ui_DialogCartEdit # type: ignore from ui.dlg_search_database_ui import Ui_Dialog # type: ignore from ui.dlg_SelectPlaylist_ui import Ui_dlgSelectPlaylist # type: ignore @@ -1039,7 +1038,6 @@ class Window(QMainWindow, Ui_MainWindow): ) fade_at = self.current_track.fade_at silence_at = self.current_track.silence_at - length = self.current_track.duration self.label_fade_length.setText( helpers.ms_to_mmss(silence_at - fade_at)) self.label_start_time.setText( @@ -1591,7 +1589,6 @@ class SelectPlaylistDialog(QDialog): self.ui.buttonBox.rejected.connect(self.close) self.session = session self.playlist = None - self.plid = None record = Settings.get_int_settings( self.session, "select_playlist_dialog_width") diff --git a/app/playlists.py b/app/playlists.py index e48efba..1525207 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -34,7 +34,6 @@ from PyQt5.QtWidgets import ( QStyledItemDelegate, QTableWidget, QTableWidgetItem, - QTextEdit, QWidget ) @@ -65,8 +64,6 @@ MINIMUM_ROW_HEIGHT = 30 class RowMeta: - CLEAR = 0 - NOTE = 1 UNREADABLE = 2 NEXT = 3 CURRENT = 4 @@ -973,12 +970,6 @@ class PlaylistTab(QTableWidget): self.selectRow(row) - def set_searchtext(self, text: Optional[str]) -> None: - """Set the search text and find first match""" - - self.search_text = text - self._find_next_match() - def set_selected_as_next(self) -> None: """Sets the select track as next to play""" @@ -1018,7 +1009,6 @@ class PlaylistTab(QTableWidget): p.row_number for p in PlaylistRows.get_played_rows( session, self.playlist_id) ] - unreadable: List[int] = self._get_unreadable_track_rows() next_start_time = None section_start_plr = None @@ -1339,16 +1329,6 @@ class PlaylistTab(QTableWidget): return (index.row() + 1 if self._is_below(event.pos(), index) else index.row()) - def _find_next_match(self) -> None: - """ - Find next match of search_text. Start at first highlighted row - if there is one, else from top of playlist. - """ - - start_row = self._get_selected_row() - if start_row is None: - start_row = 0 - def _find_next_track_row(self, session: Session, starting_row: int = None) -> Optional[int]: """ @@ -1500,11 +1480,6 @@ class PlaylistTab(QTableWidget): [row for row in set([a.row() for a in self.selectedItems()])] ) - def _get_unreadable_track_rows(self) -> List[int]: - """Return rows marked as unreadable, or None""" - - return self._meta_search(RowMeta.UNREADABLE, one=False) - def _info_row(self, track_id: int) -> None: """Display popup with info re row""" diff --git a/app/replace_files.py b/app/replace_files.py index 13e94e8..dabf1b5 100755 --- a/app/replace_files.py +++ b/app/replace_files.py @@ -4,7 +4,6 @@ # the current directory contains a "better" version of the file than the # parent (eg, bettet bitrate). -import glob import os import pydymenu # type: ignore import shutil @@ -21,7 +20,6 @@ from helpers import ( from models import Tracks from dbconfig import Session -from thefuzz import process # type: ignore from sqlalchemy.exc import IntegrityError from typing import List @@ -35,15 +33,6 @@ source_dir = '/home/kae/music/Singles/tmp' parent_dir = os.path.dirname(source_dir) # ######################################################### - -def insensitive_glob(pattern): - """Helper for case insensitive glob.glob()""" - - def either(c): - return '[%s%s]' % (c.lower(), c.upper()) if c.isalpha() else c - return glob.glob(''.join(map(either, pattern))) - - name_and_tags: List[str] = [] tags_not_name: List[str] = [] multiple_similar: List[str] = [] @@ -137,10 +126,6 @@ def main(): # Try to find a near match - # stem = new_fname.split(".")[0] - # matches = insensitive_glob(os.path.join(parent_dir, stem) + '*') - # match_count = len(matches) - # if match_count == 0: if process_no_matches: prompt = f"\n file={new_fname}\n title={new_title}\n artist={new_artist}: " # Use fzf to search diff --git a/app/utilities.py b/app/utilities.py index b8d9d8d..b769128 100755 --- a/app/utilities.py +++ b/app/utilities.py @@ -16,20 +16,6 @@ from log import log from models import Tracks -def create_track(session, path, normalise=None): - """ - Create track in database from passed path. - - Return track. - """ - - track = Tracks(session, path) - - set_track_metadata(session, track) - if normalise or normalise is None and Config.NORMALISE_ON_IMPORT: - normalise_track(path) - - def check_db(session): """ Database consistency check. @@ -44,7 +30,7 @@ def check_db(session): db_paths = set([a.path for a in Tracks.get_all(session)]) os_paths_list = [] - for root, dirs, files in os.walk(Config.ROOT): + for root, _dirs, files in os.walk(Config.ROOT): for f in files: path = os.path.join(root, f) ext = os.path.splitext(f)[1]