Skip to content

Commit 1649512

Browse files
committed
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.
1 parent 7053694 commit 1649512

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

beetsplug/web/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ def all_items():
7373
all_ids = [row[0] for row in rows]
7474
return flask.jsonify(item_ids=all_ids)
7575

76-
@app.route('/item/count')
77-
def iten_count():
78-
with g.lib.transaction() as tx:
79-
rows = tx.query("SELECT COUNT(*) FROM items")
80-
return flask.jsonify({'itemcount': rows[0][0]})
81-
8276
@app.route('/item/<int:item_id>/file')
8377
def item_file(item_id):
8478
item = g.lib.get_item(item_id)
@@ -130,6 +124,19 @@ def all_artists():
130124
return flask.jsonify(artist_names=all_artists)
131125

132126

127+
# Library information.
128+
129+
@app.route('/stats')
130+
def stats():
131+
with g.lib.transaction() as tx:
132+
item_rows = tx.query("SELECT COUNT(*) FROM items")
133+
album_rows = tx.query("SELECT COUNT(*) FROM albums")
134+
return flask.jsonify({
135+
'items': item_rows[0][0],
136+
'albums': album_rows[0][0],
137+
})
138+
139+
133140
# UI.
134141

135142
@app.route('/')

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ And some little enhancements and bug fixes:
3333

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

0 commit comments

Comments
 (0)