Created
March 29, 2012 08:38
-
-
Save beata/2235050 to your computer and use it in GitHub Desktop.
Bash script to search itunes radio channels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| until [ -z "$1" ]; do | |
| case $1 in | |
| -u | --with-url ) | |
| WITHURL=1 | |
| ;; | |
| *) | |
| if [ -z "$CATEGORY" ]; then | |
| CATEGORY=$1 | |
| elif [ -z "$STREAM" ]; then | |
| STREAM=$1 | |
| fi | |
| ;; | |
| esac | |
| shift | |
| done | |
| usage() | |
| { | |
| basename=`basename "$0"` | |
| echo "Usage: $basename [-u|--with-url] CATEGORY_NAME STREAM_NAME" | |
| } | |
| if [ -z "$CATEGORY" -o -z "$STREAM" ]; then | |
| echo "CATEGORY_NAME and STREAM_NAME are required" | |
| usage | |
| exit 1 | |
| fi | |
| if [ -z "$WITHURL" ]; then | |
| getinfo='<kb:\(station\|description\)>'; | |
| else | |
| getinfo='<kb:\(station\|description\|url\)>'; | |
| fi | |
| CATEGORYID=`curl --silent 'http://pri.kts-af.net/xml/index.xml?sid=09A05772824906D82E3679D21CB1158B&tuning_id=1' | grep -i "$CATEGORY" -A 1 | tail -n 1 | sed 's/<[^>]*>//g'` | |
| curl --silent "http://pri.kts-af.net/xml/index.xml?sid=09A05772824906D82E3679D21CB1158B&tuning_id=$CATEGORYID&show_field%5B%5D=description&show_field%5B%5D=long_description&show_field%5B%5D=num_users&show_field%5B%5D=max_users" | grep -i "$STREAM" -A 5 -B 1 | grep $getinfo | sed "s#<kb:station>#\\`echo -e '\n\r'`#g" | sed 's#<kb:[^>]*># #g' | sed 's#</kb:[^>]*>##g' | sed 's/\&/\&/g' | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment