From b399abb471159d3ef3d093de3e0db0f719a05b89 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Wed, 8 Nov 2023 23:18:33 +0000 Subject: [PATCH] WIP V3: section timings in place --- app/playlistmodel.py | 58 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/app/playlistmodel.py b/app/playlistmodel.py index 33b4d6a..a61ac55 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -339,7 +339,7 @@ class PlaylistModel(QAbstractTableModel): self.signals.span_cells_signal.emit( row, HEADER_NOTES_COLUMN, 1, self.columnCount() - 1 ) - return QVariant(prd.note) + return QVariant(self.header_text(prd)) else: return QVariant() @@ -459,6 +459,60 @@ class PlaylistModel(QAbstractTableModel): return QVariant() + def header_text(self, prd: PlaylistRowData) -> str: + """ + Process possible section timing directives embeded in header + """ + + count: int = 0 + duration: int = 0 + + if prd.note.endswith("+"): + # This header is the start of a timed section + for row_number in range(prd.plr_rownum + 1, len(self.playlist_rows)): + row_prd = self.playlist_rows[row_number] + if self.is_header_row(row_number): + if row_prd.note.endswith("-"): + return ( + f"{prd.note[:-1].strip()} " + f"[{count} tracks, {ms_to_mmss(duration)} unplayed]" + ) + else: + continue + else: + count += 1 + if not row_prd.played: + duration += row_prd.duration + return ( + f"{prd.note[:-1].strip()} " + f"[{count} tracks, {ms_to_mmss(duration)} unplayed (to end of playlist)]" + ) + elif prd.note.endswith("="): + # Show subtotal + for row_number in range(prd.plr_rownum - 1, -1, -1): + row_prd = self.playlist_rows[row_number] + if self.is_header_row(row_number): + if row_prd.note.endswith(("+", "=")): + stripped_note = prd.note[:-1].strip() + if stripped_note: + return ( + f"{stripped_note} [{count} tracks, " + f"{ms_to_mmss(duration)} unplayed]" + ) + else: + return ( + f"[Subtotal: {count} tracks, " + f"{ms_to_mmss(duration)} unplayed]" + ) + else: + continue + else: + count += 1 + if not row_prd.played: + duration += row_prd.duration + + return prd.note + def is_header_row(self, row_number: int) -> bool: """ Return True if row is a header row, else False @@ -656,7 +710,7 @@ class PlaylistModel(QAbstractTableModel): plr = session.get(PlaylistRows, plrid) if plr: # Check this isn't a header row - if plr.track is None: + if self.is_header_row(row_number): return # Check track is readable if file_is_unreadable(plr.track.path):