More 'detached session' fixes
This commit is contained in:
parent
4bae0b8548
commit
0cf649bb01
19
app/model.py
19
app/model.py
@ -189,7 +189,7 @@ class Playlists(Base):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_closed_playlists(session):
|
def get_all_closed_playlists(session):
|
||||||
"Returns a list of all playlists not currently open"
|
"Returns a list of all playlists not currently open"
|
||||||
|
|
||||||
return (
|
return (
|
||||||
session.query(Playlists)
|
session.query(Playlists)
|
||||||
@ -221,6 +221,15 @@ class Playlists(Base):
|
|||||||
def get_notes(self):
|
def get_notes(self):
|
||||||
return [a.note for a in self.notes]
|
return [a.note for a in self.notes]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_playlist(session, playlist_id):
|
||||||
|
return (
|
||||||
|
session.query(Playlists)
|
||||||
|
.filter(
|
||||||
|
Playlists.id == playlist_id # noqa E712
|
||||||
|
)
|
||||||
|
).one()
|
||||||
|
|
||||||
def get_tracks(self):
|
def get_tracks(self):
|
||||||
return [a.tracks for a in self.tracks]
|
return [a.tracks for a in self.tracks]
|
||||||
|
|
||||||
@ -244,6 +253,7 @@ class Playlists(Base):
|
|||||||
|
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
class PlaylistTracks(Base):
|
class PlaylistTracks(Base):
|
||||||
__tablename__ = 'playlisttracks'
|
__tablename__ = 'playlisttracks'
|
||||||
|
|
||||||
@ -424,13 +434,6 @@ class Tracks(Base):
|
|||||||
|
|
||||||
return [a[0] for a in session.query(Tracks.path).all()]
|
return [a[0] for a in session.query(Tracks.path).all()]
|
||||||
|
|
||||||
# Not used as of 1 June 2021
|
|
||||||
# @classmethod
|
|
||||||
# def get_all_tracks(cls):
|
|
||||||
# "Return a list of all tracks"
|
|
||||||
|
|
||||||
# return session.query(cls).all()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_path(session, id):
|
def get_path(session, id):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -217,7 +217,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
# Get output filename
|
# Get output filename
|
||||||
pathspec = QFileDialog.getSaveFileName(
|
pathspec = QFileDialog.getSaveFileName(
|
||||||
self, 'Save Playlist',
|
self, 'Save Playlist',
|
||||||
directory=f"{self.visible_playlist().db.name}.m3u",
|
directory=f"{self.visible_playlist().name}.m3u",
|
||||||
filter="M3U files (*.m3u);;All files (*.*)"
|
filter="M3U files (*.m3u);;All files (*.*)"
|
||||||
)
|
)
|
||||||
if not pathspec:
|
if not pathspec:
|
||||||
@ -227,19 +227,23 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
if not path.endswith(".m3u"):
|
if not path.endswith(".m3u"):
|
||||||
path += ".m3u"
|
path += ".m3u"
|
||||||
with open(path, "w") as f:
|
|
||||||
# Required directive on first line
|
# Get playlist db object
|
||||||
f.write("#EXTM3U\n")
|
with Session() as session:
|
||||||
for track in self.visible_playlist().db.get_tracks():
|
p = Playlists.get_playlist(session, self.visible_playlist().id)
|
||||||
f.write(
|
with open(path, "w") as f:
|
||||||
"#EXTINF:"
|
# Required directive on first line
|
||||||
f"{int(track.duration / 1000)},"
|
f.write("#EXTM3U\n")
|
||||||
f"{track.title} - "
|
for track in p.get_tracks():
|
||||||
f"{track.artist}"
|
f.write(
|
||||||
"\n"
|
"#EXTINF:"
|
||||||
f"{track.path}"
|
f"{int(track.duration / 1000)},"
|
||||||
"\n"
|
f"{track.title} - "
|
||||||
)
|
f"{track.artist}"
|
||||||
|
"\n"
|
||||||
|
f"{track.path}"
|
||||||
|
"\n"
|
||||||
|
)
|
||||||
|
|
||||||
def fade(self):
|
def fade(self):
|
||||||
"Fade currently playing track"
|
"Fade currently playing track"
|
||||||
|
|||||||
@ -279,13 +279,13 @@ class Playlist(QTableWidget):
|
|||||||
"Clear current track"
|
"Clear current track"
|
||||||
|
|
||||||
self._meta_clear_current()
|
self._meta_clear_current()
|
||||||
self._repaint(save_playlist=False)
|
self._repaint()
|
||||||
|
|
||||||
def clear_next(self):
|
def clear_next(self):
|
||||||
"Clear next track"
|
"Clear next track"
|
||||||
|
|
||||||
self._meta_clear_next()
|
self._meta_clear_next()
|
||||||
self._repaint(save_playlist=False)
|
self._repaint()
|
||||||
|
|
||||||
def get_next_track_id(self):
|
def get_next_track_id(self):
|
||||||
"Return next track id"
|
"Return next track id"
|
||||||
@ -325,7 +325,7 @@ class Playlist(QTableWidget):
|
|||||||
for row in sorted(rows, reverse=True):
|
for row in sorted(rows, reverse=True):
|
||||||
self.removeRow(row)
|
self.removeRow(row)
|
||||||
|
|
||||||
self._repaint(save_playlist=False)
|
self._repaint()
|
||||||
|
|
||||||
def get_selected_title(self):
|
def get_selected_title(self):
|
||||||
"Return title of selected row or None"
|
"Return title of selected row or None"
|
||||||
@ -352,13 +352,13 @@ class Playlist(QTableWidget):
|
|||||||
scroll_to = self.item(current_row, self.COL_INDEX)
|
scroll_to = self.item(current_row, self.COL_INDEX)
|
||||||
self.scrollToItem(scroll_to, QAbstractItemView.PositionAtCenter)
|
self.scrollToItem(scroll_to, QAbstractItemView.PositionAtCenter)
|
||||||
next_track_id = self._mark_next_track()
|
next_track_id = self._mark_next_track()
|
||||||
self._repaint(save_playlist=False)
|
self._repaint()
|
||||||
return next_track_id
|
return next_track_id
|
||||||
|
|
||||||
def play_stopped(self):
|
def play_stopped(self):
|
||||||
self._meta_clear_current()
|
self._meta_clear_current()
|
||||||
self.current_track_start_time = None
|
self.current_track_start_time = None
|
||||||
self._repaint(save_playlist=False)
|
self._repaint()
|
||||||
|
|
||||||
def populate(self, session):
|
def populate(self, session):
|
||||||
# add tracks and notes in row order.
|
# add tracks and notes in row order.
|
||||||
@ -368,6 +368,7 @@ class Playlist(QTableWidget):
|
|||||||
|
|
||||||
# First, save our id for the future
|
# First, save our id for the future
|
||||||
self.id = self.db.id
|
self.id = self.db.id
|
||||||
|
self.name = self.db.name
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
|
|
||||||
@ -392,7 +393,7 @@ class Playlist(QTableWidget):
|
|||||||
|
|
||||||
def repaint(self):
|
def repaint(self):
|
||||||
# Called when we change tabs
|
# Called when we change tabs
|
||||||
self._repaint(save_playlist=False)
|
self._repaint()
|
||||||
|
|
||||||
def select_next_track(self):
|
def select_next_track(self):
|
||||||
"""
|
"""
|
||||||
@ -520,7 +521,7 @@ class Playlist(QTableWidget):
|
|||||||
if row in self._meta_get_notes():
|
if row in self._meta_get_notes():
|
||||||
Notes.delete_note(session, id)
|
Notes.delete_note(session, id)
|
||||||
else:
|
else:
|
||||||
PlaylistTracks.remove_track(session, self.db.id, row)
|
PlaylistTracks.remove_track(session, self.id, row)
|
||||||
self.removeRow(row)
|
self.removeRow(row)
|
||||||
|
|
||||||
self._save_playlist(session)
|
self._save_playlist(session)
|
||||||
@ -707,7 +708,7 @@ class Playlist(QTableWidget):
|
|||||||
else:
|
else:
|
||||||
title = ""
|
title = ""
|
||||||
DEBUG(
|
DEBUG(
|
||||||
f"playlist[{self.db.id}:{self.db.name}]._meta_set(row={row}, "
|
f"playlist[{self.id}:{self.name}]._meta_set(row={row}, "
|
||||||
f"title={title}, metadata={metadata})"
|
f"title={title}, metadata={metadata})"
|
||||||
)
|
)
|
||||||
if row is None:
|
if row is None:
|
||||||
@ -729,14 +730,14 @@ class Playlist(QTableWidget):
|
|||||||
track_id = self._get_row_id(row)
|
track_id = self._get_row_id(row)
|
||||||
if track_id:
|
if track_id:
|
||||||
self._meta_set_next(self.currentRow())
|
self._meta_set_next(self.currentRow())
|
||||||
self._repaint(save_playlist=False)
|
self._repaint()
|
||||||
self.master_process.set_next_track(track_id)
|
self.master_process.set_next_track(track_id)
|
||||||
|
|
||||||
def _repaint(self, clear_selection=True):
|
def _repaint(self, clear_selection=True):
|
||||||
"Set row colours, fonts, etc"
|
"Set row colours, fonts, etc"
|
||||||
|
|
||||||
DEBUG(
|
DEBUG(
|
||||||
f"playlist[{self.db.id}:{self.db.name}]."
|
f"playlist[{self.id}:{self.name}]."
|
||||||
f"_repaint(clear_selection={clear_selection}"
|
f"_repaint(clear_selection={clear_selection}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -883,13 +884,13 @@ class Playlist(QTableWidget):
|
|||||||
|
|
||||||
# Tracks
|
# Tracks
|
||||||
# Remove all tracks for us in datbase
|
# Remove all tracks for us in datbase
|
||||||
PlaylistTracks.remove_all_tracks(session, self.db.id)
|
PlaylistTracks.remove_all_tracks(session, self.id)
|
||||||
# Iterate on-screen playlist and add tracks back in
|
# Iterate on-screen playlist and add tracks back in
|
||||||
for row in range(self.rowCount()):
|
for row in range(self.rowCount()):
|
||||||
if row in notes_rows:
|
if row in notes_rows:
|
||||||
continue
|
continue
|
||||||
PlaylistTracks.add_track(
|
PlaylistTracks.add_track(
|
||||||
session, self.db.id, self._get_row_id(row), row)
|
session, self.id, self._get_row_id(row), row)
|
||||||
|
|
||||||
def _set_column_widths(self):
|
def _set_column_widths(self):
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user