diff -r 13f56bb29b96 -r 85c8f5280d48 imms.py --- a/imms.py Sun Feb 08 16:55:24 2004 -0500 +++ b/imms.py Sun Feb 08 17:27:21 2004 -0500 @@ -12,7 +12,7 @@ self.cx = sqlite.connect(dbname, autocommit = 1, timeout = 2, encoding = ('utf-8', 'replace')) self.cu = self.cx.cursor() - def get_library_entries(self, **kw): + def get_library_entry(self): qry = "SELECT path, uid, sid FROM Library"; first = 1 for key in kw.keys(): @@ -51,13 +51,33 @@ def erase_path(self, path): self.cu.execute("DELETE FROM Library WHERE path = '%s';" \ % quote_sql(path)) - def get_ratings(self, min = 0, max = 250): + def get_paths(self, uids = None, sids = None): + qry = "SELECT uid, sid, path FROM Library" + first = 1 + for uid in uids: + if first: + qry += ' WHERE' + first = 0 + else: + qry += ' OR' + qry += " uid = %d" % uid + for uid in uids: + if first: + qry += ' WHERE' + first = 0 + else: + qry += ' OR' + qry += " sid = %d" % uid + qry += ';' + self.cu.execute(qry) + return self.cu.fetchall() + def get_ratings(self, min = 0, max = 150): self.cu.execute('''SELECT Rating.uid, Rating.rating FROM Rating WHERE Rating.rating >= %d AND Rating.rating <= %d ORDER BY Rating.rating;''' % (min, max)) - return cu.fetchall() + return self.cu.fetchall() def get_acoustics(self, uids = None): qry = "SELECT uid, bpm. spectrum FROM Acoustic" first = 1 @@ -70,7 +90,7 @@ qry += " uid = %d" % uid qry += ';' self.cu.execute(qry) - return cu.fetchall() + return self.cu.fetchall() def get_infos(self, sids = None): qry = "SELECT sid, artist, title FROM Infos" first = 1 @@ -83,7 +103,7 @@ qry += " sid = %d" % id qry += ';' self.cu.execute(qry) - return cu.fetchall() + return self.cu.fetchall() def get_last(self, sids = None): qry = "SELECT sid, last FROM Last" first = 1 @@ -96,26 +116,25 @@ qry += " sid = %d" % id qry += ';' self.cu.execute(qry) - return cu.fetchall() + return self.cu.fetchall() def get_uid_by_path(self, path): entries = self.get_library_entries(path = path) return map(lambda x: x[1], entries) def get_ratings_and_info(self, uids = None): - cu = self.cx.cursor() qry = '''SELECT l.uid, r.rating, l.path, ls.last - FROM Library l, Rating r, Last ls - WHERE l.uid = r.uid AND l.sid = ls.sid''' + FROM Library l, Rating r, Last ls + WHERE l.uid = r.uid AND l.sid = ls.sid''' if uids: qry += ' AND (l.uid = %d' % (uids.pop()) for uid in uids: qry += ' OR l.uid = %d' % uid qry += ')' qry += ';' - cu.execute(qry) + self.cu.execute(qry) # Better to fetch everything since locking can really mess # things in imms plugin. results = {} - tune = cu.fetchone() + tune = self.cu.fetchone() while tune: try: uid = int(tune[0]) @@ -129,5 +148,5 @@ 'last' : int(tune[3])} except UnicodeDecodeError: print tune[2] - tune = cu.fetchone() + tune = self.cu.fetchone() return results