Skip to content

Instantly share code, notes, and snippets.

@dstapp
Created January 1, 2016 16:35
Show Gist options
  • Save dstapp/5aae328bceac5e3b5c30 to your computer and use it in GitHub Desktop.
Save dstapp/5aae328bceac5e3b5c30 to your computer and use it in GitHub Desktop.
A bash script for automatically downloading new podcast episodes and pretty-printing new files. Works on Linux and BSD/OS X
#!/usr/bin/env bash
# The following script parses podcast feeds and downloads all podcast episodes listed in
# the feed if they don't exist within the target path. The target directory will be created
# if it does not exist.
[ -x "$(command -v wget)" ] || (echo "wget is not installed" && exit 1)
[ -x "$(command -v sed)" ] || (echo "sed is not installed" && exit 1)
[ -x "$(command -v xargs)" ] || (echo "xargs is not installed" && exit 1)
function download_files_from_feed {
[ -d $2 ] || mkdir -p $2
cd $2
wget -nc $(wget -q -O - $1 | sed -n 's/.*enclosure.*url="\([^"]*\)" .*/\1/p')
}
function echo_update_stats {
PODCAST_UPDATE_LIST=$(find $1 -ctime -1 -type f)
echo "All podcasts updated."
if [ -n "$PODCAST_UPDATE_LIST" ]
then
echo -e "\nNew episodes within the last 24 hours:"
echo $PODCAST_UPDATE_LIST | xargs basename | xargs printf "* %s\n"
else
echo "No new episodes are available."
fi
}
# Download audio files from podcast feeds.
# Feed subscriptions are exemplified below.
PODCAST_DIR=/storage0/podcasts
download_files_from_feed http://logbuch-netzpolitik.de/feed/m4a $PODCAST_DIR/LogbuchNetzpolitik
download_files_from_feed http://freakshow.fm/feed/m4a $PODCAST_DIR/Freakshow
download_files_from_feed http://cre.fm/feed/m4a $PODCAST_DIR/CRE
# This one's sending notifications to my phone but might not be useful for you
#/root/send_notification.sh "$(echo_update_stats $PODCAST_DIR)"
echo_update_stats $PODCAST_DIR
@xthursdayx
Copy link

Thanks for this awesome script! Just a question though. I'm trying to use this to download NPR's TinyDeskConcerts video feed. It works, but the filenames and file types are all messed up (for example, the file types are mp4?orgId=1&d=894&p=510292&story=485232774&t=podcast&e=485232774&ft=pod&f=510292)

Any idea how I can fix this? The feed location is: http://www.npr.org/rss/podcast.php?id=510292

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment