# Commandline tool for working with Listenbrainz data

**URL:** <https://community.metabrainz.org/t/commandline-tool-for-working-with-listenbrainz-data/572368>\
**Category:** ListenBrainz\
**Tags:** command-line, development\
**Created:** [February 13, 2022, 5:46pm UTC](https://community.metabrainz.org/t/commandline-tool-for-working-with-listenbrainz-data/572368 "2022-02-13T17:46:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samthursfield2](https://community.metabrainz.org/user_avatar/community.metabrainz.org/samthursfield2/32/51187_2.png) [@samthursfield2](https://community.metabrainz.org/u/samthursfield2)\
**Post date:** [February 13, 2022, 5:46pm UTC](https://community.metabrainz.org/t/commandline-tool-for-working-with-listenbrainz-data/572368/1 "2022-02-13T17:46:38Z")

</div>

Hello everyone,

Here’s a project of mine that could be interesting for folk here. [Calliope](https://calliope-music.readthedocs.io/en/latest/) is a tool for “DIY music recommendations”. It wraps some music-related APIs and marshalls the output into a [JSPF-like format](https://calliope-music.readthedocs.io/en/latest/format.html). It provides some utilities for generating playlists, resulting in a commandline playground and a Python API for building simple playlist generators. (Or whatever else you want to do).

I just cut the first Calliope release with Listenbrainz support, making two new things possible:

- You can use `cpe listenbrainz export` to fetch playlists locally. You can export in a number of formats using `cpe export`, process them further, or upload to somewhere like Spotify.
- You can use `cpe listenbrainz-history` to download your history into a local SQLite database, and run some queries on it such as ‘tracks which I first heard in 2020’.

If you want a quickstart to play around with it, here’s how to [install from PyPI](https://pypi.org/project/calliope-music/) and then pull your “Year in Music 2021” playlists from Listenbrainz. (You might replace my name with yours in the example :- )

```auto
pip3 install --user calliope-music
cpe listenbrainz --user samthursfield2 export --kind created_for

```

Here’s how you can pull your listen history. This goes via the usual Listenbrainz API so it can take 10 minutes to sync a large listen history. (If you want to use this heavily - sync from an [LB data dump](https://listenbrainz.readthedocs.io/en/production/dev/listenbrainz-dumps/) instead).

Sync and show the 5 latest listens…

```auto
cpe listenbrainz-history --user samthursfield2 listens | head -n 5

```

Show tracks you first listened to this year:

```auto
cpe listenbrainz-history --no-sync --user samthursfield2 tracks --first-play-since 2022-01-01

```

Or artists you have known since 2010:

```auto
cpe listenbrainz-history --no-sync --user samthursfield2 artists --first-play-before 2010-01-01

```

(Remember that Listenbrainz itself doesn’t deduplicate your tags, so you might see ‘false positives’ here).

Plenty more things are possible, for further info you might check out…

- the [documentation](https://calliope-music.readthedocs.io/en/latest/index.html)
- the [code](https://gitlab.com/samthursfield/calliope/)
- a [talk I did at EuroPython 2021](https://www.youtube.com/watch?v=7APk4GqIlD0&t=1482s)

Bear in mind this is very much a side project and comes with no warranty of any kind. Contributions and bugfixes are very welcome.

Ps. if you compare this to Listenbrainz [Troi](https://github.com/metabrainz/troi-recommendation-playground/) recommender playground, here are two key design differences to consider:

- Troi is currently Metabrainz-specific while Calliope has some other integrations like Last.fm and Spotify
- Troi currently requires you write playlist generators in Python, while Calliope provides a commandline API, meaning you can integrate with any language that can spawn processes and read stdin/out.

Troi has [12 example generators](https://github.com/metabrainz/troi-recommendation-playground/tree/main/troi/patches), while Calliope has [5 examples](https://gitlab.com/samthursfield/calliope/-/tree/master/examples). I’m sure Troi has many advantages over Calliope. I recommend playing with both and seeing which you prefer! And if you make any cool playlist generators please share them here.

---

<div class="post-metadata">

**Author:** ![samthursfield2](https://community.metabrainz.org/user_avatar/community.metabrainz.org/samthursfield2/32/51187_2.png) [@samthursfield2](https://community.metabrainz.org/u/samthursfield2)\
**Post date:** [January 5, 2023, 6:41pm UTC](https://community.metabrainz.org/t/commandline-tool-for-working-with-listenbrainz-data/572368/2 "2023-01-05T18:41:15Z")

</div>

In case anyone here is going to [FOSDEM 2023](https://fosdem.org/2023/schedule/) in Brussels, i’ll be speaking a bit about this tool and open music recommendations in general in the [Python devroom](https://fosdem.org/2023/schedule/track/python/). It would be nice to meet other folk who are interested in Listenbrainz and Musicbrainz there! 🙂

---

<div class="post-metadata">

**Author:** ![rob](https://community.metabrainz.org/user_avatar/community.metabrainz.org/rob/32/29_2.png) [@rob](https://community.metabrainz.org/u/rob)\
**Post date:** [January 7, 2023, 9:31am UTC](https://community.metabrainz.org/t/commandline-tool-for-working-with-listenbrainz-data/572368/3 "2023-01-07T09:31:45Z")

</div>

I’ll be there – and yes, we should most deffo have a chat. I think Calliope is a rather interesting project… We need more projects like this to get people interested in open source recommendations!

---

<div class="post-metadata">

**Author:** ![rob](https://community.metabrainz.org/user_avatar/community.metabrainz.org/rob/32/29_2.png) [@rob](https://community.metabrainz.org/u/rob)\
**Post date:** [January 31, 2023, 7:25pm UTC](https://community.metabrainz.org/t/commandline-tool-for-working-with-listenbrainz-data/572368/4 "2023-01-31T19:25:38Z")

</div>

Ping, @samthursfield2 – I leave for Brussels on Friday. When is your talk? I would love to chat and certainly listen to your talk! Send me an email at rob@metab… to connect!

---

<div class="post-metadata">

**Author:** ![samthursfield2](https://community.metabrainz.org/user_avatar/community.metabrainz.org/samthursfield2/32/51187_2.png) [@samthursfield2](https://community.metabrainz.org/u/samthursfield2)\
**Post date:** [February 2, 2023, 10:27pm UTC](https://community.metabrainz.org/t/commandline-tool-for-working-with-listenbrainz-data/572368/5 "2023-02-02T22:27:40Z")

</div>

Hello, have just seen these nice messages and mailed you 🙂

The talk is [14:00 Sunday](https://www.fosdem.org/2023/schedule/event/python_music_recommendation/) in the Python devroom, I’ll probably be around the Python devroom most of the afternoon.
