Compare commits

..

No commits in common. "405efee7324709a6ee3314356b10351c7e8efaaf" and "da751ee530f0862eb41ed54c8e6c801f06c0ae78" have entirely different histories.

3 changed files with 35 additions and 88 deletions

View File

@ -223,7 +223,7 @@ class ImportTrack(QObject):
print(e)
return
helpers.normalise_track(track.path)
self.playlist.insert_track(session=session, track=track, target_row=target_row)
self.playlist.insert_track(session, track, target_row)
# Insert next row under this one
target_row += 1
# We're importing potentially multiple tracks in a loop.

View File

@ -249,30 +249,18 @@ class PlaylistTab(QTableWidget):
else:
rowMapping[row + len(rows)] = targetRow + idx
colCount = self.columnCount()
with Session() as session:
for srcRow, tgtRow in sorted(rowMapping.items()):
# Messy: will be fixed with model/view implementation.
# If we just move the row, the displayed text will be
# used. That is incorrect for timing starts, ends and
# subtotals, so take text from database and use that.
is_header_row = self._get_row_track_id(srcRow) == 0
if is_header_row:
# This is a header row so save original text from db
source_plr = self._get_row_plr(session, srcRow)
if not source_plr:
print("Can't get source_plr in playlists:dropEvent()")
return
note_text = source_plr.note
# Copy to new locations
for srcRow, tgtRow in sorted(rowMapping.items()):
if self._get_row_track_id(srcRow):
# This is a track row
for col in range(0, colCount):
self.setItem(tgtRow, col, self.takeItem(srcRow, col))
# Fixup header text
if is_header_row:
target_item = self.item(tgtRow, HEADER_NOTES_COLUMN)
if target_item:
target_item.setText(note_text)
self.setSpan(tgtRow, HEADER_NOTES_COLUMN, 1, len(columns) - 1)
else:
self.setItem(
tgtRow,
HEADER_NOTES_COLUMN,
self.takeItem(srcRow, HEADER_NOTES_COLUMN),
)
self.setSpan(tgtRow, HEADER_NOTES_COLUMN, 1, len(columns) - 1)
for row in reversed(sorted(rowMapping.keys())):
self.removeRow(row)
self.resizeRowsToContents()
@ -652,8 +640,8 @@ class PlaylistTab(QTableWidget):
self,
session: scoped_session,
track: Tracks,
note: Optional[str] = "",
repaint: Optional[bool] = True,
note: str = "",
repaint: bool = True,
target_row: Optional[int] = None,
) -> None:
"""
@ -1461,32 +1449,20 @@ class PlaylistTab(QTableWidget):
return userdata_item.data(role)
def _get_section_timing_string(
self,
unplayed_time: int,
end_time: Optional[datetime] = None,
no_end: bool = False,
self, total_time: int, unplayed_time: int, no_end: bool = False
) -> str:
"""
Return string describing section duration. If end_time specified, also
return section end time calculated as end_time + unplayed duration.
"""
"""Return string describing section duration"""
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)
+ "]"
)
total_duration = ms_to_mmss(total_time)
if unplayed_time:
unplayed_duration = ms_to_mmss(unplayed_time)
else:
end_str = ""
unplayed_duration = "[No unplayed tracks]"
caveat = ""
if no_end:
caveat = " (to end of playlist)"
return f" {unplayed_duration} {caveat} {end_str}"
return f" {unplayed_duration} ({total_duration}){caveat}"
def _get_selected_row(self) -> Optional[int]:
"""
@ -2410,24 +2386,26 @@ class PlaylistTab(QTableWidget):
self.save_playlist(session)
self._update_start_end_times(session)
def _unplayed_track_time_between_rows(
def _track_time_between_rows(
self, session: scoped_session, from_plr: PlaylistRows, to_plr: PlaylistRows
) -> int:
) -> Tuple[int, int]:
"""
Returns the total unplayed duration of all tracks in rows between
from_row and to_row inclusive
Returns the (total duration of all tracks in rows between
from_row and to_row inclusive, total unplayed time in those rows)
"""
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 unplayed_time
return (total_time, unplayed_time)
def _update_row_track_info(
self, session: scoped_session, row: int, track: Tracks
@ -2461,21 +2439,6 @@ 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)
@ -2494,19 +2457,12 @@ class PlaylistTab(QTableWidget):
try:
from_plr = section_start_rows.pop()
to_plr = plr
unplayed_time = self._unplayed_track_time_between_rows(
total_time, unplayed_time = self._track_time_between_rows(
session, from_plr, to_plr
)
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)
time_str = self._get_section_timing_string(
total_time, unplayed_time
)
self._set_row_header_text(
session, from_plr.plr_rownum, from_plr.note + time_str
)
@ -2535,19 +2491,10 @@ class PlaylistTab(QTableWidget):
return
from_plr = subtotal_from
to_plr = plr
unplayed_time = self._unplayed_track_time_between_rows(
total_time, unplayed_time = self._track_time_between_rows(
session, subtotal_from, to_plr
)
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)
time_str = self._get_section_timing_string(total_time, unplayed_time)
if to_plr.note.strip() == "=":
leader_text = "Subtotal: "
@ -2563,7 +2510,7 @@ class PlaylistTab(QTableWidget):
if possible_plr:
to_plr = possible_plr
for from_plr in section_start_rows:
unplayed_time = self._unplayed_track_time_between_rows(
total_time, unplayed_time = self._track_time_between_rows(
session, from_plr, to_plr
)
time_str = self._get_section_timing_string(

View File

@ -255,7 +255,7 @@ def process_track(src, dst, title, artist, bitrate):
shutil.move(src, new_path)
# Update track metadata
set_track_metadata(track)
set_track_metadata(session, track)
main()