Compare commits
4 Commits
da751ee530
...
405efee732
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
405efee732 | ||
|
|
2db407edc5 | ||
|
|
ab8da0a312 | ||
|
|
48d26d80df |
@ -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, track, target_row)
|
self.playlist.insert_track(session=session, track=track, target_row=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.
|
||||||
|
|||||||
109
app/playlists.py
109
app/playlists.py
@ -249,17 +249,29 @@ 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:
|
|
||||||
self.setItem(
|
# Fixup header text
|
||||||
tgtRow,
|
if is_header_row:
|
||||||
HEADER_NOTES_COLUMN,
|
target_item = self.item(tgtRow, HEADER_NOTES_COLUMN)
|
||||||
self.takeItem(srcRow, HEADER_NOTES_COLUMN),
|
if target_item:
|
||||||
)
|
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)
|
||||||
@ -640,8 +652,8 @@ class PlaylistTab(QTableWidget):
|
|||||||
self,
|
self,
|
||||||
session: scoped_session,
|
session: scoped_session,
|
||||||
track: Tracks,
|
track: Tracks,
|
||||||
note: str = "",
|
note: Optional[str] = "",
|
||||||
repaint: bool = True,
|
repaint: Optional[bool] = True,
|
||||||
target_row: Optional[int] = None,
|
target_row: Optional[int] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
@ -1449,20 +1461,32 @@ class PlaylistTab(QTableWidget):
|
|||||||
return userdata_item.data(role)
|
return userdata_item.data(role)
|
||||||
|
|
||||||
def _get_section_timing_string(
|
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:
|
) -> 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:
|
else:
|
||||||
unplayed_duration = "[No unplayed tracks]"
|
end_str = ""
|
||||||
|
|
||||||
caveat = ""
|
caveat = ""
|
||||||
if no_end:
|
if no_end:
|
||||||
caveat = " (to end of playlist)"
|
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]:
|
def _get_selected_row(self) -> Optional[int]:
|
||||||
"""
|
"""
|
||||||
@ -2386,26 +2410,24 @@ class PlaylistTab(QTableWidget):
|
|||||||
self.save_playlist(session)
|
self.save_playlist(session)
|
||||||
self._update_start_end_times(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
|
self, session: scoped_session, from_plr: PlaylistRows, to_plr: PlaylistRows
|
||||||
) -> Tuple[int, int]:
|
) -> int:
|
||||||
"""
|
"""
|
||||||
Returns the (total duration of all tracks in rows between
|
Returns the total unplayed duration of all tracks in rows between
|
||||||
from_row and to_row inclusive, total unplayed time in those rows)
|
from_row and to_row inclusive
|
||||||
"""
|
"""
|
||||||
|
|
||||||
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 (total_time, unplayed_time)
|
return 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
|
||||||
@ -2439,6 +2461,21 @@ 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)
|
||||||
@ -2457,12 +2494,19 @@ class PlaylistTab(QTableWidget):
|
|||||||
try:
|
try:
|
||||||
from_plr = section_start_rows.pop()
|
from_plr = section_start_rows.pop()
|
||||||
to_plr = plr
|
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
|
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(
|
time_str = self._get_section_timing_string(
|
||||||
total_time, unplayed_time
|
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
|
||||||
)
|
)
|
||||||
@ -2491,10 +2535,19 @@ class PlaylistTab(QTableWidget):
|
|||||||
return
|
return
|
||||||
from_plr = subtotal_from
|
from_plr = subtotal_from
|
||||||
to_plr = plr
|
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
|
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() == "=":
|
if to_plr.note.strip() == "=":
|
||||||
leader_text = "Subtotal: "
|
leader_text = "Subtotal: "
|
||||||
@ -2510,7 +2563,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:
|
||||||
total_time, unplayed_time = self._track_time_between_rows(
|
unplayed_time = self._unplayed_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(session, track)
|
set_track_metadata(track)
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user