db: Give Albums a find_disc() function

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-10-10 11:43:02 -04:00
parent 44a002ecac
commit 67238ed385
7 changed files with 16 additions and 10 deletions

View File

@ -19,7 +19,7 @@ def make_fake_track(trackno, length, title, path, lib="/a/b/c", art="Test Artist
lib = library.Table.find(pathlib.Path(lib))
art = artist.Table.find(art, art)
alb = art.find_album(alb)
disk = disc.Table.find(alb, disk, subtitle)
disk = alb.find_disc(disk, subtitle)
dec = decade.Table.find((yeer // 10) * 10)
yeer = dec.find_year(yeer)
return track.Table.insert(lib, art, alb, disk, dec, yeer, trackno,

View File

@ -22,7 +22,12 @@ class Album(playlist.ParentPlaylist):
@GObject.Property
def name(self): return self._name
def find_disc(self, number, subtitle):
return self.find_child(number, subtitle)
def get_child_table(self): return disc.Table
def lookup_child(self, number, subtitle):
return disc.Table.lookup(self, number)
class AlbumTable(playlist.ChildModel):

View File

@ -52,10 +52,5 @@ class DiscTable(playlist.ChildModel):
return sql.execute("SELECT * FROM discs WHERE (albumid=? AND number=?)",
[ album.rowid, number ])
def find(self, album, number, subtitle):
if (res := self.lookup(album, number)):
return res
return self.insert(album, number, subtitle)
Table = DiscTable()

View File

@ -15,6 +15,12 @@ class TestAlbum(unittest.TestCase):
self.assertEqual(album.get_property("name"), "Test Album")
self.assertEqual(album.get_child_table(), db.disc.Table)
def test_find_disc(self):
artist = db.artist.Table.find("Test Artist", "Test Sort")
album = artist.find_album("Test Album")
disc = album.find_disc(1, None)
self.assertIsInstance(disc, db.disc.Disc)
class TestAlbumTable(unittest.TestCase):
def setUp(self):

View File

@ -10,7 +10,7 @@ class TestDisc(unittest.TestCase):
def make_disc(self, artist, album, discno, subtitle):
artist = db.artist.Table.find(artist, artist)
return db.disc.Table.find(artist.find_album(album), discno, subtitle)
return artist.find_album(album).find_disc(discno, subtitle)
def test_init(self):
disc = self.make_disc("Test Artist", "Test Album", 1, "")
@ -65,6 +65,6 @@ class TestDiscTable(unittest.TestCase):
def test_lookup(self):
artist = db.artist.Table.insert("Test Artist", "Test Sort")
album = artist.find_album("Test Album")
disc = db.disc.Table.insert(album, 1, None)
disc = album.find_disc(1, None)
self.assertEqual(db.disc.Table.lookup(album, 1), disc)
self.assertIsNone(db.disc.Table.lookup(album, "none"))

View File

@ -20,7 +20,7 @@ class TestTrackTable(unittest.TestCase):
library = db.library.Table.find(pathlib.Path("/a/b/c"))
artist = db.artist.Table.find("Test Artist", "test artist")
album = artist.find_album("Test Album")
disc = db.disc.Table.find(album, 1, None)
disc = album.find_disc(1, None)
decade = db.decade.Table.find(2020)
year = decade.find_year(2021)
track = db.track.Table.insert(library, artist, album, disc, decade, year,

View File

@ -24,7 +24,7 @@ class FileTask(Task):
with metadata.Metadata(self.filepath) as meta:
artist = db.artist.Table.find(meta.artist(), meta.artistsort())
album = artist.find_album(meta.album())
disc = db.disc.Table.find(album, meta.discnumber(), meta.discsubtitle())
disc = album.find_disc(meta.discnumber(), meta.discsubtitle())
decade = db.decade.Table.find(meta.decade())
year = decade.find_year(meta.year())
track = db.track.Table.insert(self.library, artist, album, disc,