WIP: remove sessions from file_importer
This commit is contained in:
parent
4eaab98745
commit
e39518e5ee
@ -629,42 +629,19 @@ class DoTrackImport(QThread):
|
||||
# Move new file to destination
|
||||
shutil.move(self.import_file_path, self.destination_track_path)
|
||||
|
||||
with db.Session() as session:
|
||||
if self.track_id == 0:
|
||||
# Import new track
|
||||
try:
|
||||
track = Tracks(
|
||||
session,
|
||||
path=self.destination_track_path,
|
||||
**self.tags._asdict(),
|
||||
**self.audio_metadata._asdict(),
|
||||
)
|
||||
except Exception as e:
|
||||
self.signals.show_warning_signal.emit(
|
||||
"Error importing track", str(e)
|
||||
)
|
||||
return
|
||||
else:
|
||||
track = session.get(Tracks, self.track_id)
|
||||
if track:
|
||||
for key, value in self.tags._asdict().items():
|
||||
if hasattr(track, key):
|
||||
setattr(track, key, value)
|
||||
for key, value in self.audio_metadata._asdict().items():
|
||||
if hasattr(track, key):
|
||||
setattr(track, key, value)
|
||||
track.path = self.destination_track_path
|
||||
else:
|
||||
log.error(f"Unable to retrieve {self.track_id=}")
|
||||
return
|
||||
session.commit()
|
||||
# Normalise
|
||||
normalise_track(self.destination_track_path)
|
||||
|
||||
normalise_track(self.destination_track_path)
|
||||
# Update databse
|
||||
if self.track_id == 0:
|
||||
track_dto = repository.create_track(self.destination_track_path)
|
||||
else:
|
||||
track_dto = repository.update_track(self.destination_track_path, self.track_id)
|
||||
|
||||
self.signals.status_message_signal.emit(
|
||||
f"{os.path.basename(self.import_file_path)} imported", 10000
|
||||
)
|
||||
self.import_finished.emit(self.import_file_path, track.id)
|
||||
self.signals.status_message_signal.emit(
|
||||
f"{os.path.basename(self.import_file_path)} imported", 10000
|
||||
)
|
||||
self.import_finished.emit(self.import_file_path, track_dto.track_id)
|
||||
|
||||
|
||||
class PickMatch(QDialog):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user