soulseek shenanigans (nicotine gluetun port forwarding script)

published on

<== megmer ebubbles ==>

preamble

okay so i had been using sonarr, radarr, prowlarr, and qbittorrent, with gluetun to connect to proton vpn, so my isp doesn't send me a letter, as well as the gluetun qbittorrent port manager by snoringdragon to update the port, in order to download and organize content for my jellyfin media server.

that all works perfectly, with one hitch. i cant listen to music! i mean sure music piracy is trivially easy if youre okay with listening to youtube, mp3s, or otherwise compressed audio, but my ears are too good for that. no, i need a library full of lossless (or as close to lossless as i could find) audio files ready to stream at a moment's notice. the first thing i tried was lidarr, but that was underwhelming. the problem was that 1. torrent sites only really have mainstream music for whatever reason and 2. the database thingy that lidarr uses isnt very good, leading to a lot of music i enjoy not being listed, or being listed wrong.

i heard deezer lets you download flacs through some sort of api if you are a premium subscriber, and that there is a lidarr plugin that makes it all easy but wait wasnt i supposed to be pirating? it seems kinda weird to pay 10 bucks a month to pirate music, but whatever, thats still a good option i guess. (i might still set it up someday who knows)

soulseek

in comes soulseek (with the client nicotine+ behind this docker container), my personal messiah in terms of getting music for free. the way soulseek works is everyone (a good few of us) shares their files (usually music) to be indexed by the soulseek server and downloaded peer to peer by whoever wants it. you can think of it like bittorrent, except there is only one tracker and you are morally obligated to share all your obscure crap, making content easier to find. it doesnt work with lidarr or anything, so you gotta sort everything yourself, but thats not really a big deal to me.

also just like torrents, 2 clients can only connect if at least one of them has an open port. its still possible to use soulseek with a closed port, but you will have less to download and less people will download from you.

since i am pirating behind a vpn with an assigned port that changes every reload, i would have to change my settings every time the vpn restarts, which is often. qbittorrent has the same problem, but there are several scripts to update it. i searched online, but there were no scripts out there, so i decided to make my own.

the script

the script i made is a fork of this script. the prereqs for running it are:

  1. you have nicotine plus and gluetun up and running
  2. your vpn allows port forwarding
  3. you have /tmp/gluetun from the gluetun container and /root/.config/nicotine from the nicotine container mounted
  4. manually changing the port works

this is the first script i have ever written, so if its bad tell me. the important thing is it works. for best results, set a crontab to run the script every 12 hours or so.

#!/bin/bash

PORT_FORWARDED='YOUR/GLUETUN/TEMP/DIRECTORY/forwarded_port'

docker restart gluetun

update_port () {
PORT=$(cat $PORT_FORWARDED)
sed -i "29s/.*/portrange = ($PORT, $PORT)/" YOUR/NICOTINE/CONFIG/DIRECTORY/config
echo "successfully updated nicotine+ to port $PORT"
docker restart nicotine
exit 0
}

while true; do
if [ -f $PORT_FORWARDED ]; then
update_port
inotifywait -mq -e close_write $PORT_FORWARDED | while read change; do
update_port
done
else
echo "couldnt find file $PORT_FORWARDED"
echo "trying again in 10 seconds"
sleep 10
fi
done

<== megmer ebubbles ==>