From 7de294ba9f1e427e3cb1afc83485ed78262d0ffa Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Wed, 21 Jul 2010 11:26:43 -0700 Subject: [PATCH] add get_item convenience function to fetch Items by id The beetfs project uses this to quickly get paths for items when reading them. --- beets/library.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/beets/library.py b/beets/library.py index 64957bd26..dd48c2f36 100644 --- a/beets/library.py +++ b/beets/library.py @@ -884,6 +884,19 @@ class Library(BaseLibrary): " ORDER BY artist, album, disc, track" c = self.conn.execute(sql, subvals) return ResultIterator(c, self) + + + # Convenience accessor. + + def get_item(self, id): + """Fetch an Item by its ID. Returns None if no match is found. + """ + c = self.conn.execute("SELECT * FROM items WHERE id=?", (id,)) + it = ResultIterator(c, self) + try: + return it.next() + except StopIteration: + return None # Album-level data.