Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add functions needed for ScriptCollection Support in Tomahawk #240

merged 1 commit into from

2 participants


Add support for querying a bit more information from the beets web api to support the view of the whole collection in Tomahawk.

  • albums_for_artist does not expand the items as this is not needed by Tomahawk and expanding the items would increase the response time significantly
@xhochy xhochy referenced this pull request in tomahawk-player/tomahawk-resolvers

[beets] Add ScriptCollection support #42

@sampsyo sampsyo merged commit 828bee0 into sampsyo:master

1 check passed

Details default The Travis build passed

Awesome; thanks for looking into this!

I changed the API by one small detail: instead of a dedicated /album/artist/... API endpoint, one can now just use the standard query. Also, I'm defaulting to your new "non-expanded" behavior for the albums endpoint; this makes a lot of sense to me. I'm opening a corresponding PR in the tomahawk-resolvers repo.

@xhochy xhochy deleted the xhochy:feature/tomahawk-scriptcollections branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 2 deletions.
  1. +16 −2 beetsplug/web/
18 beetsplug/web/
@@ -24,7 +24,7 @@
# Utilities.
-def _rep(obj):
+def _rep(obj, expand=True):
"""Get a flat -- i.e., JSON-ish -- representation of a beets Item or
Album object.
@@ -44,7 +44,8 @@ def _rep(obj):
elif isinstance(obj, beets.library.Album):
out = dict(obj._record)
del out['artpath']
- out['items'] = [_rep(item) for item in obj.items()]
+ if expand:
+ out['items'] = [_rep(item) for item in obj.items()]
return out
@@ -97,6 +98,12 @@ def all_albums():
all_ids = [row[0] for row in rows]
return flask.jsonify(album_ids=all_ids)
+def albums_for_artist(artist):
+ albums = g.lib.albums(artist=artist)
+ # Expanding album items would cost a lot of runtime which is not needed here
+ return flask.jsonify(results=[_rep(album, False) for album in albums])
def album_query(query):
parts = query.split('/')
@@ -108,6 +115,13 @@ def album_art(album_id):
album = g.lib.get_album(album_id)
return flask.send_file(album.artpath)
+# Artists.
+def all_artists():
+ with g.lib.transaction() as tx:
+ rows = tx.query("SELECT DISTINCT albumartist FROM albums")
+ all_artists = [row[0] for row in rows]
+ return flask.jsonify(artist_names=all_artists)
# UI.
Something went wrong with that request. Please try again.