WIP: Make ds.track_update more generic
This commit is contained in:
parent
83780bfb68
commit
ffb1b238f4
16
app/ds.py
16
app/ds.py
@ -451,7 +451,7 @@ def track_set_intro(track_id: int, intro: int) -> None:
|
|||||||
|
|
||||||
# @log_call
|
# @log_call
|
||||||
def track_update(
|
def track_update(
|
||||||
path: str, track_id: int, metadata: dict[str, str | int | float]
|
track_id: int, metadata: dict[str, str | int | float]
|
||||||
) -> TrackDTO:
|
) -> TrackDTO:
|
||||||
"""
|
"""
|
||||||
Update an existing track db entry return the DTO
|
Update an existing track db entry return the DTO
|
||||||
@ -462,14 +462,12 @@ def track_update(
|
|||||||
|
|
||||||
if not track:
|
if not track:
|
||||||
raise ApplicationError(f"Can't retrieve Track ({track_id=})")
|
raise ApplicationError(f"Can't retrieve Track ({track_id=})")
|
||||||
track.path = str(metadata["path"])
|
|
||||||
track.title = str(metadata["title"])
|
for key, value in metadata.items():
|
||||||
track.artist = str(metadata["artist"])
|
if hasattr(track, key):
|
||||||
track.duration = int(metadata["duration"])
|
setattr(track, key, value)
|
||||||
track.start_gap = int(metadata["start_gap"])
|
else:
|
||||||
track.fade_at = int(metadata["fade_at"])
|
raise ApplicationError(f"Tried to set attribute {key} on {track}")
|
||||||
track.silence_at = int(metadata["silence_at"])
|
|
||||||
track.bitrate = int(metadata["bitrate"])
|
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|||||||
@ -640,9 +640,7 @@ class DoTrackImport(QThread):
|
|||||||
if self.track_id == 0:
|
if self.track_id == 0:
|
||||||
track_dto = ds.track_create(metadata)
|
track_dto = ds.track_create(metadata)
|
||||||
else:
|
else:
|
||||||
track_dto = ds.track_update(
|
track_dto = ds.track_update(self.track_id, metadata)
|
||||||
self.destination_track_path, self.track_id, metadata
|
|
||||||
)
|
|
||||||
|
|
||||||
self.signals.status_message_signal.emit(
|
self.signals.status_message_signal.emit(
|
||||||
f"{os.path.basename(self.import_file_path)} imported", 10000
|
f"{os.path.basename(self.import_file_path)} imported", 10000
|
||||||
|
|||||||
@ -1038,7 +1038,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
|
|
||||||
track = self.playlist_rows[row_number]
|
track = self.playlist_rows[row_number]
|
||||||
metadata = get_all_track_metadata(track.path)
|
metadata = get_all_track_metadata(track.path)
|
||||||
_ = ds.track_update(track.path, track.track_id, metadata)
|
_ = ds.track_update(track.track_id, metadata)
|
||||||
|
|
||||||
roles = [
|
roles = [
|
||||||
Qt.ItemDataRole.BackgroundRole,
|
Qt.ItemDataRole.BackgroundRole,
|
||||||
|
|||||||
@ -91,7 +91,6 @@ def update_bitrates() -> None:
|
|||||||
for track in ds.tracks_all():
|
for track in ds.tracks_all():
|
||||||
try:
|
try:
|
||||||
t = get_tags(track.path)
|
t = get_tags(track.path)
|
||||||
# TODO this won't persist as we're updating DTO
|
ds.track_update(t)
|
||||||
track.bitrate = t.bitrate
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user