mirror of
https://github.com/beetbox/beets.git
synced 2025-12-31 04:52:49 +01:00
albuminfo() can now take an album id as well as an item
This commit is contained in:
parent
a49ebc853a
commit
e7e7ee64b0
2 changed files with 20 additions and 9 deletions
|
|
@ -945,17 +945,23 @@ class Library(BaseLibrary):
|
|||
# Album information.
|
||||
|
||||
def albuminfo(self, item):
|
||||
# Lazily create a row in the albums table if one doesn't
|
||||
# exist.
|
||||
sql = 'SELECT id FROM albums WHERE artist=? AND album=?'
|
||||
c = self.conn.execute(sql, (item.artist, item.album))
|
||||
row = c.fetchone()
|
||||
if row:
|
||||
album_id = row[0]
|
||||
"""Get an album info proxy object given either an item or an
|
||||
album id.
|
||||
"""
|
||||
if isinstance(item, int):
|
||||
album_id = item
|
||||
else:
|
||||
sql = 'INSERT INTO albums (artist, album) VALUES (?, ?)'
|
||||
# Lazily create a row in the albums table if one doesn't
|
||||
# exist.
|
||||
sql = 'SELECT id FROM albums WHERE artist=? AND album=?'
|
||||
c = self.conn.execute(sql, (item.artist, item.album))
|
||||
album_id = c.lastrowid
|
||||
row = c.fetchone()
|
||||
if row:
|
||||
album_id = row[0]
|
||||
else:
|
||||
sql = 'INSERT INTO albums (artist, album) VALUES (?, ?)'
|
||||
c = self.conn.execute(sql, (item.artist, item.album))
|
||||
album_id = c.lastrowid
|
||||
return AlbumInfo(self, album_id)
|
||||
|
||||
def _album_get(self, album_id, key):
|
||||
|
|
|
|||
|
|
@ -409,6 +409,11 @@ class AlbumInfoTest(unittest.TestCase):
|
|||
# Cursor should only return one row.
|
||||
self.assertNotEqual(c.fetchone(), None)
|
||||
self.assertEqual(c.fetchone(), None)
|
||||
|
||||
def test_albuminfo_by_albumid(self):
|
||||
ai = self.lib.albuminfo(self.i)
|
||||
ai = self.lib.albuminfo(ai.id)
|
||||
self.assertEqual(ai.artist, self.i.artist)
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
|
|
|||
Loading…
Reference in a new issue