# Meta backend for beets queries

**URL:** <https://discourse.mopidy.com/t/meta-backend-for-beets-queries/762>\
**Category:** Misc\
**Created:** [June 9, 2015, 10:49am UTC](https://discourse.mopidy.com/t/meta-backend-for-beets-queries/762 "2015-06-09T10:49:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![giorgos](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/giorgos/32/197_2.png) [@giorgos](https://discourse.mopidy.com/u/giorgos)\
**Post date:** [June 9, 2015, 10:49am UTC](https://discourse.mopidy.com/t/meta-backend-for-beets-queries/762/1 "2015-06-09T10:49:28Z")

</div>

Hi all,

I’m a fan and user of both mopidy and beets. I want to combine them in a way so I can support beet queries in playlists.

Imagine the following:

- In playlists, for example m3u playlists using the M3U Playlist extension, and there are entries using the uri `beetsquery:albumartist:muse album:drones track+`.
- Then the `beetsquery` backend, which has already loaded the beets database, executes the query and generates a list of mopidy `Tracks` with their uri pointing to the path returned by beets, e.g. `file:///data/Music/Muse/Drones/01.flac`

This will allow us to take advantage of the powerful beets query language and run queries like `beetsquery:genre:garage` or `beetsquery:year:2010..2015`

The way I’m thinking to implement this I won’t be implementing a real backend but a meta-backend, which will run a query and add `Tracks` to the queue for the streaming backend to play. Since there is no access to `core` in backend extensions -but only in frontend extensions- I need some pointers on what to overload to achieve my goal.

Ideas and / or other approaches are welcome. I just started to dive into mopidy’s code so I could be missing something.

Thanks!

---

<div class="post-metadata">

**Author:** ![adamcik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/adamcik/32/5_2.png) [@adamcik](https://discourse.mopidy.com/u/adamcik)\
**Post date:** [June 9, 2015, 8:18pm UTC](https://discourse.mopidy.com/t/meta-backend-for-beets-queries/762/2 "2015-06-09T20:18:33Z")

</div>

Some thing like that should be doable, have you checked if one of, or both of the following extensions might solve what you are looking for?

- [https://github.com/rawdlite/mopidy-beets-local](https://github.com/rawdlite/mopidy-beets-local)
- [https://github.com/mopidy/mopidy-beets](https://github.com/mopidy/mopidy-beets)

And yes having a backend that only implements library features and returns URLs that some other backend can handle is supported.

---

<div class="post-metadata">

**Author:** ![giorgos](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/giorgos/32/197_2.png) [@giorgos](https://discourse.mopidy.com/u/giorgos)\
**Post date:** [June 10, 2015, 8:15am UTC](https://discourse.mopidy.com/t/meta-backend-for-beets-queries/762/3 "2015-06-10T08:15:49Z")

</div>

> [@adamcik](#):
>
> Some thing like that should be doable, have you checked if one of, or both of the following extensions might solve what you are looking for?
> 
> [GitHub - rawdlite/mopidy-beets-local: Access a local beets library from mopidy via beets native api](https://github.com/rawdlite/mopidy-beets-local)

I think `beets-local` is close but as far as I understand it doesn’t allow user to run raw beet queries and directly play the results. Maybe @rawdlite can comment?

> [@adamcik](#):
>
> And yes having a backend that only implements library features and returns URLs that some other backend can handle is supported.

Can you give me some hints? Want I actually want is a [translate\_uri](https://docs.mopidy.com/en/latest/api/backends/#mopidy.backend.PlaybackProvider.translate_uri) like method which can return a `list` of uris.

---

<div class="post-metadata">

**Author:** ![adamcik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/adamcik/32/5_2.png) [@adamcik](https://discourse.mopidy.com/u/adamcik)\
**Post date:** [June 10, 2015, 8:28am UTC](https://discourse.mopidy.com/t/meta-backend-for-beets-queries/762/4 "2015-06-10T08:28:11Z")

</div>

> [@giorgos](#):
>
> Can you give me some hints? Want I actually want is a translate\_uri like method which can return a list of uris.

[mopidy.core — Core API — Mopidy 4.0.0a1 documentation](https://docs.mopidy.com/en/develop/api/core/#mopidy.core.LibraryController.lookup) is what you just described. The backend version of this is `lookup(uri) --> list[Tracks]`.

---

<div class="post-metadata">

**Author:** ![rawdlite](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/rawdlite/32/764_2.png) [@rawdlite](https://discourse.mopidy.com/u/rawdlite)\
**Post date:** [June 10, 2015, 9:14am UTC](https://discourse.mopidy.com/t/meta-backend-for-beets-queries/762/5 "2015-06-10T09:14:59Z")

</div>

Hi Giorgos,

I also like mopidy and beets a lot, which is the reason i wrote beets-local to have a feature complete local backend for mopidy.  
Now what beets-local does is, it takes search and browse requests from mopidy-core, translates them to a beets query and runs them against beets using its API. Unfortunately syntax and structure from mopidys queries and beets queries differ quite a lot. Not all of beets query abilities can be expressed in a mopidy query. (And vice versa)

That being said, i think the browse function in beets-local could be adapted to accept a native beets query as i am pretty free in the way i build the url schema and the browse tree there.  
The result would be a list of Tracks and Albums ( Although i haven’t yet seen a client that uses the returned albums array )

A client that issues this raw beets queries as browse request an adds the result to the mopidy play queue would need to be written.  
I started a a headless client [https://github.com/rawdlite/mopidy-remote](https://github.com/rawdlite/mopidy-remote) that could be extended to do that.

On the other hand you could just use a beets plugin to build mopidy playlists from beets queries.

HTH
