Radio Shows As Podcasts: Part 1 – The Set Up

I prefer to listen to radio shows and plays as podcasts than as normal mp3s or items in my library. There are various ways to obtain BBC radio shows as mp3 files, and to set the tags as needed to be added as podcasts in iTunes, which I will leave as an exercise for the reader.

Last time I put this together, I had my Raspberry Pi download the shows. I then wrote a python script to connect to the Pi, check the tags on the file and copy them across to my laptop into the “Automatically add to iTunes” folder. This script had to run each night, and (due to the slow speed of my home network) would only work if I was in a particular part of the house and had the network share mounted. It also didn’t manage the files on the Raspberry Pi.

Rather than attempt to update this script, I’ve taken the far more elegant approach of turning my Raspberry Pi into a podcast server for my home network. This approach is incredibly simple, and should require far less work on my part to manage the files and ensure the tags are all as they should be.

There are 4 basic steps to this approach:

  1. Set up a minimal web server on the Raspberry Pi
  2. Obtain your radio show as a podcast, with the programme information in an xml file.
  3. Generate the XML for the podcast feed.
  4. Subscribe in iTunes

1. Set up a minimal web server

I chose to run the minimal web server lighttp, which was as straightforward as it comes. Simply run

sudo apt-get install lighttp

to install and start the web server. The server directory is found in /var/www/

Obtain your radio show

This is left as an exercise for the reader.

Generate the XML for the podcast feed

I will go through this step in Part 2.

For initial set up and testing, I simply copied XML from an existing podcast feed, e.g. from The Guardian’s Rugby World Cup Podcast.

Subscribe in iTunes

Subscribing in iTunes is as simple as selecting File > Subscribe to Podcast… and entering the internal url to the XML file. iTunes should then automatically start downloading the podcast from the Raspberry Pi, as per your default podcast settings.

Notes on Set Up

I had a few problems when initially setting this up. First, I have the podcast files on an external disk, rather than the /var/www/ folder, which is on the Raspberry Pi SD card. I simply created a symbolic link within the /var/www/ folder pointing to where I store the podcasts to solve this problem.

Second, and the most frustrating problem, was that I could not get iTunes to download the podcast files using a link in the <encode url="…"> XML tag. I could point my browser to the file, e.g. to 192.168.1.84/podcast.mp3, and it would play. So why wasn’t it downloading through iTunes? Well, it turns out that iTunes can only resolve the address of the podcast file if http:// is included at the start of the address in the <encode> tag.

A minor, third, problem, is that iTunes will not download the file if the length property of the <encode> tag is wrong.

Next: Part 2, where I will go through writing a Python script to automatically generate the XML for the podcast feed. This will involving checking when a new podcast is created in a watched folder and scraping its XML file for the relevant information.

Leave a comment

Raspberry Pi – Update

Just a quick update to my Raspberry Pi set up.

The bug in mounting drives with the Raspberry Pi 2 required the work around outlined in the last post: code was added to rc.local that caused a wait of 30 seconds before the sudo mount -a command is run. If one has a daemon set to run on start up that requires either access to files on the mounted disk, or creates files on the mounted disks, problems can arise. For instance, if the daemon creates a file or directory in the mount directory before the mount command is executed, the mount command will fail complaining that the mount directory is non-empty.

In order to solve this problem, I looked for a way to modify the daemon init.d script to check if the relevant disks were mounted. I succeeded in finding the following code on the Raspbian part of Stack Exchange, which was easy enough to modify for my needs.

log_daemon_msg "Checking if shares are mounted" "$NAME"
count=0
while [ ! -f /home/pi/nas/public/Downloads/check.txt ]
do
  log_daemon_msg "Waiting 30 seconds to allow for mounting" "$NAME"
  sleep 30
  count=$((count+1))
  if [ $count -eq 10 ]; then
    log_daemon_msg "Giving up after 10 retries. Please check network and mounts" "$NAME"
    exit 1
  fi
done
Leave a comment

