Adrian Sampson committed e6a1c64

web: item_count -> stats (#333)

The new /stats endpoint now counts both items and albums. In the future, it
could also expose other interesting information.

  • Participants
  • Parent commits 022f4c9

Comments (0)

Files changed (2)

File beetsplug/web/

     all_ids = [row[0] for row in rows]
     return flask.jsonify(item_ids=all_ids)
-def iten_count():
-    with g.lib.transaction() as tx:
-        rows = tx.query("SELECT COUNT(*) FROM items")
-    return flask.jsonify({'itemcount': rows[0][0]})
 def item_file(item_id):
     item = g.lib.get_item(item_id)
     return flask.jsonify(artist_names=all_artists)
+# Library information.
+def stats():
+    with g.lib.transaction() as tx:
+        item_rows = tx.query("SELECT COUNT(*) FROM items")
+        album_rows = tx.query("SELECT COUNT(*) FROM albums")
+    return flask.jsonify({
+        'items': item_rows[0][0],
+        'albums': album_rows[0][0],
+    })
 # UI.

File docs/changelog.rst

 * Multi-disc directory names can now contain "disk" (in addition to "disc").
   Thanks to John Hawthorn.
+* :doc:`/plugins/web`: An item count is now exposed through the API for use
+  with the Tomahawk resolver. Thanks to Uwe L. Korn.
 * Python 2.6 compatibility for :doc:`/plugins/beatport`,
   :doc:`/plugins/missing`, and `/plugins/duplicates`. Thanks to Wesley
   Bitter and Pedro Silva.