Commits

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/__init__.py

     all_ids = [row[0] for row in rows]
     return flask.jsonify(item_ids=all_ids)
 
-@app.route('/item/count')
-def iten_count():
-    with g.lib.transaction() as tx:
-        rows = tx.query("SELECT COUNT(*) FROM items")
-    return flask.jsonify({'itemcount': rows[0][0]})
-
 @app.route('/item/<int:item_id>/file')
 def item_file(item_id):
     item = g.lib.get_item(item_id)
     return flask.jsonify(artist_names=all_artists)
 
 
+# Library information.
+
+@app.route('/stats')
+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.
 
 @app.route('/')

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.