Raspberry Pi, & Multimedia PCs

I’ve just got my hands on a Raspberry Pi 2, to go along with my A model. After having a lot of problems running RaspBMC, Kodi and OSMC as a media centre, I’ve decided to upgrade to the Pi 2 and run Plex, making use of the htpcguides. First I installed Minibian. This is a very minimal version of Raspbian. It doesn’t even come with nano! I didn’t install the wireless firmware, as I have chosen to plug my Pi into my router.[1] I also didn’t install a GUI for Minibian; I’ll only be interacting with the Pi through ssh sessions, using it completely headless.

On my first attempt, I tried to run

apt-get upgrade && apt-get update

before the step

apt-get install nano sudo rpi-update raspi-config usbutils dosfstools -y

This, unfortunately, lead to raspberrypi-bootloader_1.20150923-1_armhf.deb failing to be upgraded, which prevented apt-get from installing anything, and meant that a reboot lead to Minibian not being loaded. A quick re-flash of the SD card, and a proper following of the steps went far smoother. Lesson learnt: don’t think you know what you’re doing with upgrades and updates on a slightly different version of Linux than you’re used to.

After getting Minibian running, I followed the guide for installing Plex. Being from the UK, I first attempted to install Plex using  the local en_GB.utf8 rather than en_US.utf8. I managed to update libc6 to version 2.19 manually, and followed Method 1 to install Plex Media server by using a repository.

Before going any further, I also set up password-less access to the Pi, using the official documentation. This fails because Minibian doesn’t have either a .ssh folder, nor an authorised_keys file in that folder. A quick look at this Ras Pi TV guide showed that the easy and obvious solution is to simply log into the Pi and make them (making sure they’re owned by the user you’re wanting to log in as without passwords). Side note: I created the authorized_keys file with the command

touch .ssh/authorized_keys

This is a command I’ve seen used, but was never quite sure what it did. Now I know. After making this file, the command to copy the contents of the public key on my computer to the authorized_keys file on the Pi went through successfully, and I could log in without entering my password.

The last thing I needed to do was to alter the fstab to auto-mount my external drive. Although I thought I already knew how to do this from my previous dealings with my first Raspberry Pi and RaspBMC/Kodi, I found the htcguides guide on setting disks to auto-mount to be a great resource on how to find all the useful information (UUID, file system type, etc.). More importantly, the end of the guide included an explanation that there is a bug on the Raspberry Pi 2 that messes up auto-mounting, and outlines two ways to fix this. First, edit the /boot/cmdline.txt file to add a delay. Unfortunately this made no difference, so I had to apply he second fix, adding the command[2]

sudo mount -a

to the script /etc/rc.local. This, however, also did nothing. A quick google search later, and I found this discussion on the Plex forums, which finally allowed me to solve the auto-mounting issue by amending /etc/rc.local to read as follows:

sleep 30

sudo mount -a

exit 0

Edit: Just a quick update. During the installation of the Plex media server, the HTPC guide gets you to pin apt sources, namely the Jessie repositories, when upgrading libc6. This can cause issues installing packages, as noted in the guide. I encountered this problem rather quickly when attempting to install the python-dev package. In order to install this package, I had to use the -t flag when installing it. That is:

sudo apt-get install -t jessie package name

The -t flag for apt-get install alters the pin status for the declared resource.[3]

[1] Possibly the most important step to editing the fstab is to ensure you run the sudo mount -a command after editing the fstab, to make sure that you’ve not broken anything before rebooting! A broken fstab can prevent the disk with the root file system on from mounting properly. The only solutions to a broken fstab being to mount the drive on another computer and edit the fstab from there, or to restore form a backup

[2] I also have my TV wired into the network. The wireless card broke a year or two ago, for no real reason. Samsung wouldn’t help me out, but Amazon did offer me a partial refund due to the Sales of Goods Act, which now seems to have been replaced by the Consumer Rights Act.

[3] See the manual for more information.

Leave a comment