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:
parent
3fb6f3a2ba
commit
0e55bb25e9
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue