Skip to content

Instantly share code, notes, and snippets.

@domcleal
Created December 4, 2011 11:08
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 domcleal/1429914 to your computer and use it in GitHub Desktop.
Save domcleal/1429914 to your computer and use it in GitHub Desktop.
Uploads radio station favourites to an Onkyo TX-NR509
#!/bin/bash
#
# Uploads a list of radio stations into an Onkyo receiver's web page
# Tested with a TX-NR509.
#
# Supply the list as "NAME=URL" lines on stdin.
#
# Copyright (c) 2011 Dominic Cleal <dominic@computerkb.co.uk>
# Released under the MIT licence.
RECEIVER=receiver.int.m0dlx.com
URL="${RECEIVER}/station.cgi?page"
upload() {
echo "Uploading page $((page + 1)) of radio stations"
curl -o /dev/null --data "@$form" "$URL=$page"
((page+=1))
printf "save.x=1&save.y=1&page=%s" $page > $form
}
urlencode() {
# Courtesy of http://andy.wordpress.com/2008/09/17/urlencode-in-bash-with-perl/
echo -n "$1" | perl -pe's/([^-_.~A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg'
}
form=$(mktemp --tmpdir onkyo.XXXX)
page=0
printf "save.x=1&save.y=1&page=%s" $page > $form
count=0
while IFS="=" read stname sturl; do
stname=$(urlencode "$stname")
sturl=$(urlencode "$sturl")
printf "&name%.2d=%s&url%.2d=%s" $count "$stname" $count "$sturl" >> $form
((count+=1))
if [ $count -eq 20 ]; then
upload
count=0
fi
done
if [ $count -gt 0 ]; then
upload
fi
rm -f $form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment