Music Library

Deprecated and discontinued. Use NGINX + Furumi HTTP Fuse

Preface

I’ve used Goolge Music, Youtube Music, Yandex.Music & Spotify. The last one is the best, but i can’t control it so I’ve made self hosted service. First of all I managed to setup NFS share on my Linux Server and share it between my workstations, it’s quite simple and reliably but it’s hard to secure and can’t stand network changes. I come into two solutions. Player way 1. Make an API that can handle my music library and serve clients who want it. 2. Make a player or plugin for existent player as a client for my API. Filesystem way 1. Same as previous #1 2. Make a FUSE app to mount my library over HTTPS securely.


API was made by @nixargh. I’ve tried player way first, you can find it in GitHub taihen player. Player works somehow but i do not support it anymore. Later I’ve made FUSE app mus-fuse it works exactly i want it to. With any player, i use Cmus btw.

Prerequisites

  • Linux server with music. I use Ubuntu 18.04
  • Linux box as a client. I use Arch Linux

Setup server

Precompiled binary is available on release page playongo. Also you can compile it according to README.md. Scan music library, it takes some time:

$ ./playongo -musicDir ~/Music -scan

Create user for running server

$ sudo useradd -d /storage/MUS/ -c "playongo server" -U -r playongo 

Create systemd unit /lib/systemd/system/playongo.service for managing API app. Unit file assumes that playongo binary located in /opt/playongo/playongo and music is stored in /storage/MUS/.

[Unit]
Description=Playongo music library service
[Service]
Type=simple
User=playongo
Group=playongo
Restart=always
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
WorkingDirectory=/opt/playongo
ExecStart=/opt/playongo/playongo -musicDir /storage/MUS/
ExecStop=/usr/bin/killall -TERM /opt/playongo/playongo
[Install]
WantedBy=multi-user.target

Enable and start unit:

$ sudo systemctl enable playongo.service
$ sudo systemctl enable playongo.service
# Check if it works. It should show your music library as JSON.
$ curl http://localhost:12345/songs | less 

Also it’s a good idea to run Nginx as a proxy and SSL terminator, here is an example of setup, make sure you do have SSL certificates. If don’t so create a new certificate from Let’s Encrypt immediately. Also mind that auth_basic is enabled. It’s strongly recommend to use it but you can disable it by commenting any auth_basic* directives. How to create .htpasswd Do not use CloudFlare because low latency is a decisive factor here.

server {
    listen 80;
    listen [::]:80;

    server_name mus.hexor.ru;

    gzip on;
    gzip_min_length 256;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_vary on;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://127.0.0.1:12345;
        proxy_redirect off;
        auth_basic           "Administrator’s Area";
        auth_basic_user_file /etc/nginx/.htpasswd;
    }

### SSL PART
    listen [::]:443 ssl ipv6only=on; 
    listen 443 ssl; 
    ssl_certificate /etc/letsencrypt/live/mus.hexor.ru/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/mus.hexor.ru/privkey.pem; 
    include /etc/letsencrypt/options-ssl-nginx.conf; 
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 
### END OF SSL PART

}

Client side

As FUSE is using for mus-fuse it should be installed, fuse package for Arch Linux and Ubuntu. Precompiled binary is available on release page mus-fuse. Also you can compile it according to REAMDE.md.

Mus-fuse can be run like that:

$ export HTTP_USER=user
$ export HTTP_PASS=pass
$ export RUST_LOG=info
$ ./mus-fuse <address> <mountpoint>
# address is your server with playongo with protocol (https|http)

Systemd unit file may be like this:

[Unit]
Description=Mount mus-fuse

[Service]
User=ab
Type=simple
Environment=HTTP_USER=user
Environment=HTTP_PASS=pass
ExecStart=/usr/bin/mus-fuse /MUS https://mus.hexor.ru
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

#linux #golang #rust #music #cmus #selfhosted

Leave a Reply

Your email address will not be published.