Show section end time for all unplayed tracks
This commit is contained in:
parent
ab8da0a312
commit
2db407edc5
@ -1461,20 +1461,32 @@ class PlaylistTab(QTableWidget):
|
||||
return userdata_item.data(role)
|
||||
|
||||
def _get_section_timing_string(
|
||||
self, total_time: int, unplayed_time: int, no_end: bool = False
|
||||
self,
|
||||
unplayed_time: int,
|
||||
end_time: Optional[datetime] = None,
|
||||
no_end: bool = False,
|
||||
) -> str:
|
||||
"""Return string describing section duration"""
|
||||
"""
|
||||
Return string describing section duration. If end_time specified, also
|
||||
return section end time calculated as end_time + unplayed duration.
|
||||
"""
|
||||
|
||||
total_duration = ms_to_mmss(total_time)
|
||||
if unplayed_time:
|
||||
unplayed_duration = ms_to_mmss(unplayed_time)
|
||||
unplayed_duration = ms_to_mmss(unplayed_time)
|
||||
if end_time:
|
||||
section_end_time = end_time + timedelta(milliseconds=unplayed_time)
|
||||
end_str = (
|
||||
"[End time for all unplayed tracks in section: "
|
||||
+ section_end_time.strftime(Config.TRACK_TIME_FORMAT)
|
||||
+ "]"
|
||||
)
|
||||
else:
|
||||
unplayed_duration = "[No unplayed tracks]"
|
||||
end_str = ""
|
||||
|
||||
caveat = ""
|
||||
if no_end:
|
||||
caveat = " (to end of playlist)"
|
||||
|
||||
return f" {unplayed_duration} ({total_duration}){caveat}"
|
||||
return f" {unplayed_duration} {caveat} {end_str}"
|
||||
|
||||
def _get_selected_row(self) -> Optional[int]:
|
||||
"""
|
||||
@ -2398,26 +2410,24 @@ class PlaylistTab(QTableWidget):
|
||||
self.save_playlist(session)
|
||||
self._update_start_end_times(session)
|
||||
|
||||
def _track_time_between_rows(
|
||||
def _unplayed_track_time_between_rows(
|
||||
self, session: scoped_session, from_plr: PlaylistRows, to_plr: PlaylistRows
|
||||
) -> Tuple[int, int]:
|
||||
) -> int:
|
||||
"""
|
||||
Returns the (total duration of all tracks in rows between
|
||||
from_row and to_row inclusive, total unplayed time in those rows)
|
||||
Returns the total unplayed duration of all tracks in rows between
|
||||
from_row and to_row inclusive
|
||||
"""
|
||||
|
||||
plr_tracks = PlaylistRows.get_rows_with_tracks(
|
||||
session, self.playlist_id, from_plr.plr_rownum, to_plr.plr_rownum
|
||||
)
|
||||
|
||||
total_time = 0
|
||||
total_time = sum([a.track.duration for a in plr_tracks if a.track.duration])
|
||||
unplayed_time = 0
|
||||
unplayed_time = sum(
|
||||
[a.track.duration for a in plr_tracks if a.track.duration and not a.played]
|
||||
)
|
||||
|
||||
return (total_time, unplayed_time)
|
||||
return unplayed_time
|
||||
|
||||
def _update_row_track_info(
|
||||
self, session: scoped_session, row: int, track: Tracks
|
||||
@ -2451,6 +2461,21 @@ class PlaylistTab(QTableWidget):
|
||||
|
||||
section_start_rows: List[PlaylistRows] = []
|
||||
subtotal_from: Optional[PlaylistRows] = None
|
||||
active_row: Optional[int] = None
|
||||
active_endtime: Optional[datetime] = None
|
||||
current_row_prlid = self.musicmuster.current_track.plr_id
|
||||
if current_row_prlid:
|
||||
current_row = self._plrid_to_row_number(current_row_prlid)
|
||||
if current_row:
|
||||
active_row = current_row
|
||||
active_end = self.musicmuster.current_track.end_time
|
||||
else:
|
||||
previous_row_plrid = self.musicmuster.previous_track.plr_id
|
||||
if previous_row_plrid:
|
||||
previous_row = self._plrid_to_row_number(previous_row_plrid)
|
||||
if previous_row:
|
||||
active_row = previous_row
|
||||
active_end = self.musicmuster.previous_track.end_time
|
||||
|
||||
header_rows = [
|
||||
self._get_row_plr_id(row_number)
|
||||
@ -2469,12 +2494,19 @@ class PlaylistTab(QTableWidget):
|
||||
try:
|
||||
from_plr = section_start_rows.pop()
|
||||
to_plr = plr
|
||||
total_time, unplayed_time = self._track_time_between_rows(
|
||||
unplayed_time = self._unplayed_track_time_between_rows(
|
||||
session, from_plr, to_plr
|
||||
)
|
||||
time_str = self._get_section_timing_string(
|
||||
total_time, unplayed_time
|
||||
)
|
||||
if (
|
||||
active_row
|
||||
and active_row >= from_plr.plr_rownum
|
||||
and active_row <= to_plr.plr_rownum
|
||||
):
|
||||
time_str = self._get_section_timing_string(
|
||||
unplayed_time, active_end
|
||||
)
|
||||
else:
|
||||
time_str = self._get_section_timing_string(unplayed_time, None)
|
||||
self._set_row_header_text(
|
||||
session, from_plr.plr_rownum, from_plr.note + time_str
|
||||
)
|
||||
@ -2503,10 +2535,19 @@ class PlaylistTab(QTableWidget):
|
||||
return
|
||||
from_plr = subtotal_from
|
||||
to_plr = plr
|
||||
total_time, unplayed_time = self._track_time_between_rows(
|
||||
unplayed_time = self._unplayed_track_time_between_rows(
|
||||
session, subtotal_from, to_plr
|
||||
)
|
||||
time_str = self._get_section_timing_string(total_time, unplayed_time)
|
||||
if (
|
||||
active_row
|
||||
and active_row >= from_plr.plr_rownum
|
||||
and active_row <= to_plr.plr_rownum
|
||||
):
|
||||
time_str = self._get_section_timing_string(
|
||||
unplayed_time, active_end
|
||||
)
|
||||
else:
|
||||
time_str = self._get_section_timing_string(unplayed_time, None)
|
||||
|
||||
if to_plr.note.strip() == "=":
|
||||
leader_text = "Subtotal: "
|
||||
@ -2522,7 +2563,7 @@ class PlaylistTab(QTableWidget):
|
||||
if possible_plr:
|
||||
to_plr = possible_plr
|
||||
for from_plr in section_start_rows:
|
||||
total_time, unplayed_time = self._track_time_between_rows(
|
||||
unplayed_time = self._unplayed_track_time_between_rows(
|
||||
session, from_plr, to_plr
|
||||
)
|
||||
time_str = self._get_section_timing_string(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user