Skip to content

Instantly share code, notes, and snippets.

@ritiek
Last active February 3, 2024 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritiek/a5a741d0602c47deee136ae6737e1360 to your computer and use it in GitHub Desktop.
Save ritiek/a5a741d0602c47deee136ae6737e1360 to your computer and use it in GitHub Desktop.
Keep Spotify playlists in sync locally using spotdl

Setting up

First run

$ mkdir /media/spotdlsync
$ cd /media/spotdlsync

$ mkdir "Life is Strange"
$ cd "Life is Strange"
$ docker run -v "$(pwd):/music" --rm spotdl/spotify-downloader sync https://open.spotify.com/playlist/3zm1edwUQr94IznMv2PXiv?si=b342fc800a14433e --save-file life-is-strange.spotdl

Subsquent runs

Download spotdl-sync.sh spotdl-sync.service spotdl-sync.timer to the directories as mentioned in the beginning of each script. Update the download directory in spotdl-sync.service from /media/spotdlsync to whatever you kept in the first run section above.

Then run these:

$ sudo chmod +x /usr/local/bin/spotdl-sync
$ sudo systemctl daemon-reload
$ sudo systemctl enable --now spotdl-sync.timer

That should be it. This will sync your Spotify playlists locally every 6 hours, persistenly over reboots.

# /etc/systemd/system/spotdl-sync.service
[Unit]
Description=Sync Spotify playlists locally
AssertPathIsDirectory=/media/spotdlsync
After=network-online.target
[Service]
Type=oneshot
WorkingDirectory=/media/spotdlsync
ExecStart=/usr/local/bin/spotdl-sync
ExecReload=/bin/kill -9 $MAINPID
ExecStop=/bin/kill -9 $MAINPID
[Install]
WantedBy=multi-user.target
#!/bin/sh
# /usr/local/bin/spotdl-sync
for directory in */; do
cd "${directory}"
/usr/bin/docker run -v "$(pwd):/music" --rm spotdl/spotify-downloader sync "/music/$(ls *.spotdl)"
cd ..
echo
done
# /etc/systemd/system/spotdl-sync.timer
[Unit]
Description=Run sync Spotify playlists service periodically
[Timer]
Unit=spotdl-sync.service
OnBootSec=10m
OnUnitActiveSec=6h
[Install]
WantedBy=timers.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment