4o1x5.dev/content/post/guides/ host-your-own-spotify/index.en.md
2024-07-15 21:55:44 +02:00

8.3 KiB

title description date image categories tags draft writingTime
Ditch spotify, make your own Stream music from your local jellyfin server 2024-07-15 07:00:00+0000 feishin.png
Nix
Piracy
Jellyfin
Music
Homelab
Selfhost
false 1h 40m

Introduction

I have ditched all kind of subscription based services as of 2024. Spotify was one of my last subscriptions I cancelled and I have migrated to listening offline, then to online via my jellyfin server. I mainly listen to high-bitrate flac music that I pirate from sources like soulseek. I have a collection of about 1000 music from 500 different artists.

I download flacs only to make my self feel better by saying I listen to HQ music but in reality I probably don't hear the difference between a 128kb compressed MP3 and a 1440kb ripped Flac. I also have a entry level KZ ZS10 IEM that I use with my on-board audio driver. I am also a based bass enjoyer, so all I really need is sub frequencies...

Why pirate?

My main reason is privacy. I have yet to find a platform that respects my privacy and allows me to buy any kind of albums/songs with Bitcoin or Monero, therefore my last resort is to pirate. I could buy the original CD's but most artists I listen to don't have one, and I loath ripping.
Everyone has their own opinion about piracy, and I think in my case it's a 100% justified.

Jellyfin

Jellyfin is a Free Software Media System that puts you in control of managing and streaming your media. It is an alternative to the proprietary Emby and Plex, to provide media from a dedicated server to end-user devices via multiple apps.

Jellyfin is a really great mediaserver, It has many clients and supports almost any kind of media, ranging from visual to audible.
I have been using it for about two years now, but recently I just realized I could stream my music from there instead of syncing my pirated music to all my devices. For the past few days It has been a pleasureful experience and I have no complaints.

Feishin desktop

Feishin is a rewrite of sonixd, a client for subsonic.
It's a really clean music client for jellyfin, I found it in nixpkgs and I use it daily.
It has many features and a modern spotify-like UI. Sadly it's missing a download feature, meaning I cannot download music then listen to it on the road or something like that. Streaming flacs is really inefficient if you are using mobile data or some public data. I travel a lot meaning this is kind of a deal breaker, but I can just use my phone. Here is a video of how it looks like in it's fullscreen mode:

Finamp mobile

Finamp is an open-source jellyfin music client for Android.
It's one of the most feature rich clients out there, supporting many features also found in the mobile Spotify client.
I don't really like it's design as It doesn't really look like Spotify but that probably due to their focus not being on that. Regardless Its clean.

Song focus List of songs

Self-hosting

Jellyfin

Nixpkgs has jellyfin options so we can deploy it that way. It's really straight-forward and seamless.
This example also includes a nginx configuration, since I'm assuming you want to access it from remote locations and maybe share it with friends.

{ pkgs, config, ... }: {

  services.jellyfin = {
    enable = true;
    # Setting the home directory
    # might need to create with mkdir /home/jellyfin
    dataDir = "/home/jellyfin";
  };
  services.nginx = {
    virtualHosts = {
      "jelly.${config.networking.domain}" = {
        forceSSL = true;
        enableACME = true;

        locations."/" = {
          extraConfig = ''
            proxy_pass http://localhost:8096;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Protocol $scheme;
            proxy_set_header X-Forwarded-Host $http_host;
          '';

        };
        # Enable socket for features like syncPlay and live view in the admin panel
        locations."/socket" = {
          extraConfig = ''
            proxy_pass http://localhost:8096;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Protocol $scheme;
            proxy_set_header X-Forwarded-Host $http_host;
          '';
        };
      };
    };
  };
}

After this you can head to jelly.yourdomain.com and run the setup.
Keep in mind this is a really basic setup, all data will be stored at /home/jellyfin including the SQLite database.

slskd

slskd is a fully featured modern client-server client for soulseek. You can log in to it's panel and download files from the network.
I had some problems with permissions when I was trying to use the native version from nixpkgs, so instead I just made an oci-container that uses linux namespaces to run applications. Docker and podman is also based on it.

Create directories

mkdir /home/jellyfin/Music
mkdir /home/jellyfin/Music/unsorted
{ pkgs, config, ... }: {

  # Define the slskd container
  virtualisation.oci-containers.containers = {
    slskd = {
      image = "slskd/slskd";
      ports = [
        "5030:5030" # panel
        "50300:50300" # soulseek
      ];
      volumes = [
        # you can use picard or similar applications to sort them, that's why I link it to unsorted
        "/home/jellyfin/Music/unsorted:/downloads"
        "/home/jellyfin/Music:/music"
      ];

      environment = {
        SLSKD_SHARED_DIR = "/music";
        SLSKD_DOWNLOADS_DIR = "/downloads";
        SLSKD_USERNAME = "slskd username";
        SLSKD_PASSWORD = "slskd password";
        SLSKD_SLSK_USERNAME = "soulseek login name";
        SLSKD_SLSK_PASSWORD = "soulseek login name";
        SLSKD_SLSK_LISTEN_IP_ADDRESS = "0.0.0.0";
      };
    };
  };
  # Open the ports for slskd so users can download from you
  networking.firewall = {
    enable = true;
    allowedTCPPorts = [
      50300
    ];
    allowedUDPPorts = [
      50300
    ];
  };


  services.nginx = {
    virtualHosts = {
      "soulseek.${config.networking.domain}" = {
        forceSSL = true;
        enableACME = true;
        locations."/" = {
          extraConfig = ''
            proxy_pass http://localhost:5030;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header Host $host;
            proxy_request_buffering off;
          '';
        };
      };
    };
  };
}

Don't forget to open up the ports on your router so that users can download from you!

Usage

Create a music library for jellyfin

Head to the defined jellyfin domain, and log in with the credentials you have given. On the top right click on the profile icon and head to Dashboard -> Libraries -> Add Media Library and add a new music library like in the picture.

Download music

Head to the domain soulseek domain you have defined, and log into slskd.
Slskd is really easy to use, upon entering you are greeted with the search bar, type in anything and hit enter. Slskd will search other peers on the network for the string and return files.

After hitting download slskd will put it in /home/jellyfin/Music/unsorted. Jellyfin will automatically scan you library every 3 hours bot you can override this by clicking Scan All Libraries in the Dashboard

Connect a client.

Download a client, I recommend the ones I mentioned and connect to your server.
They will ask for a server url, which is always https://jelly.yourdomain.com and your user credentials.

Enjoy