Sunday, 13 April 2014

Scheduled RSS Podcast Downloader for Raspberry Pi



I have a number of RSS podcasts that I frequently listen to. I can listen to them on a number of devices like my phone or tablet. My requirement was a setup where during the night the podcasts would be downloaded to the Raspberry Pi so I could then quickly download them to my phone or tablet.

I looked at a number of solutions but the one I liked the best was BashPodder which essentially is a small bash script that download the file. It conforms to the KISS rule (Keep It Simple Stupid). Its easy to set-up, configure and set a cron job to run.

Set-up

  • There are three files :
    • bashpodder.shell - The main program
    • parse_enclosure.xsl - xsl style sheet
    • bp.conf - podcast config list
  • Once you download these to your Pi you can edit the 'bp.conf' file for the RSS feeds you want. They are a number of example podcasts in this file already but you can edit as necessary. 
  • I removed all and added two e.g.

$ cat bp.conf    
http://www.howstuffworks.com/podcasts/stuff-you-missed-in-history-class.rss
http://feeds.feedburner.com/JupiterBroadcastingVideos


  • After that its simple to run the downloader :

$ cd /data/podcasts/bashpodder/ && ./bashpodder.shell

  • The podcats will be downloaded to a date stamped folder in the directory the script was run :

$ ls -lh 2013-10-20/
total 206M
-rw-r--r-- 1 cwishaw users 206M Oct 14 12:23 cr-0071-432p.mp4

  • The name of the folder can be changed if required in 'bashpodder.shell'
  • Note - The first time you run the ./bashpodder.shell it will download all the podcasts which may be massive. One way to avoid this is to update the 'podcast.log' file which is a list of the files that have been downloaded by BashPodder.
$ tail -n 2 podcast.log
http://www.podtrac.com/pts/redirect.mp3/podcasts.howstuffworks.com/hsw/podcasts/symhc/2013-10-14-symhc-elsa-lanchester-1.mp3
http://www.podtrac.com/pts/redirect.mp3/podcasts.howstuffworks.com/hsw/podcasts/symhc/2013-10-16-symhc-elsa-lanchester-2.mp3



  • To create the list you can use Python. For example on Arch :
$ pacman -S python-pip
$ sudo pip install feedparser
  • Run wget to obtain the RSS file e.g.
$ wget http://www.howstuffworks.com/podcasts/stuff-you-missed-in-history-class.rss

  • Create a python script :

#!/usr/bin/python
import feedparser

RSSFEED = '~/tmp/stuff-you-missed-in-history-class.rss'
OUTPUTFILE = '~/tmp/RSSFeedParser.tmp'

## End of Configuration

d = feedparser.parse(RSSFEED)

text_file = open (OUTPUTFILE, "w")

for post in d.entries:
    #text_file.write(post.title + ": " + post.link + "\n")
    text_file.write(post.link + "\n")
   
text_file.close()

text_file = open (OUTPUTFILE, "r")
print (text_file.read())
text_file.close()



  • You can then append the file :

$ cat RSSFeedParser.tmp >> podcast.log 

  • Final Task is to set up a cron job to run at 2 AM every morning :
$ crontab -e

00 02 * * * cd /data/podcasts/bashpodder/ && ./bashpodder.shell > /dev/null 2>&1 &

  • On Android I use an app called 'Turbo Client' to download the podcasts locally via SFTP.

1 comment:

  1. Awesome.

    I have been looking for something similar to this, but in a contained player.

    ReplyDelete