it scrobbles your music to rocksky

add initial files

+20
README.md
···
+
# Rocksky Auto-scrobbler
+
+
A command-line program/service to automatically scrobble your music listening to [Rocksky](https://rocksky.app)!
+
+
## Prerequisites
+
+
You'll need the following pre-installed:
+
+
* [media-control](https://github.com/ungive/media-control)
+
* [jq](https://jqlang.org/)
+
+
I guess also bash. You probably have bash.
+
+
## Installation
+
+
From the folder, run `install.sh`, probably either as an admin user or as long as you know the sudo password. Once you've done that, it'll be running, and always run on startup.
+
+
## Pausing/Uninstalling
+
+
If you need to turn off the scrobbler, run `systemctl stop rocksky-autoscrobble`. (In this case, it will restart when your computer does, or when you restart the service.) If you need to disable it indefinitely, run `systemctl disable rocksky-autoscrobble.service`.
+11
install.sh
···
+
#!/usr/bin/env bash
+
+
sudo chmod +x scrobble.sh
+
sudo cp scrobble.sh /usr/bin/local
+
if [[ "$OSTYPE" == "darwin*" ]]; then
+
sudo cp rocksky-autoscrobble.plist ~/Library/LaunchAgents
+
else
+
sudo cp rocksky-autoscrobble.service /lib/systemd/system
+
sudo systemctl enable rocksky-autoscrobble.service
+
sudo systemctl start rocksky-autoscrobble.service
+
fi
+10
rocksky-autoscrobble.plist
···
+
<?xml version="1.0" encoding="UTF-8"?>
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+
<plist version="1.0">
+
<dict>
+
<key>Label</key>
+
<string>sh.birdwrongs.rockskyautoscrobbler</string>
+
<key>KeepAlive</key>
+
<true/>
+
</dict>
+
</plist>
+8
rocksky-autoscrobble.service
···
+
[Unit]
+
Description=Rocksky Autoscrobbler
+
+
[Service]
+
ExecStart=/usr/bin/local/scrobble.sh
+
+
[Install]
+
WantedBy=multi-user.target
+15
scrobble.sh
···
+
#!/usr/bin/env bash
+
+
index=0; media-control stream | \
+
while IFS= read -r line; do \
+
musicapp=$(jq -e '.payload.isMusicApp' <<< $line); \
+
if [ "$musicapp" = true ]; then \
+
title=$(jq -e '.payload.title' <<< $line); \
+
artist=$(jq -e '.payload.artist' <<< $line); \
+
if [ "$title" >/dev/null != null ]; then \
+
eval "rocksky scrobble $title $artist"; \
+
echo "rocksky scrobble $title $artist"; \
+
echo "rocksky scrobble $title $artist" >> cronlog.txt; \
+
fi \
+
fi \
+
done