Hack86.Grab Podcasts from the Command Line

Hack 86. Grab Podcasts from the Command Line

A simple shell script is all it takes to pull down your favorite podcasts from the command line.

While streaming audio on the Internet has been around for a number of years, one problem is that since it is a live stream, you have to tune in to the stream at a certain time or you miss the broadcast. [Hack #81] discusses one method for saving streaming broadcasts, but a number of people have come up with another solutionpodcasting. Podcasting is a way to publish files (most often audio files) on the Internet using RSS feeds. There are three basic steps to podcasting:

  1. A podcaster records a broadcast in some audio format and then makes it available on her web site.

  2. The podcast RSS feed gets updated with the link to the new content and people who have subscribed to the RSS feed then get the notification of the new content.

  3. Subscribers download the podcast and listen to it on their computers or portable music players.

There are a number of programs out there for various platforms that aggregate podcast feeds and keep track of and download new feeds when they appear. Many of them even synchronize the new feeds with portable audio players such as an iPod so you can listen to the broadcast at your leisure (this is where the "pod" in podcasting came from). Under Linux, one such program is Bashpodder.

Bashpodder is impressive in its pure simplicity. Bashpodder is comprised of a forty-or-so-line shell script, a small stylesheet, and a config file that simply contains links to RSS feeds you want to subscribe to. To install Bashpodder, download bashpodder.shell, parse_enclosure,xsl, and bp.conf files from the official site at http://linc.homeunix.org:8080/scripts/bashpodder and put them in a special directory (such as ~/bashpodder). Then make the bashpodder.shell script executable. Here are the commands necessary to set up Bashpodder:

 greenfly@moses:~/$ mkdir ~/bashpodder greenfly@moses:~/$ cd bashpodder greenfly@moses:~/bashpodder$ wget http://linc.homeunix.org:8080/scripts/ bashpodder/bashpodder.shell greenfly@moses:~/bashpodder$ wget http://linc.homeunix.org:8080/scripts/ bashpodder/parse_enclosure.xsl greenfly@moses:~/bashpodder$ wget http://linc.homeunix.org:8080/scripts/ bashpodder/bp.conf greenfly@moses:~/bashpodder$ chmod a+x bashpodder.shell 

The next step is to configure Bashpodder with the feeds you wish to subscribe to. Open bp.conf in a text editor and add the URL to your RSS feed to the file, one feed per line. By default bp.conf contains some sample feeds the Bashpodder author likes, so you can use those as examples.

After bp.conf is configured with your feeds, you are ready to grab the latest podcasts. Run the Bashpodder shell from the command line:

 greenfly@moses$ ~/bashpodder/bashpodder.shell grep: podcast.log: No such file or directory … 

The first time you run Bashpodder, it will basically download all of the podcasts linked to inside your config file, which might take some time. Don't worry about the grep: podcast.log: No such file or directory error. Bashpodder creates that file after the first run so it can keep track of what it has already downloaded. Again, since it is downloading every single file linked to in the feeds, it will take some time to complete. Bashpodder puts each of the files it grabs in a directory named after the current date so you can look inside that directory to keep track of the progress.

If you don't want to download every single item in a podcast the first time through, create your own podcast.log file and add direct links to each of the MP3s you want Bashpodder to ignore. Then run bashpodder.shell and it will skip over those files.

Since Bashpodder is just a shell script, it lends itself very well to running within a cron job. This way, you can synchronize your podcasts daily, weekly, or whenever you want. For example, to run Bashpodder every day at 4:30 A. M., edit your user's crontab (type crontab-e) and add the following line:

 03 4 * * * /home/username/bashpodder/bashpodder.shell 

Replace the above path with the path to your bashpodder.shell file.

The nice thing about the simplicity of Bashpodder is that with minimal shell scripting ability you can customize it to your needs. You could add a shell command to synchronize the downloaded files with your portable audio player, or you could change how it names the directory it stores the podcasts in, or any number of other things. The Bashpodder site contains some of the customizations other users have made already.

Linux Multimedia Hacks
Linux Multimedia Hacks
ISBN: 596100760
Year: 2005
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net