Tuesday, July 8, 2014

Bash Scripting - NPR Podcast downloader

Stuff to listen to on walk from South Station to work..


arrayNames=(AllSongs AlmostYesterday AtlandsSounds AustinMusic ByteMarks CarTalk ClassicsForKids DigitalAge Engines Environmental Freakonomics FutureTense Kinsey MoneyTalking MoneyTalks Music OnPoint PlanetMoney Tech Ted TinyDesk WorldCafe WaitWait)

arrayIds=(4819413 15167326 19099072 4819408 193172758 9911203 14946301 7494440 5183222 4985907 148603480 122980869 18659325 161302666 172886153 4819384 5183210 94411890 4819382 151446218 187050159 5421673 5183214)

printf "%s\n" "${arrayNames[@]}"

printf "%s\n" "${arrayIds[@]}"

total1=${#arrayNames[*]}
total2=${#arrayIds[*]}
if [ "$total1" -ne "$total2" ]
then
    printf "array lengths not equal. BYE!"
    exit 1
fi


for (( i=0; i<=$(( $total2 -1 )); i++ ))
do
    echo $i
    one=$(curl http://www.npr.org/rss/podcast/podcast_detail.php?siteId=${arrayIds[$i]} | grep downloadmp3 | cut -d\" -f2 )
    echo $one
    two=${arrayNames[$i]}$(date +%Y%m%d)
    echo $two
    curl -L $one > $two.mp3
    echo
    date
done

No comments:

Post a Comment