First of course I searched for some already existing implemetations, but the
ones I found were either outdated (using the old API) or I didn’t like how they
were used or how things were implemented. Then after checking the API Docs I
got the idea of just using curl to upload replays, since there is no fancy
authentication workflow needed to generate a token. The API just uses the
authorization key from My Account ➡️ Settings ➡️ API Access as value in an
Authorization
header, so uploading a replay is just a single API call.
The result is a simple bash script, that uses inotify tools to watch the folder where the replay files are located and uploads each newly created replay file after creation. Renaming replay later within Starcraft II does not re-upload replays.
See the source code here: sc2replaystats.sh
To use this uploader download the script, edit it and set your sc2replaystats API key in line 20 and run the script before starting Starcraft. If you are using lutris you can set it up to start when you are starting the game.
I want the uploader automatically running on login, so I created a user spaced systemd unit. Systemd also makes sure it keeps running or gets restarted on failure.
To do so, I created a file ~/.config/systemd/user/sc2replaystats.service
with
the content:
[Unit]
Description=Upload Starcraft II replays to sc2replaystats.com
[Service]
Type=simple
StandardOutput=journal
ExecStart=<absolute path to sc2replaystats.sh>
[Install]
WantedBy=default.target
Now these commands in the terminal:
systemctl --user enable sc2replaystats
systemctl --user start sc2replaystats
The first one makes sure the service gets started on login, the second one starts it in the current session - this is not necessary in following sessions.