diff --git a/app/helpers.py b/app/helpers.py index be197ff..389acfc 100644 --- a/app/helpers.py +++ b/app/helpers.py @@ -252,7 +252,12 @@ def send_mail(to_addr, from_addr, subj, body): s.quit() -def ms_to_mmss(ms: Optional[int], decimals: int = 0, negative: bool = False) -> str: +def ms_to_mmss( + ms: Optional[int], + decimals: int = 0, + negative: bool = False, + none: Optional[str] = None, +) -> str: """Convert milliseconds to mm:ss""" minutes: int @@ -260,7 +265,10 @@ def ms_to_mmss(ms: Optional[int], decimals: int = 0, negative: bool = False) -> seconds: float if not ms: - return "-" + if none: + return none + else: + return "-" sign = "" if ms < 0: if negative: diff --git a/app/playlistmodel.py b/app/playlistmodel.py index a61ac55..8d1796a 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -485,24 +485,28 @@ class PlaylistModel(QAbstractTableModel): duration += row_prd.duration return ( f"{prd.note[:-1].strip()} " - f"[{count} tracks, {ms_to_mmss(duration)} unplayed (to end of playlist)]" + f"[{count} tracks, {ms_to_mmss(duration, none='none')} " + "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("-"): + # There was no start of section + return prd.note if row_prd.note.endswith(("+", "=")): stripped_note = prd.note[:-1].strip() if stripped_note: return ( - f"{stripped_note} [{count} tracks, " + f"{stripped_note} [{count} track{'s' if count > 1 else ''}, " f"{ms_to_mmss(duration)} unplayed]" ) else: return ( - f"[Subtotal: {count} tracks, " - f"{ms_to_mmss(duration)} unplayed]" + f"[Subtotal: {count} track{'s' if count > 1 else ''}, " + f"{ms_to_mmss(duration, none='none')} unplayed]" ) else: continue