Compare commits
3 Commits
0e3e30391b
...
ccbe8fdb1b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccbe8fdb1b | ||
|
|
762a41bec6 | ||
|
|
7ed7730574 |
@ -71,6 +71,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
self.menuTest.menuAction().setVisible(Config.TESTMODE)
|
||||
self.set_main_window_size()
|
||||
self.lblSumPlaytime = QLabel("")
|
||||
self.statusbar.addPermanentWidget(self.lblSumPlaytime)
|
||||
|
||||
self.visible_playlist_tab = self.tabPlaylist.currentWidget
|
||||
|
||||
@ -252,9 +254,10 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
self.current_track = None
|
||||
|
||||
# Clean up display
|
||||
self.label_end_timer.setText("00:00")
|
||||
self.frame_silent.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()
|
||||
|
||||
# Enable controls
|
||||
|
||||
@ -89,6 +89,8 @@ class PlaylistTab(QTableWidget):
|
||||
self.customContextMenuRequested.connect(self._context_menu)
|
||||
self.viewport().installEventFilter(self)
|
||||
|
||||
self.itemSelectionChanged.connect(self._select_event)
|
||||
|
||||
self.current_track_start_time = None
|
||||
self.played_tracks = []
|
||||
|
||||
@ -1001,8 +1003,29 @@ class PlaylistTab(QTableWidget):
|
||||
PlaylistTracks.add_track(
|
||||
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
|
||||
with Session() as session:
|
||||
for column in range(self.columnCount()):
|
||||
|
||||
@ -21,12 +21,16 @@ def main():
|
||||
|
||||
# Parse command line
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument('-u', '--update',
|
||||
action="store_true", dest="update",
|
||||
default=False, help="Update database")
|
||||
p.add_argument('-f', '--full-update',
|
||||
action="store_true", dest="full_update",
|
||||
default=False, help="Update database")
|
||||
# Only allow one option to be specified
|
||||
group = p.add_mutually_exclusive_group()
|
||||
|
||||
group.add_argument('-u', '--update',
|
||||
action="store_true", dest="update",
|
||||
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()
|
||||
|
||||
# Run as required
|
||||
@ -38,13 +42,18 @@ def main():
|
||||
INFO("Full update of database")
|
||||
with Session() as 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:
|
||||
INFO("No action specified")
|
||||
|
||||
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
|
||||
if path already in database.
|
||||
@ -52,13 +61,19 @@ def create_track_from_file(session, path):
|
||||
Return track.
|
||||
"""
|
||||
|
||||
if verbose:
|
||||
INFO(f"Importing {path}...")
|
||||
track = Tracks.get_or_create(session, path)
|
||||
if verbose:
|
||||
INFO("Get track info...")
|
||||
t = get_music_info(path)
|
||||
track.title = t['title']
|
||||
track.artist = t['artist']
|
||||
track.duration = int(round(
|
||||
t['duration'], Config.MILLISECOND_SIGFIGS) * 1000)
|
||||
|
||||
if verbose:
|
||||
INFO("Parse for start, fade and silence...")
|
||||
audio = get_audio_segment(path)
|
||||
track.start_gap = leading_silence(audio)
|
||||
track.fade_at = round(fade_point(audio) / 1000,
|
||||
@ -69,6 +84,8 @@ def create_track_from_file(session, path):
|
||||
session.commit()
|
||||
|
||||
if Config.NORMALISE_ON_IMPORT:
|
||||
if verbose:
|
||||
INFO("Normalise...")
|
||||
# Check type
|
||||
ftype = os.path.splitext(path)[1][1:]
|
||||
if ftype not in ['mp3', 'flac']:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user