WIP V3: smarten up section timings

This commit is contained in:
Keith Edmunds 2023-11-08 23:34:17 +00:00
parent ab084ccf97
commit 2907514eb7
2 changed files with 18 additions and 6 deletions

View File

@ -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:

View File

@ -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