February 5, 2007

CLI Magic: Bring in podcasts with BashPodder

Author: Michael Stutz

Podcatchers, the programs that download and aggregate your favorite podcasts, are popular on all platforms. Many are available for Linux, including iPodder and Podget. But the truth is that you don't need all that fancy stuff to harvest podcasts with Linux. BashPodder is a quick CLI-based GPLed podcatching client. It's one of the oldest ones out there, and may still be the best. It's hands-on, no-frills -- and a perfect example of how a few command-line statements can work together to do a powerful job.

Written by Linc Fessenden of The Linux Link Tech Show podcast, BashPodder parses the URLs of any podcast feeds you give it and saves the podcast files to dated directories. Because of its simplicity, it works on every Linux distribution, and it's cross-platform, too -- Fessenden reports that users have gotten it to work on AIX, BSD, Mac OS X, and Solaris, among others.

You might say, "Well, I'm pretty sure I can do that with wget" -- and you're right. That's what BashPodder uses behind the scenes. It's actually a very simple program itself -- strip away the few dozen comment lines and you have just 20 lines of Bash code, with wget smack in the center. An experienced shell programmer could write and debug an equivalent in an afternoon.

But there's no need to, now that Fessenden's already done the work. And you can use it to do some pretty useful stuff.

Getting started

BashPodder is very much a DIY project; there's no man page or documentation of any kind. There's isn't even a formal tar.gz source file. It requires that you have the bash shell, sed, and wget, which are all universal on Linux, plus xsltproc, a tool that applies XSLT stylesheets to XML documents from the command line.

First make a main directory where you want to keep your podcasts, and then make it the current directory. I suggest ~/podcasts:

~$ mkdir podcasts
~$ cd podcasts

Then use wget to download the three files that comprise the heart and guts of BashPodder:

~/podcasts$ wget http://linc.homeunix.org:8080/scripts/bashpodder/bashpodder.shell
~/podcasts$ wget http://linc.homeunix.org:8080/scripts/bashpodder/parse_enclosure.xsl
~/podcasts$ wget http://linc.homeunix.org:8080/scripts/bashpodder/bp.conf

The file bashpodder.shell is the BashPodder shell script itself; parse_enclosure.xsl is the stylesheet used on the actual XML feeds, and bp.conf is the configuration file that contains your list of podcasts to catch, one to a line.

While bp.conf comes preconfigured with a dozen-odd popular Linux podcasts, you can edit this file in a text editor, adding or deleting feeds. If you don't have any favorite podcasts yet, you can find some to try from any number of sites, including podcast.net and Podcast Alley.

But note this warning: if you have a slow connection or you're hard up for disk space, you might want to edit the list down to only one or two to start with, because some podcasters make a lot of archive files available in their feeds, so the first time you run BashPodder to download the feeds you're going to be pulling in a lot of data. If you only want to try one -- maybe the Ogg feed for Fessenden's show -- your bp.conf file should contain only one line:


Now you should make the bashpodder.shell script executable:

~/podcasts$ chmod 755 bashpodder.shell

Finally, you're ready to run it:

~/podcasts$ ./bashpodder.shell

Like many classic CLI tools, bashpodder.shell doesn't "make any noise" -- you won't see any output on the screen unless something goes awry. The first time you run it, it retrieves everything in the archives of all the feeds specified in bp.conf, and saves them all to a subdirectory named with the current date in the format of YYYY-MM-DD. From then on, whenever you run it, all the new feeds that you haven't caught yet are downloaded and stored in a new subdirectory with that same date format.

When it's done running, check the new subdirectory it created for the presence of new podcasts and a podcast.m3u playlist file:

~/podcasts$ ls
2007-02-02        bp.conf        parse_enclosure.xsl
bashpodder.shell  podcast.log
~/podcasts$ ls 2007-02-02

You can play your podcasts with your favorite audio or media player, such as Amarok, Exaile, or XMMS, by giving their names as arguments. For example, to play all of the day's new podcasts, using a command like:

$ xmms ~/podcasts/2007-02-02/*

BashPodder also keeps a running log of downloaded podcasts in a file called podcasts.log. If a download is interrupted, you can get the list of podcasts that were in progress from the temp.log file, which is deleted at the end of normal execution.

Whenever you want to fetch the latest podcasts from the feeds you've selected, just run bashpodder.shell again. If you run it and there's nothing new to download, it just exits. But if you run it again the next day, and there are new podcasts in your feeds, they're saved in a new directory with that day's date:

~/podcasts$ bashpodder.shell
~/podcasts$ ls
2007-02-02          2007-02-03        bp.conf
parse_enclosure.xsl bashpodder.shell  podcast.log

Automatic podcast delivery

If you want to have BashPodder check your feeds and download new podcasts every day, you can easily automate it by scheduling a cron job.

To have it run automatically every weekday morning, add the following line to your crontab file:

15 07 * * 1-5 ~/podcasts/bashpodder.shell

This will run BashPodder at 7:15 in the morning on weekdays.

If you don't already have a personal crontab file, make a new one by running crontab -e and then typing the above line in the new file; when you save it, your crontab should be updated.

You can check to make sure that the crontab has been updated with your new job by running the tool of the same name:

$ crontab -l
15 07 * * 1-5 ~/podcasts/bashpodder.shell

Beyond BashPodder

This is all just basic BashPodder, which is more than adequate for keeping up with your favorite podcasts, but for the adventurous, there are all kinds of BashPodder modifications and improvements to try. It's practically become a hobby for Linux podcast enthusiasts to write their own BashPodder extensions. Fessenden has published a big directory of user contributions, including modified versions with useful options such as commented URL support and support for BitTorrent and a "first-only" flag to only download the most recent podcast.

A number of entirely new podcatchers have been written as outright replacements for BashPodder, including the Perl-based mpodder and GoldenPod, so if BashPodder doesn't do exactly what you need it to, you might want to check out these derivatives. Kamiware BashPodder, for instance, boasts "even functions no other podcast client has."

And finally, if you've had enough of the CLI, you can install KPodder, which is a Python-based KDE front end for BashPodder.

- Write for us - and get paid! -

Click Here!