iPhone and Linux

Thursday, October 8, 2009

iPhone command line podacatcher

I've been using RSSPlayer to download and listen to podcasts on my iPhone, but it's started to get buggy and misses a lot of new podcast episodes.

I started looking for a simple Linux podcatcher just to check the feeds and tell if there are any new episodes. I stumbled across BashPodder, which is an excellent command line podcatcher, but it downloaded all the episodes and I only wanted to get a list of what was available.

I started looking at the code and realized it was extracting links with xsltproc. I'd never heard of that so checked into it. Basically, it takes an xsl stylesheet and filters things though it. BashPodder uses a file named parse_enclosure.xsl which is available on their website.

I realized I could use that to write a simple shell script to use on the iPhone to notify myself of new podcasts available. Then I realized I could use it to just download the podcasts instead of simply notifying me of them. The podcasts can then be listened to with iFile (from Cydia). All you need on the phone is MobileTerminal, awk, wget (any hacker should already have those), libxslt (I couldn't find it in Cydia but found it here), this script and parse_enclosure.xsl from the BashPodder project.
#! /bin/sh

# This requires the parse_enclosure.xsl file from bashpodder

function fetch {
echo "Checking $2"
wget -q -O .$2 $1
cat .$2 | xsltproc ./parse_enclosure.xsl - > .$2b
if
diff .$2b .$2a | grep \< > /dev/null
then
echo "$2" >> new
diff .$2b .$2a | awk '{ print $2 }' | sed /^$/d >> new
echo >> new
fi
mv .$2b .$2a
rm .$2
}
# Was that enough 2's for you? Sorry, that's
# the downside to using function variables.


# Add your podcast links below and remove the #
# The format must be "fetch link nickname"
# fetch is the name of the function, it will only
# run the function on lines beginning with the word fetch
# The nickname is whatever one-word nickname you want to
# give a podcast. Don't use special characters.
#################FEEDLIST###################
#fetch http://www.site1.com/feed.xml nickname
#fetch http://www.site2.com/feed.xml nickname2
# ...etc
###########################################


if
ls | grep new
then

# If you only want to be
# notified of new podcasts
# and not download them,
# change this line to:
# cat new

cat new | grep http > get; wget -i get; rm get

rm new
else
echo "Sorry, no nothing new"
fi

Blog Archive