Compare commits

...

3 Commits

Author SHA1 Message Date
Keith Edmunds
21fe8fff83 Update track.lastplayed field
Fixes #78
2021-09-24 08:05:01 +01:00
Keith Edmunds
780b053219 Check for duplicate title on import
Fixes #80
2021-09-23 18:07:28 +01:00
Keith Edmunds
2fbf829eed Show track info when importing track
Fixes #79
2021-09-23 17:50:39 +01:00
3 changed files with 25 additions and 8 deletions

View File

@ -106,7 +106,7 @@ class Playdates(Base):
pd.lastplayed = datetime.now()
pd.track_id = track.id
session.add(pd)
track.update_lastplayed()
track.update_lastplayed(session, track.id)
session.commit()
@staticmethod
@ -596,8 +596,11 @@ class Tracks(Base):
return session.query(Tracks).filter(
Tracks.id == id).one()
def update_lastplayed(self):
self.lastplayed = datetime.now()
@staticmethod
def update_lastplayed(session, track_id):
track = session.query(Tracks).filter(Tracks.id == track_id).one()
track.lastplayed = datetime.now()
session.commit()
@staticmethod
def update_artist(session, track_id, artist):

View File

@ -511,7 +511,6 @@ class Window(QMainWindow, Ui_MainWindow):
QColor(Config.COLOUR_NEXT_TAB))
# Tell database to record it as played
self.current_track.update_lastplayed()
Playdates.add_playdate(session, self.current_track)
self.disable_play_next_controls()

View File

@ -66,12 +66,27 @@ def create_track_from_file(session, path, verbose=False):
str = f"Importing {path}"
INFO(str)
INFO("-" * len(str))
track = Tracks.get_or_create(session, path)
if verbose:
INFO("Get track info...")
t = get_music_info(path)
track.title = t['title']
track.artist = t['artist']
title = t['title']
artist = t['artist']
if verbose:
INFO(f" Title: \"{title}\"")
INFO(f" Artist: \"{artist}\"")
# Check for duplicate
tracks = Tracks.search_titles(session, title)
if tracks:
print("Found the following possible matches:")
for track in tracks:
print(f'"{track.title}" by {track.artist}')
response = input("Continue [c] or abort [a]?")
if not response:
return
if response[0].lower() not in ['c', 'y']:
return
track = Tracks.get_or_create(session, path)
track.title = title
track.artist = artist
track.duration = int(round(
t['duration'], Config.MILLISECOND_SIGFIGS) * 1000)