Scrobbling Your Music with Maloja
Some people like tracking every little bit of their life, including the music they listen to. In fact, there are platforms online that will graciously track and display information for you, such as Last.fm and Listenbrainz. However, there’s also a subsection of these individuals that may not want to have a third party in control of their music listening habits. That’s where Maloja comes in.
Maloja is a Python-based music scrobble database that you can host yourself!
Neat things:
- It supports any scrobbler with the Listenbrainz API if you supply the endpoint
/apis/listenbrainz
- It has a Docker image, so you can set it up easily.
- You can write rules to automatically rename scrobbled titles or artists.
- You can merge together song scrobbles. Helpful for when you rename a song and need to merge the old scrobbles.
Meh things:
- Supports only one user.
- Cannot natively host on a subdirectory of a domain.
- Looks pretty awful on mobile. While the album art is gigantic, some of the user interface is absurdly small.
Docker Setup
I love Docker. Everything’s so easy to spin up. Here’s my Docker Compose file.
---
version: "3"
services:
maloja:
container_name: "maloja"
# Make sure to change this to the latest
# version on DockerHub:
# https://hub.docker.com/r/krateng/maloja
image: "krateng/maloja:3.1.5"
environment:
# This will be the password to the admin panel of Maloja
MALOJA_FORCE_PASSWORD: "{A very strong password}"
# This skips any interactive steps of
#Maloja's setup, since we're using Docker.
MALOJA_SKIP_SETUP: true
# This sets the directory that Maloja uses inside the Docker container.
MALOJA_DATA_DIRECTORY: "/data"
ports:
- "3418:42010"
# Make sure the right-side of the colon is equal to
# MALOJA_DATA_DIRECTORY or you could end up
# deleting your database.
volumes:
- "./data:/data"
Run docker compose up -d
and that should be it, you’re done.
Maloja behind Nginx
Now, what if you want to scrobble Maloja behind HTTPS? A bog-standard HTTPS configuration will do, but my Maloja does not appear to allow the OPTIONS method, which means CORS requests with browser-based scrobblers like Web Scrobbler with fail with 402 Method Not Allowed
. I fix this with a hack in my configuration.
server {
listen 80;
listen [::]:80;
return 301 https://$server_name$request_uri;
server_name maloja.example.org;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name maloja.example.org;
ssl_certificate /path/to/certificate;
ssl_certificate_key /path/to/privatekey;
ssl_session_timeout 5m;
location / {
proxy_pass http://localhost:3418;
}
location /apis {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST' always;
add_header 'Access-Control-Allow-Headers' 'content-type' always;
# Avoid 405 Method Not Allowed
# I assume it's because Maloja doesn't include "OPTIONS"
# in its "Allow" header.
if ($request_method = OPTIONS ) {
return 200;
}
proxy_pass http://localhost:3418;
}
Connecting Scrobblers to Maloja
There are some cool programs I’ve been playing with to scrobble my music to Maloja. Here’s how you, too, can configure them to scrobble music.
First, you’ll need to get an API key from Maloja. I recommend creating a new key for each scrobbler.
- Navigate to your Maloja instance in a browser.
- Click the cog in the top right.
- Select API Keys from the navigation.
- Think of a cool name for your API key and click “New Key'.
- Copy the key you generated.
Web Scrobbler (browser-based)
Using Web Scrobbler, you can scobble music from tons of music platforms, especially those that don’t natively support scrobbling. It actually supports Maloja natively.
You can set it up Maloja by:
- Navigate to the Web Scrobbler settings.
- Go to “Accounts” and find “Maloja”.
- Insert
{MALOJA_URL}/apis/mlj_1/newscrobble
for the “API URL”. - Insert your Maloja API token for “Token”.
Now start playing music on any of the sites that Web Scrobbler supports and you’ll see it on Maloja!
Pano Scrobbler (Android)
On Android devices, you can scrobble anything that uses the music notification panel with Pano Scrobbler. However, you will need to scrobble to Maloja by pretending that it’s a custom Listenbrainz server.
If you are opening the app for the first time…
- Select “Custom Listenbrainz” from the dropdown.
- Insert
{MALOJA_URL}/apis/listenbrainz/
for the “API URL”. - Insert your Maloja API token for “Authentication token”.
If you want to add Maloja…
- Open the user menu.
- Select “Configure”.
- Scroll down to “Services”.
- Follow the steps above.
If you’ve just got Maloja, nothing in Pano Scrobbler app itself works. The “Friends” and “Charts” tabs load endlessly and “Scrobbles” is forever empty. However, it will dutifully scrobble your music to Maloja regardless.
Inside Navidrome
Navidrome is a selfhosted music player compatible with the Subsonic API. Unfortunately, you’ll need access to the Navidrome configuration if you want to scrobble music directly from it.
- In your Navidrome configuration, set
ListenBrainz.BaseURL
to{MALOJA_URL}/apis/listenbrainz/1/
.- To be honest, I’m not sure if the
/1/
matters. But it works. - If you’re on Docker, you can use the enviroment variable
ND_LISTENBRAINZ_BASEURL
.- Because Navidrome itself sends the scrobble, you can put Maloja and Navidrome in the same Docker network and set it to
http://maloja:42010/apis/listenbrainz/1/
!
- Because Navidrome itself sends the scrobble, you can put Maloja and Navidrome in the same Docker network and set it to
- To be honest, I’m not sure if the
- After logging into Navidrome, click your profile in the top right and select “Personal”.
- Enable “Scrobble to ListenBrainz”.
- Enter your Maloja API token.
If you get a green toast at the top, you’re done.
Fun tip: if you listen to music on Navidrome using app that supports the Subsonic API, Navidrome will automatically scrobble the music! However, unlike the web UI, it seems to only scrobble when the song is completely finished, at least with the app I’m using.
Setting Rules in Maloja
You can write rules to normalize your scrobbles, such as translating songs to their English name or fixing typos.
- Navigate to
rules
in the Maloja data directory. - Create a new
.tsv
file. - Write down your new rules.
- Read through the
rules.info
file in the same directory for help, or look at a pre-made.tsv
under thepredefined
directory.
- Read through the
- Save the file and restart Maloja.
- I’m not sure if there’s a way to hot-reload the rules in Maloja, but they don’t seem to take effect until you do restart.
Once you do this, new songs will be automatically translated. For old songs, you may need to activate “Admin Mode” in the Maloja admin panel and click the reparse button. Alternatively, you can merge them with the newly-renamed songs by selecting the old song, hitting the pull request icon, selecting the new song, and clicking Merge.
Fun tip: if you put your .tsv
. in predefined
, it’ll appear in your admin panel under “Server Setup”. If you follow the format of YOURNAME_FILENAME.tsv
like the other predefined rules, your name will appear as the author there, too. You can use # NAME:
and # DESC:
in the .tsv
itself to change the title and description of your module.
Sadly, there isn’t a page in Maloja that properly displays your own rules.
Here’s an example:
# NAME: Bocchi the Rock!
# DESC: Romanizes the tracks and artists for Kessoku Band.
# Kessoku Band
replaceartist 結束バンド kessoku band
## Kessoku Band (album)
replacetitle 青春コンプレックス seisyun complex
replacetitle ひとりぼっち東京 hitoribocchi tokyo
replacetitle ひみつ基地 Secret base
replacetitle ギターと孤独と蒼い惑星 Guitar, Loneliness and Blue Planet
replacetitle Guitar to Kodoku to Aoi Hoshi Guitar, Loneliness, and Blue Planet
replacetitle ラブソングが歌えない I can't sing a love song
replacetitle Love Song ga Utaenai I can't sing a love song
replacetitle あのバンド That band
replacetitle Ano Bando That Band
replacetitle カラカラ Karakara
replacetitle 小さな海 The Little Sea
replacetitle Chiisana Umi The Little Sea
replacetitle なにが悪い What is wrong with
replacetitle Nani ga Warui What is wrong with
replacetitle 忘れてやらない Never forget
replacetitle Wasurete Yaranai Never forget
replacetitle 星座になれたら If I could be a constellation
replacetitle Seiza ni Naretara If I could be a constellation
replacetitle フラッシュバッカー Flashbacker
replacetitle 転がる岩、君に朝が降る Rockn' Roll, Morning Light Falls on You
replacetitle Korogaru Iwa, Kimi ni Asa ga Furu Rockn' Roll, Morning Light Falls on You
Note that these are tabs between each column, not spaces. The amount of tabs doesn’t matter, just make sure you’re putting tabs.
Fixing artist and album cover art
Maloja often displays the wrong album or song art. If you want to fix it, go to your settings and activate “Admin Mode.” While in this mode, click on any artist or song and you can edit their name or add new cover art by dragging an image onto the old image. It, as expected, supports JPEG and PNG, as well as WebP. You can drag a GIF, too, but it’ll only apply the first frame as the art.
There doesn’t seem to be a way to do it preemptively for entire albums, since Maloja only concerns itself with individual songs. You’re going to have to listen to all the songs first, then go back and fix the art.
Also note that it doesn’t seem to like high resolution album art. 600x600 works, but a 1000x1000 gives me 413 Request Entity Too Large
. And this is not about file size because that 1000x1000 was only 80.7 kB compared to the 600x600 at 96.4 kB.