Automatic podcast to player copier

When I plug my mobile phone or mp3 player into my PC the newest editions of the podcasts I subscribe to are transfered. No mousing and clicking anymore, everything is handled automatically by the computer.

I subscribe to podcasts using the podget bash script. This script is run by cron/anacron when I turn on the computer in the morning. Podget downloads any new podcasts. When I plug a player into the computer a udev rule mounts the player file system and transfers the new podcasts. This task is performed by pod2player, a small bash program of mine.

Podget setup

After installing Podget you will find a new directory ~/.podget with two files:  podgetrc and serverlist. The podget setup is specified in podgetrc. For my use I only want to download the latest edition and don’t want to keep it for too long, if I plug in the player, say at least once a week, the files may be deleted after seven days. For that I apply these settings to podgetrc:

most_recent=1
force=0
cleanup=1
cleanup_days=7

If you have problems downloading certain podcasts you may try to enable filters in this configuration file.

The podcast subscriptions are given in serverlist one line for each station in a url-genre-name tuple, for example:

http://downloads.bbc.co.uk/podcasts/radio/newspod/rss.xml pod  bbc_news
http://www.guardian.co.uk/science/series/science/podcast.xml pod  science
http://www.nature.com/nature/podcast/rss/nature.xml pod  nature

The downloaded mp3 files will end up in a genre/name directory e.g. pod/science. By using pod as the genre for all stations all files will be found below pod.

udev rule

Now that podget keeps the last podcasts in the pod directory we need a udev rule that triggers when the player is plugged in. In the /etc/udev/rules.d directory I have the rule file pod2player.rule with one line:

ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/usr/local/bin/pod2player %k"

which will run pod2player when a device satisfying the expression sd[b-z][0-9] is discovered, e.g. sdb1. This rule excludes /dev/sda devices to prevent pod2player to execute for all hard drive partitions when I boot my computer.

The %k represents the device name, e.g. sdb1, which will appear as the first argument of pod2player. The above rule will trigger whenever a block device is discovered. It is up to pod2player to determine if the device is a player we want to transfer files to.

pod2player

Pod2player is a bash script which main purposes are to determine if a target player has been plugged in and then, if the available podcast files are newer than those on the player, to transfer the files. The main part is:

 
MEDIAPATH='/media/player/' 
FOLDER='pod/' 

/bin/mkdir -p $MEDIAPATH   # create the mount point
dev="/dev/"$1              # $1 from udev rule
/bin/mount $dev $MEDIAPATH # mount the device
if [ -d $MEDIAPATH$FOLDER ]; then 
         copyfiles  
         /bin/sync& 
         pid=$!
         wait $pid  
         ...
fi

This code creates a mount point /media/player and mounts the device. If the directory /media/player/pod is found the podcasts are copied over. So every player I want to receive podcasts must have a pod top directory. One may choose other criteria for the target device acceptance, e.g. vendor/product ID or volume name. Such environment variables are inherited from the udev system.

If pod2player is used by more than one user the player volume label may be used to select which home directory to copy files from. Player volume label can be set by mlabel from the mtools package. As an example, to set the label to MY_NOKIA execute

sudo mlabel -i /dev/sdb1  ::MY_NOKIA

while the phone is plugged in but not mounted. Use dmesg to see which device is actually in use, can be something other than sdb1.

Only one edition of each podcast will ever exist on the player. This allows for simpler and more VFAT compatible file names than those used on the PC. I use a name derived from the name given in the serverlist file, e.g. bbc_news.mp3.

After the copyfiles function initiates file transfers sync is executed and we wait for sync to complete, which indicates that all files have been copied. Following this the user is notified and the device will be unmounted and the mount point removed, see the complete source code.

podget and pod2player will run as root and will access configuration files and podcast files under /root. The user is notified by sound and a pop up message. To allow the root user access to do this you must run xhost si:localuser:root, perhaps include this in your .bashrc.

The mp3 player
The simplest players make all files on the player available for playing, other players will only play files registered in an embedded data base. I use a Nokia 6700 mobile phone with pod2player. This phone asks me if I want to update the data base after a new file has been transfered. I can also activate an update menu item to do this manually. Since all editions of a podcast station use the same file name this update is only needed when a new station is subscribed to.

Other players, like some from Apple and Phillips, use data bases that must be updated by the program that transfer the files. This is not included in pod2player, but information is available about new stations so an appropriate program may be called after the files have been copied.

0 Responses to “Automatic podcast to player copier”


  • No Comments

Leave a Reply