Created
March 12, 2011 00:04
-
-
Save peta/866840 to your computer and use it in GitHub Desktop.
Tool for batch downloading FM4 podcasts
This file contains 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
#!/usr/bin/env bash | |
# Author: Peter Geil -- @pbyte | |
# Version: 0.1 | |
# Description: Tool for batch downloading <http://fm4.orf.at> podcasts. | |
DIRECTORY=$(cd `dirname $0` && pwd) | |
if [ $(($#)) -gt 0 ]; then | |
URL=$1 | |
else | |
URL="http://fm4.orf.at/radio/stories/audio" | |
fi | |
echo "Analyzing: '$URL'" | |
playlists=( $(curl -s "http://fm4.orf.at/radio/stories/audio" | grep "name=.flashVars." | sed 's|.*xmlUrl=\(http://[^&]*\.xspf\).*|\1|') ) | |
nPlaylists=${#playlists[@]} | |
echo "Found $nPlaylists playlists" | |
if [ $nPlaylists -gt 0 ]; then | |
echo "---------------------" | |
echo "Which playlist you want to download?" | |
for ((i=0; i < $nPlaylists ; i++)); do | |
echo " $(($i+1))) ${playlists[$i]}" | |
done | |
echo "Enter ordinal number:" | |
read choice | |
if [[ "$choice" =~ ^[0-9]+$ | |
&& $choice -gt 0 | |
&& $choice -le $nPlaylists ]] ; then | |
choice=${playlists[$(($choice-1))]} | |
else | |
exec >&2; echo "Invalid choice. Terminating"; exit 1 | |
fi | |
else | |
exit 0 | |
fi | |
# Fetch XSPF file and extract urls | |
podcasts=( $(curl -s "$choice" | grep '<location>' | sed 's|.*<location>\(.*tp://[^<]*\).*|\1|') ) | |
nPodcasts=${#podcasts[@]} | |
echo "---------------------" | |
echo "Playlist '$choice' contains $nPodcasts podcasts" | |
if [ $nPodcasts -gt 0 ]; then | |
plName="`basename $choice`" | |
if ! [ -d $plName ]; then | |
echo "Creating subdirectory '$plName'" | |
# Create subdirectory for files of sample playlist | |
mkdir "$plName" | |
fi | |
else | |
echo "Nothing to do. Terminating" | |
exit 0 | |
fi | |
# Download podcast files | |
cd $plName | |
for podcastFile in ${podcasts[@]} | |
do | |
if ! [ -f "`basename $podcastFile`" ]; then | |
# Assume podcast wasn't downloaded yet | |
echo "Downloading '$podcastFile'" | |
curl -O "$podcastFile" | |
echo "`date +[%Y-%m-%d]` Downloaded $podcastFile" >> log | |
else | |
echo "Skipping podcast file '$podcastFile' (does already exist)" | |
fi | |
done | |
echo "---------------------" | |
echo "Podcast download finished. Terminating" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment