]> kaliko git repositories - mpd-sima.git/blobdiff - sima/lib/simadb.py
Better Meta object comparison
[mpd-sima.git] / sima / lib / simadb.py
index 6f881444efb8ab430052ff61b83355b74a31542e..a7ce7597d80050d00c006f493478c42b9410197d 100644 (file)
@@ -187,8 +187,8 @@ class SimaDB(object):
         """
         get album information from the database.
         if not in database insert new entry.
-        Attention: use Track() object!!
-        Use AlbumArtist tag is provided, fallback to Album tag
+        Attention: use Track|Album object!!
+        Use AlbumArtist tag if provided, fallback to Album tag
         """
         if with_connection:
             connection = with_connection
@@ -346,6 +346,24 @@ class SimaDB(object):
             self.close_database_connection(connection)
         return False
 
+    def get_artists_history(self, artists, duration=__HIST_DURATION__):
+        """
+        """
+        date = datetime.utcnow() - timedelta(hours=duration)
+        connection = self.get_database_connection()
+        rows = connection.execute(
+            "SELECT arts.name, albs.name, trs.name, trs.file"
+            " FROM artists AS arts, tracks AS trs, history AS hist, albums AS albs"
+            " WHERE trs.id = hist.track AND trs.artist = arts.id AND trs.album = albs.id"
+            " AND hist.last_play > ? ORDER BY hist.last_play DESC", (date.isoformat(' '),))
+        for row in rows:
+            if artists and row[0] not in artists:
+                continue
+            for art in artists:
+                if row[0] == art:
+                    yield art
+        self.close_database_connection(connection)
+
     def get_history(self, artist=None, artists=None, duration=__HIST_DURATION__):
         """Retrieve complete play history, most recent tracks first
         artist  : filter history for specific artist
@@ -606,7 +624,7 @@ class SimaDB(object):
             "SELECT artist FROM albums")] +
             [row[0] for row in connection.execute(
             "SELECT artist FROM tracks")])
-        orphans = [ (orphan,) for orphan in artists_ids - artist_2_artist_ids ]
+        orphans = [(orphan,) for orphan in artists_ids - artist_2_artist_ids]
         connection.executemany('DELETE FROM artists WHERE id = (?);', orphans)
         if not with_connection:
             connection.commit()
@@ -626,7 +644,7 @@ class SimaDB(object):
             """SELECT albums.id FROM albums
             LEFT JOIN tracks ON albums.id = tracks.album
             WHERE tracks.album IS NULL""")])
-        orphans = [ (orphan,) for orphan in orphan_black_ids & orphan_tracks_ids ]
+        orphans = [(orphan,) for orphan in orphan_black_ids & orphan_tracks_ids]
         connection.executemany('DELETE FROM albums WHERE id = (?);', orphans)
         if not with_connection:
             connection.commit()
@@ -646,7 +664,7 @@ class SimaDB(object):
             """SELECT tracks.id FROM tracks
             LEFT JOIN black_list ON tracks.id = black_list.track
             WHERE black_list.track IS NULL""")])
-        orphans = [ (orphan,) for orphan in hist_orphan_ids & black_list_orphan_ids ]
+        orphans = [(orphan,) for orphan in hist_orphan_ids & black_list_orphan_ids]
         connection.executemany('DELETE FROM tracks WHERE id = (?);', orphans)
         if not with_connection:
             connection.commit()