Compare commits
No commits in common. "405efee7324709a6ee3314356b10351c7e8efaaf" and "da751ee530f0862eb41ed54c8e6c801f06c0ae78" have entirely different histories.
405efee732
...
da751ee530
@ -223,7 +223,7 @@ class ImportTrack(QObject):
|
|||||||
print(e)
|
print(e)
|
||||||
return
|
return
|
||||||
helpers.normalise_track(track.path)
|
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
|
# Insert next row under this one
|
||||||
target_row += 1
|
target_row += 1
|
||||||
# We're importing potentially multiple tracks in a loop.
|
# We're importing potentially multiple tracks in a loop.
|
||||||
|
|||||||
119
app/playlists.py
119
app/playlists.py
@ -249,30 +249,18 @@ class PlaylistTab(QTableWidget):
|
|||||||
else:
|
else:
|
||||||
rowMapping[row + len(rows)] = targetRow + idx
|
rowMapping[row + len(rows)] = targetRow + idx
|
||||||
colCount = self.columnCount()
|
colCount = self.columnCount()
|
||||||
with Session() as session:
|
for srcRow, tgtRow in sorted(rowMapping.items()):
|
||||||
for srcRow, tgtRow in sorted(rowMapping.items()):
|
if self._get_row_track_id(srcRow):
|
||||||
# Messy: will be fixed with model/view implementation.
|
# This is a track row
|
||||||
# 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 col in range(0, colCount):
|
for col in range(0, colCount):
|
||||||
self.setItem(tgtRow, col, self.takeItem(srcRow, col))
|
self.setItem(tgtRow, col, self.takeItem(srcRow, col))
|
||||||
|
else:
|
||||||
# Fixup header text
|
self.setItem(
|
||||||
if is_header_row:
|
tgtRow,
|
||||||
target_item = self.item(tgtRow, HEADER_NOTES_COLUMN)
|
HEADER_NOTES_COLUMN,
|
||||||
if target_item:
|
self.takeItem(srcRow, HEADER_NOTES_COLUMN),
|
||||||
target_item.setText(note_text)
|
)
|
||||||
self.setSpan(tgtRow, HEADER_NOTES_COLUMN, 1, len(columns) - 1)
|
self.setSpan(tgtRow, HEADER_NOTES_COLUMN, 1, len(columns) - 1)
|
||||||
for row in reversed(sorted(rowMapping.keys())):
|
for row in reversed(sorted(rowMapping.keys())):
|
||||||
self.removeRow(row)
|
self.removeRow(row)
|
||||||
self.resizeRowsToContents()
|
self.resizeRowsToContents()
|
||||||
@ -652,8 +640,8 @@ class PlaylistTab(QTableWidget):
|
|||||||
self,
|
self,
|
||||||
session: scoped_session,
|
session: scoped_session,
|
||||||
track: Tracks,
|
track: Tracks,
|
||||||
note: Optional[str] = "",
|
note: str = "",
|
||||||
repaint: Optional[bool] = True,
|
repaint: bool = True,
|
||||||
target_row: Optional[int] = None,
|
target_row: Optional[int] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
@ -1461,32 +1449,20 @@ class PlaylistTab(QTableWidget):
|
|||||||
return userdata_item.data(role)
|
return userdata_item.data(role)
|
||||||
|
|
||||||
def _get_section_timing_string(
|
def _get_section_timing_string(
|
||||||
self,
|
self, total_time: int, unplayed_time: int, no_end: bool = False
|
||||||
unplayed_time: int,
|
|
||||||
end_time: Optional[datetime] = None,
|
|
||||||
no_end: bool = False,
|
|
||||||
) -> str:
|
) -> 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.
|
|
||||||
"""
|
|
||||||
|
|
||||||
unplayed_duration = ms_to_mmss(unplayed_time)
|
total_duration = ms_to_mmss(total_time)
|
||||||
if end_time:
|
if unplayed_time:
|
||||||
section_end_time = end_time + timedelta(milliseconds=unplayed_time)
|
unplayed_duration = ms_to_mmss(unplayed_time)
|
||||||
end_str = (
|
|
||||||
"[End time for all unplayed tracks in section: "
|
|
||||||
+ section_end_time.strftime(Config.TRACK_TIME_FORMAT)
|
|
||||||
+ "]"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
end_str = ""
|
unplayed_duration = "[No unplayed tracks]"
|
||||||
|
|
||||||
caveat = ""
|
caveat = ""
|
||||||
if no_end:
|
if no_end:
|
||||||
caveat = " (to end of playlist)"
|
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]:
|
def _get_selected_row(self) -> Optional[int]:
|
||||||
"""
|
"""
|
||||||
@ -2410,24 +2386,26 @@ class PlaylistTab(QTableWidget):
|
|||||||
self.save_playlist(session)
|
self.save_playlist(session)
|
||||||
self._update_start_end_times(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
|
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
|
Returns the (total duration of all tracks in rows between
|
||||||
from_row and to_row inclusive
|
from_row and to_row inclusive, total unplayed time in those rows)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
plr_tracks = PlaylistRows.get_rows_with_tracks(
|
plr_tracks = PlaylistRows.get_rows_with_tracks(
|
||||||
session, self.playlist_id, from_plr.plr_rownum, to_plr.plr_rownum
|
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 = 0
|
||||||
unplayed_time = sum(
|
unplayed_time = sum(
|
||||||
[a.track.duration for a in plr_tracks if a.track.duration and not a.played]
|
[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(
|
def _update_row_track_info(
|
||||||
self, session: scoped_session, row: int, track: Tracks
|
self, session: scoped_session, row: int, track: Tracks
|
||||||
@ -2461,21 +2439,6 @@ class PlaylistTab(QTableWidget):
|
|||||||
|
|
||||||
section_start_rows: List[PlaylistRows] = []
|
section_start_rows: List[PlaylistRows] = []
|
||||||
subtotal_from: Optional[PlaylistRows] = None
|
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 = [
|
header_rows = [
|
||||||
self._get_row_plr_id(row_number)
|
self._get_row_plr_id(row_number)
|
||||||
@ -2494,19 +2457,12 @@ class PlaylistTab(QTableWidget):
|
|||||||
try:
|
try:
|
||||||
from_plr = section_start_rows.pop()
|
from_plr = section_start_rows.pop()
|
||||||
to_plr = plr
|
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
|
session, from_plr, to_plr
|
||||||
)
|
)
|
||||||
if (
|
time_str = self._get_section_timing_string(
|
||||||
active_row
|
total_time, unplayed_time
|
||||||
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(
|
self._set_row_header_text(
|
||||||
session, from_plr.plr_rownum, from_plr.note + time_str
|
session, from_plr.plr_rownum, from_plr.note + time_str
|
||||||
)
|
)
|
||||||
@ -2535,19 +2491,10 @@ class PlaylistTab(QTableWidget):
|
|||||||
return
|
return
|
||||||
from_plr = subtotal_from
|
from_plr = subtotal_from
|
||||||
to_plr = plr
|
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
|
session, subtotal_from, to_plr
|
||||||
)
|
)
|
||||||
if (
|
time_str = self._get_section_timing_string(total_time, unplayed_time)
|
||||||
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() == "=":
|
if to_plr.note.strip() == "=":
|
||||||
leader_text = "Subtotal: "
|
leader_text = "Subtotal: "
|
||||||
@ -2563,7 +2510,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
if possible_plr:
|
if possible_plr:
|
||||||
to_plr = possible_plr
|
to_plr = possible_plr
|
||||||
for from_plr in section_start_rows:
|
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
|
session, from_plr, to_plr
|
||||||
)
|
)
|
||||||
time_str = self._get_section_timing_string(
|
time_str = self._get_section_timing_string(
|
||||||
|
|||||||
@ -255,7 +255,7 @@ def process_track(src, dst, title, artist, bitrate):
|
|||||||
shutil.move(src, new_path)
|
shutil.move(src, new_path)
|
||||||
|
|
||||||
# Update track metadata
|
# Update track metadata
|
||||||
set_track_metadata(track)
|
set_track_metadata(session, track)
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user