Fix background importing and duplicate checking

This commit is contained in:
Keith Edmunds 2022-06-04 22:32:22 +01:00
parent fc9a10ad52
commit a8395d8c97
2 changed files with 18 additions and 12 deletions

View File

@ -63,12 +63,13 @@ def get_tags(path: str) -> Dict[str, Union[str, int]]:
tag: TinyTag = TinyTag.get(path)
return dict(
d = dict(
title=tag.title,
artist=tag.artist,
duration=int(round(tag.duration, Config.MILLISECOND_SIGFIGS) * 1000),
path=path
)
return d
def get_relative_date(past_date: datetime, reference_date: datetime = None) \

View File

@ -437,9 +437,10 @@ class Window(QMainWindow, Ui_MainWindow):
possible_matches = Tracks.search_titles(session, title)
if possible_matches:
txt += 'Similar to new track '
txt += f'"{title}" by "{artist}":\n'
txt += f'"{title}" by "{artist} ({fname})":\n\n'
for track in possible_matches:
txt += f' "{track.title}" by {track.artist}\n'
txt += f' "{track.title}" by {track.artist}'
txt += f' ({track.path})\n'
txt += "\n"
# Check whether to proceed if there were potential matches
if txt:
@ -455,18 +456,22 @@ class Window(QMainWindow, Ui_MainWindow):
# Import in separate thread
thread = threading.Thread(target=self._import_tracks,
args=(session, new_tracks))
args=(new_tracks,))
thread.start()
def _import_tracks(self, session: Session, tracks: list):
"""Import passed files"""
def _import_tracks(self, tracks: list):
"""
Import passed files. Don't use parent session as that may be invalid
by the time we need it.
"""
for (fname, tags) in tracks:
track = create_track_from_file(session, fname, tags=tags)
# Add to playlist on screen
# If we don't specify "repaint=False", playlist will
# also be saved to database
self.visible_playlist_tab().insert_track(session, track)
with Session() as session:
for (fname, tags) in tracks:
track = create_track_from_file(session, fname, tags=tags)
# Add to playlist on screen
# If we don't specify "repaint=False", playlist will
# also be saved to database
self.visible_playlist_tab().insert_track(session, track)
def load_last_playlists(self):
"""Load the playlists that we loaded at end of last session"""