Idea
A Tonie figurine (or NFC Tag) which always plays the latest episode of a podcast. The content should update automatically as soon as a new episode is available.
Possible solution
A cron job which runs a small shell script (every few hours). It checks if a new podcast episode is available on the official RSS feed. If so, it overwrites the content filepath of a tap
(which I assigned to a Tonie) and deletes the previously cached taf file in the Teddycloud library.
The base bus.tap
in my library is very basic and looks like this:
{
"type": "tap",
"filepath": "lib://by/tapID/bitsundso.taf",
"name": "Bits und so",
"files": [
{
"filepath": "https://media2.bitsundso.de/bits/2024/bits-2024-12-01-926.mp3",
"name": "Bits und so Podcast"
}
]
}
Now here’s the shell script which only needs jq
as a dependency (besides default Linux Gnu Tools like curl, grep, sed, cat):
bus-updater.sh
#!/bin/bash
# teddyCloud library path
lib_dir="/var/lib/docker/volumes/teddycloud_library/_data"
# podcast feed url
podcast_feed="https://www.bitsundso.de/feed/"
# get latest episode mp3
latest=$(curl -s "$podcast_feed" | sed -n 's/.*url="\([^"]*\).*/\1/p' | head -1)
# get current tap episode mp3
current=$(cat $lib_dir/bus.tap | jq -r '.files[0].filepath')
# check if new episode exists
if [[ -n "$latest" && "$latest" != "$current" ]]; then
# change tap mp3 filepath in-file
contents=$(jq ".files[0].filepath = \"$latest\"" $lib_dir/bus.tap) && \
echo -E "${contents}" > $lib_dir/bus.tap
# delete cached taf with former episode
rm "$lib_dir/by/tapID/bitsundso.taf"
fi
Important: make script executable (chmod +x bus-updater.sh
) and execute as sudo
.
For a cronjob which runs every 6 hours (adapt the script path):
sudo crontab -e
0 */6 * * * /bin/bash /home/pi/scripts/bus-updater.sh &>/dev/null &
:wq