Compare commits

..

3 Commits

Author SHA1 Message Date
Keith Edmunds
ccbe8fdb1b Import tracks from command line
songdb.py -i FILENAME
2021-08-21 16:46:37 +01:00
Keith Edmunds
762a41bec6 Add total time of selected tracks to status bar 2021-08-21 14:22:55 +01:00
Keith Edmunds
7ed7730574 Clean up timers when track ends 2021-08-15 17:03:19 +01:00
4 changed files with 57 additions and 10 deletions

View File

@ -71,6 +71,8 @@ class Window(QMainWindow, Ui_MainWindow):
self.menuTest.menuAction().setVisible(Config.TESTMODE) self.menuTest.menuAction().setVisible(Config.TESTMODE)
self.set_main_window_size() self.set_main_window_size()
self.lblSumPlaytime = QLabel("")
self.statusbar.addPermanentWidget(self.lblSumPlaytime)
self.visible_playlist_tab = self.tabPlaylist.currentWidget self.visible_playlist_tab = self.tabPlaylist.currentWidget
@ -252,9 +254,10 @@ class Window(QMainWindow, Ui_MainWindow):
self.current_track = None self.current_track = None
# Clean up display # Clean up display
self.label_end_timer.setText("00:00")
self.frame_silent.setStyleSheet("")
self.frame_fade.setStyleSheet("") self.frame_fade.setStyleSheet("")
self.label_silent_timer.setText("00:00")
self.frame_silent.setStyleSheet("")
self.label_end_timer.setText("00:00")
self.update_headers() self.update_headers()
# Enable controls # Enable controls

View File

@ -89,6 +89,8 @@ class PlaylistTab(QTableWidget):
self.customContextMenuRequested.connect(self._context_menu) self.customContextMenuRequested.connect(self._context_menu)
self.viewport().installEventFilter(self) self.viewport().installEventFilter(self)
self.itemSelectionChanged.connect(self._select_event)
self.current_track_start_time = None self.current_track_start_time = None
self.played_tracks = [] self.played_tracks = []
@ -1001,8 +1003,29 @@ class PlaylistTab(QTableWidget):
PlaylistTracks.add_track( PlaylistTracks.add_track(
session, self.id, self._get_row_id(row), row) session, self.id, self._get_row_id(row), row)
def _set_column_widths(self): def _select_event(self):
"""
Called when item selection changes.
If multiple rows are selected, display sum of durations in status bar.
"""
# Clear label
self.master_process.lblSumPlaytime.setText("")
rows = set([item.row() for item in self.selectedItems()])
notes = self._meta_get_notes()
ms = 0
with Session() as session:
for row in rows:
if row in notes:
continue
ms += Tracks.get_duration(session, self._get_row_id(row))
# Only paint message if there are selected track rows
if ms > 0:
self.master_process.lblSumPlaytime.setText(
f"Selected duration: {helpers.ms_to_mmss(ms)}")
def _set_column_widths(self):
# Column widths from settings # Column widths from settings
with Session() as session: with Session() as session:
for column in range(self.columnCount()): for column in range(self.columnCount()):

View File

@ -21,12 +21,16 @@ def main():
# Parse command line # Parse command line
p = argparse.ArgumentParser() p = argparse.ArgumentParser()
p.add_argument('-u', '--update', # Only allow one option to be specified
action="store_true", dest="update", group = p.add_mutually_exclusive_group()
default=False, help="Update database")
p.add_argument('-f', '--full-update', group.add_argument('-u', '--update',
action="store_true", dest="full_update", action="store_true", dest="update",
default=False, help="Update database") default=False, help="Update database")
group.add_argument('-f', '--full-update',
action="store_true", dest="full_update",
default=False, help="Update database")
group.add_argument('-i', '--import', dest="fname", help="Input file")
args = p.parse_args() args = p.parse_args()
# Run as required # Run as required
@ -38,13 +42,18 @@ def main():
INFO("Full update of database") INFO("Full update of database")
with Session() as session: with Session() as session:
full_update_db(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)
else: else:
INFO("No action specified") INFO("No action specified")
INFO("Finished") INFO("Finished")
def create_track_from_file(session, path): def create_track_from_file(session, path, verbose=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.
@ -52,13 +61,19 @@ def create_track_from_file(session, path):
Return track. Return track.
""" """
if verbose:
INFO(f"Importing {path}...")
track = Tracks.get_or_create(session, path) track = Tracks.get_or_create(session, path)
if verbose:
INFO("Get track info...")
t = get_music_info(path) t = get_music_info(path)
track.title = t['title'] track.title = t['title']
track.artist = t['artist'] track.artist = t['artist']
track.duration = int(round( track.duration = int(round(
t['duration'], Config.MILLISECOND_SIGFIGS) * 1000) t['duration'], Config.MILLISECOND_SIGFIGS) * 1000)
if verbose:
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)
track.fade_at = round(fade_point(audio) / 1000, track.fade_at = round(fade_point(audio) / 1000,
@ -69,6 +84,8 @@ def create_track_from_file(session, path):
session.commit() session.commit()
if Config.NORMALISE_ON_IMPORT: if Config.NORMALISE_ON_IMPORT:
if verbose:
INFO("Normalise...")
# Check type # Check type
ftype = os.path.splitext(path)[1][1:] ftype = os.path.splitext(path)[1][1:]
if ftype not in ['mp3', 'flac']: if ftype not in ['mp3', 'flac']:

4
mmimport Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
# cd /home/kae/mm
# MYSQL_CONNECT="mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_prod" ROOT="/home/kae/music" direnv exec .
app/songdb.py -i "$1"