db: Give Tracks a way to directly set playcount and lastplayed

This will be needed when importing tracks from the tagdb into the sqlite
db

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-08-25 10:31:33 -04:00
parent 3fb6f3a2ba
commit 0e55bb25e9
2 changed files with 15 additions and 1 deletions

View File

@ -77,6 +77,13 @@ class TestTrackTable(unittest.TestCase):
def test_track_played(self):
track = db.make_fake_track(1, 1.234, "Test Title", "/a/b/c/d.efg")
today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)
track.played()
self.assertEqual(track.playcount, 1)
self.assertEqual(track.lastplayed, datetime.date.today())
self.assertEqual(track.lastplayed, today)
track.last_played(4, yesterday)
self.assertEqual(track.playcount, 4)
self.assertEqual(track.lastplayed, yesterday)

View File

@ -84,6 +84,13 @@ class Track(objects.Row):
commit()
def last_played(self, playcount, lastplayed):
execute("UPDATE tracks "
"SET playcount=?, lastplayed=? "
"WHERE trackid=?", [ playcount, lastplayed, self.rowid ])
commit()
class TrackTable(objects.Table):
def __init__(self):
objects.Table.__init__(self, "tracks", Track)