Compare commits
6 Commits
1749f0a0b8
...
19b1bf3fde
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19b1bf3fde | ||
|
|
316b4708c6 | ||
|
|
4fd9a0381f | ||
|
|
88cce738d7 | ||
|
|
9720c11ecc | ||
|
|
ca4c490091 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@ StudioPlaylist.png
|
|||||||
tmp/
|
tmp/
|
||||||
.coverage
|
.coverage
|
||||||
profile_output*
|
profile_output*
|
||||||
|
kae.py
|
||||||
|
|||||||
@ -140,6 +140,6 @@ class Config(object):
|
|||||||
WIKIPEDIA_ON_NEXT = False
|
WIKIPEDIA_ON_NEXT = False
|
||||||
|
|
||||||
# These rely on earlier definitions
|
# These rely on earlier definitions
|
||||||
HIDE_PLAYED_MODE = HIDE_PLAYED_MODE_SECTIONS
|
HIDE_PLAYED_MODE = HIDE_PLAYED_MODE_TRACKS
|
||||||
IMPORT_DESTINATION = os.path.join(ROOT, "Singles")
|
IMPORT_DESTINATION = os.path.join(ROOT, "Singles")
|
||||||
REPLACE_FILES_DEFAULT_DESTINATION = os.path.dirname(REPLACE_FILES_DEFAULT_SOURCE)
|
REPLACE_FILES_DEFAULT_DESTINATION = os.path.dirname(REPLACE_FILES_DEFAULT_SOURCE)
|
||||||
|
|||||||
@ -35,6 +35,7 @@ from classes import (
|
|||||||
)
|
)
|
||||||
from config import Config
|
from config import Config
|
||||||
from helpers import (
|
from helpers import (
|
||||||
|
audio_file_extension,
|
||||||
file_is_unreadable,
|
file_is_unreadable,
|
||||||
get_tags,
|
get_tags,
|
||||||
show_OK,
|
show_OK,
|
||||||
@ -104,16 +105,14 @@ class FileImporter:
|
|||||||
# variable or an instance variable are effectively the same thing.
|
# variable or an instance variable are effectively the same thing.
|
||||||
workers: dict[str, DoTrackImport] = {}
|
workers: dict[str, DoTrackImport] = {}
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, base_model: PlaylistModel, row_number: int) -> None:
|
||||||
self, base_model: PlaylistModel, row_number: Optional[int] = None
|
|
||||||
) -> None:
|
|
||||||
"""
|
"""
|
||||||
Initialise the FileImporter singleton instance.
|
Initialise the FileImporter singleton instance.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
log.debug(f"FileImporter.__init__({base_model=}, {row_number=})")
|
||||||
|
|
||||||
# Create ModelData
|
# Create ModelData
|
||||||
if not row_number:
|
|
||||||
row_number = base_model.rowCount()
|
|
||||||
self.model_data = ThreadData(base_model=base_model, row_number=row_number)
|
self.model_data = ThreadData(base_model=base_model, row_number=row_number)
|
||||||
|
|
||||||
# Data structure to track files to import
|
# Data structure to track files to import
|
||||||
@ -202,6 +201,7 @@ class FileImporter:
|
|||||||
self.sort_track_match_data(tfd)
|
self.sort_track_match_data(tfd)
|
||||||
selection = self.get_user_choices(tfd)
|
selection = self.get_user_choices(tfd)
|
||||||
if self.process_selection(tfd, selection):
|
if self.process_selection(tfd, selection):
|
||||||
|
if self.extension_check(tfd):
|
||||||
if self.validate_file_data(tfd):
|
if self.validate_file_data(tfd):
|
||||||
tfd.import_this_file = True
|
tfd.import_this_file = True
|
||||||
|
|
||||||
@ -237,6 +237,26 @@ class FileImporter:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def extension_check(self, tfd: TrackFileData) -> bool:
|
||||||
|
"""
|
||||||
|
If we are replacing an existing file, check that the correct file
|
||||||
|
extension of the replacement file matches the existing file
|
||||||
|
extension and return True if it does (or if there is no exsting
|
||||||
|
file), else False.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not tfd.file_path_to_remove:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if tfd.file_path_to_remove.endswith(audio_file_extension(tfd.source_path)):
|
||||||
|
return True
|
||||||
|
|
||||||
|
tfd.error = (
|
||||||
|
f"Existing file ({tfd.file_path_to_remove}) has a different "
|
||||||
|
f"extension to replacement file ({tfd.source_path})"
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
def find_similar(self, tfd: TrackFileData) -> None:
|
def find_similar(self, tfd: TrackFileData) -> None:
|
||||||
"""
|
"""
|
||||||
- Search title in existing tracks
|
- Search title in existing tracks
|
||||||
@ -445,7 +465,8 @@ class FileImporter:
|
|||||||
if tfd.track_id == 0 and tfd.destination_path != tfd.file_path_to_remove:
|
if tfd.track_id == 0 and tfd.destination_path != tfd.file_path_to_remove:
|
||||||
while os.path.exists(tfd.destination_path):
|
while os.path.exists(tfd.destination_path):
|
||||||
msg = (
|
msg = (
|
||||||
f"New import requested but default destination path ({tfd.destination_path})"
|
"New import requested but default destination path"
|
||||||
|
f" ({tfd.destination_path})"
|
||||||
" already exists. Click OK and choose where to save this track"
|
" already exists. Click OK and choose where to save this track"
|
||||||
)
|
)
|
||||||
show_OK(title="Desintation path exists", msg=msg, parent=None)
|
show_OK(title="Desintation path exists", msg=msg, parent=None)
|
||||||
@ -627,7 +648,8 @@ class DoTrackImport(QThread):
|
|||||||
f"Importing {os.path.basename(self.import_file_path)}", 5000
|
f"Importing {os.path.basename(self.import_file_path)}", 5000
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get audio metadata in this thread rather than calling function to save interactive time
|
# Get audio metadata in this thread rather than calling
|
||||||
|
# function to save interactive time
|
||||||
self.audio_metadata = helpers.get_audio_metadata(self.import_file_path)
|
self.audio_metadata = helpers.get_audio_metadata(self.import_file_path)
|
||||||
|
|
||||||
# Remove old file if so requested
|
# Remove old file if so requested
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import tempfile
|
|||||||
from PyQt6.QtWidgets import QInputDialog, QMainWindow, QMessageBox, QWidget
|
from PyQt6.QtWidgets import QInputDialog, QMainWindow, QMessageBox, QWidget
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
|
import filetype
|
||||||
from mutagen.flac import FLAC # type: ignore
|
from mutagen.flac import FLAC # type: ignore
|
||||||
from mutagen.mp3 import MP3 # type: ignore
|
from mutagen.mp3 import MP3 # type: ignore
|
||||||
from pydub import AudioSegment, effects
|
from pydub import AudioSegment, effects
|
||||||
@ -50,6 +51,14 @@ def ask_yes_no(
|
|||||||
return button == QMessageBox.StandardButton.Yes
|
return button == QMessageBox.StandardButton.Yes
|
||||||
|
|
||||||
|
|
||||||
|
def audio_file_extension(fpath: str) -> str | None:
|
||||||
|
"""
|
||||||
|
Return the correct extension for this type of file.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return filetype.guess(fpath).extension
|
||||||
|
|
||||||
|
|
||||||
def fade_point(
|
def fade_point(
|
||||||
audio_segment: AudioSegment,
|
audio_segment: AudioSegment,
|
||||||
fade_threshold: float = 0.0,
|
fade_threshold: float = 0.0,
|
||||||
@ -94,6 +103,9 @@ def file_is_unreadable(path: Optional[str]) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def get_audio_segment(path: str) -> Optional[AudioSegment]:
|
def get_audio_segment(path: str) -> Optional[AudioSegment]:
|
||||||
|
if not path.endswith(audio_file_extension(path)):
|
||||||
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if path.endswith(".mp3"):
|
if path.endswith(".mp3"):
|
||||||
return AudioSegment.from_mp3(path)
|
return AudioSegment.from_mp3(path)
|
||||||
|
|||||||
27
app/log.py
27
app/log.py
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Standard library imports
|
# Standard library imports
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from functools import wraps
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
@ -108,4 +109,30 @@ def handle_exception(exc_type, exc_value, exc_traceback):
|
|||||||
QMessageBox.critical(None, "Application Error", msg)
|
QMessageBox.critical(None, "Application Error", msg)
|
||||||
|
|
||||||
|
|
||||||
|
def truncate_large(obj, limit=5):
|
||||||
|
"""Helper to truncate large lists or other iterables."""
|
||||||
|
if isinstance(obj, (list, tuple, set)):
|
||||||
|
if len(obj) > limit:
|
||||||
|
return f"{type(obj).__name__}(len={len(obj)}, items={list(obj)[:limit]}...)"
|
||||||
|
|
||||||
|
return repr(obj)
|
||||||
|
|
||||||
|
|
||||||
|
def log_call(func):
|
||||||
|
@wraps(func)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
args_repr = [truncate_large(a) for a in args]
|
||||||
|
kwargs_repr = [f"{k}={truncate_large(v)}" for k, v in kwargs.items()]
|
||||||
|
params_repr = ", ".join(args_repr + kwargs_repr)
|
||||||
|
log.debug(f"call {func.__name__}({params_repr})")
|
||||||
|
try:
|
||||||
|
result = func(*args, **kwargs)
|
||||||
|
log.debug(f"return {func.__name__}: {truncate_large(result)}")
|
||||||
|
return result
|
||||||
|
except Exception as e:
|
||||||
|
log.debug(f"exception in {func.__name__}: {e}")
|
||||||
|
raise
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
sys.excepthook = handle_exception
|
sys.excepthook = handle_exception
|
||||||
|
|||||||
@ -63,6 +63,7 @@ from sqlalchemy.orm.session import Session
|
|||||||
import stackprinter # type: ignore
|
import stackprinter # type: ignore
|
||||||
|
|
||||||
# App imports
|
# App imports
|
||||||
|
from audacity_controller import AudacityController
|
||||||
from classes import (
|
from classes import (
|
||||||
ApplicationError,
|
ApplicationError,
|
||||||
Filter,
|
Filter,
|
||||||
@ -72,8 +73,8 @@ from classes import (
|
|||||||
from config import Config
|
from config import Config
|
||||||
from dialogs import TrackSelectDialog
|
from dialogs import TrackSelectDialog
|
||||||
from file_importer import FileImporter
|
from file_importer import FileImporter
|
||||||
from helpers import ask_yes_no, file_is_unreadable, get_name
|
from log import log, log_call
|
||||||
from log import log
|
from helpers import ask_yes_no, file_is_unreadable, get_name, show_warning
|
||||||
from models import db, Playdates, PlaylistRows, Playlists, Queries, Settings, Tracks
|
from models import db, Playdates, PlaylistRows, Playlists, Queries, Settings, Tracks
|
||||||
from music_manager import RowAndTrack, track_sequence
|
from music_manager import RowAndTrack, track_sequence
|
||||||
from playlistmodel import PlaylistModel, PlaylistProxyModel
|
from playlistmodel import PlaylistModel, PlaylistProxyModel
|
||||||
@ -1208,6 +1209,13 @@ class Window(QMainWindow):
|
|||||||
self.load_last_playlists()
|
self.load_last_playlists()
|
||||||
self.stop_autoplay = False
|
self.stop_autoplay = False
|
||||||
|
|
||||||
|
# Set up for Audacity
|
||||||
|
try:
|
||||||
|
self.ac: Optional[AudacityController] = AudacityController()
|
||||||
|
except ApplicationError as e:
|
||||||
|
self.ac = None
|
||||||
|
show_warning(self, "Audacity error", str(e))
|
||||||
|
|
||||||
# # # # # # # # # # Overrides # # # # # # # # # #
|
# # # # # # # # # # Overrides # # # # # # # # # #
|
||||||
|
|
||||||
def closeEvent(self, event: Optional[QCloseEvent]) -> None:
|
def closeEvent(self, event: Optional[QCloseEvent]) -> None:
|
||||||
@ -1467,6 +1475,7 @@ class Window(QMainWindow):
|
|||||||
|
|
||||||
return Playlists(session, name, template_id)
|
return Playlists(session, name, template_id)
|
||||||
|
|
||||||
|
@log_call
|
||||||
def _open_playlist(self, playlist: Playlists, is_template: bool = False) -> int:
|
def _open_playlist(self, playlist: Playlists, is_template: bool = False) -> int:
|
||||||
"""
|
"""
|
||||||
With passed playlist:
|
With passed playlist:
|
||||||
@ -1989,6 +1998,7 @@ class Window(QMainWindow):
|
|||||||
dlg.exec()
|
dlg.exec()
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
@log_call
|
||||||
def load_last_playlists(self) -> None:
|
def load_last_playlists(self) -> None:
|
||||||
"""Load the playlists that were open when the last session closed"""
|
"""Load the playlists that were open when the last session closed"""
|
||||||
|
|
||||||
@ -2725,6 +2735,7 @@ class Window(QMainWindow):
|
|||||||
self.catch_return_key = False
|
self.catch_return_key = False
|
||||||
self.show_status_message("Play controls: Enabled", 0)
|
self.show_status_message("Play controls: Enabled", 0)
|
||||||
# Re-enable 10ms timer (see above)
|
# Re-enable 10ms timer (see above)
|
||||||
|
log.debug(f"issue287: {self.timer10.isActive()=}")
|
||||||
if not self.timer10.isActive():
|
if not self.timer10.isActive():
|
||||||
self.timer10.start(10)
|
self.timer10.start(10)
|
||||||
log.debug("issue223: update_clocks: 10ms timer enabled")
|
log.debug("issue223: update_clocks: 10ms timer enabled")
|
||||||
|
|||||||
@ -46,7 +46,7 @@ from helpers import (
|
|||||||
remove_substring_case_insensitive,
|
remove_substring_case_insensitive,
|
||||||
set_track_metadata,
|
set_track_metadata,
|
||||||
)
|
)
|
||||||
from log import log
|
from log import log, log_call
|
||||||
from models import db, NoteColours, Playdates, PlaylistRows, Tracks
|
from models import db, NoteColours, Playdates, PlaylistRows, Tracks
|
||||||
from music_manager import RowAndTrack, track_sequence
|
from music_manager import RowAndTrack, track_sequence
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,6 @@ from PyQt6.QtWidgets import (
|
|||||||
# import line_profiler
|
# import line_profiler
|
||||||
|
|
||||||
# App imports
|
# App imports
|
||||||
from audacity_controller import AudacityController
|
|
||||||
from classes import ApplicationError, Col, MusicMusterSignals, PlaylistStyle, TrackInfo
|
from classes import ApplicationError, Col, MusicMusterSignals, PlaylistStyle, TrackInfo
|
||||||
from config import Config
|
from config import Config
|
||||||
from dialogs import TrackSelectDialog
|
from dialogs import TrackSelectDialog
|
||||||
@ -44,7 +43,7 @@ from helpers import (
|
|||||||
show_OK,
|
show_OK,
|
||||||
show_warning,
|
show_warning,
|
||||||
)
|
)
|
||||||
from log import log
|
from log import log, log_call
|
||||||
from models import db, Settings
|
from models import db, Settings
|
||||||
from music_manager import track_sequence
|
from music_manager import track_sequence
|
||||||
from playlistmodel import PlaylistModel, PlaylistProxyModel
|
from playlistmodel import PlaylistModel, PlaylistProxyModel
|
||||||
@ -308,13 +307,6 @@ class PlaylistTab(QTableView):
|
|||||||
self.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
|
self.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
|
||||||
self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
|
self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
|
||||||
|
|
||||||
# Set up for Audacity
|
|
||||||
try:
|
|
||||||
self.ac: Optional[AudacityController] = AudacityController()
|
|
||||||
except ApplicationError as e:
|
|
||||||
self.ac = None
|
|
||||||
show_warning(self.musicmuster, "Audacity error", str(e))
|
|
||||||
|
|
||||||
# Load model, set column widths
|
# Load model, set column widths
|
||||||
self.setModel(model)
|
self.setModel(model)
|
||||||
self._set_column_widths()
|
self._set_column_widths()
|
||||||
@ -546,8 +538,8 @@ class PlaylistTab(QTableView):
|
|||||||
track_path = base_model.get_row_info(model_row_number).path
|
track_path = base_model.get_row_info(model_row_number).path
|
||||||
|
|
||||||
# Open/import in/from Audacity
|
# Open/import in/from Audacity
|
||||||
if track_row and not this_is_current_row:
|
if track_row and not this_is_current_row and self.musicmuster.ac:
|
||||||
if self.ac and track_path == self.ac.path:
|
if track_path == self.musicmuster.ac.path:
|
||||||
# This track was opened in Audacity
|
# This track was opened in Audacity
|
||||||
self._add_context_menu(
|
self._add_context_menu(
|
||||||
"Update from Audacity",
|
"Update from Audacity",
|
||||||
@ -657,8 +649,8 @@ class PlaylistTab(QTableView):
|
|||||||
that we have an edit open.
|
that we have an edit open.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.ac:
|
if self.musicmuster.ac:
|
||||||
self.ac.path = None
|
self.musicmuster.ac.path = None
|
||||||
|
|
||||||
def clear_selection(self) -> None:
|
def clear_selection(self) -> None:
|
||||||
"""Unselect all tracks and reset drag mode"""
|
"""Unselect all tracks and reset drag mode"""
|
||||||
@ -860,10 +852,10 @@ class PlaylistTab(QTableView):
|
|||||||
Import current Audacity track to passed row
|
Import current Audacity track to passed row
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not self.ac:
|
if not self.musicmuster.ac:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
self.ac.export()
|
self.ac.musicmuster.export()
|
||||||
self._rescan(row_number)
|
self._rescan(row_number)
|
||||||
except ApplicationError as e:
|
except ApplicationError as e:
|
||||||
show_warning(self.musicmuster, "Audacity error", str(e))
|
show_warning(self.musicmuster, "Audacity error", str(e))
|
||||||
@ -920,15 +912,16 @@ class PlaylistTab(QTableView):
|
|||||||
Open track in passed row in Audacity
|
Open track in passed row in Audacity
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if not self.musicmuster.ac:
|
||||||
|
return
|
||||||
|
|
||||||
path = self.get_base_model().get_row_track_path(row_number)
|
path = self.get_base_model().get_row_track_path(row_number)
|
||||||
if not path:
|
if not path:
|
||||||
log.error(f"_open_in_audacity: can't get path for {row_number=}")
|
log.error(f"_open_in_audacity: can't get path for {row_number=}")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not self.ac:
|
self.musicmuster.ac.open(path)
|
||||||
self.ac = AudacityController()
|
|
||||||
self.ac.open(path)
|
|
||||||
except ApplicationError as e:
|
except ApplicationError as e:
|
||||||
show_warning(self.musicmuster, "Audacity error", str(e))
|
show_warning(self.musicmuster, "Audacity error", str(e))
|
||||||
|
|
||||||
|
|||||||
@ -33,6 +33,8 @@ dependencies = [
|
|||||||
"types-pyyaml>=6.0.12.20241230",
|
"types-pyyaml>=6.0.12.20241230",
|
||||||
"dogpile-cache>=1.3.4",
|
"dogpile-cache>=1.3.4",
|
||||||
"pdbpp>=0.10.3",
|
"pdbpp>=0.10.3",
|
||||||
|
"filetype>=1.2.0",
|
||||||
|
"black>=25.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependency-groups]
|
[dependency-groups]
|
||||||
@ -63,6 +65,9 @@ python_version = 3.11
|
|||||||
warn_unused_configs = true
|
warn_unused_configs = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
|
|
||||||
|
[tool.pylsp.plugins.pycodestyle]
|
||||||
|
maxLineLength = 88
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
addopts = "--exitfirst --showlocals --capture=no"
|
addopts = "--exitfirst --showlocals --capture=no"
|
||||||
pythonpath = [".", "app"]
|
pythonpath = [".", "app"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user