Google Reader + Podcasts + MP3Player == GReaderSync.pl

Google Reader is great, it lets you keep up on your feeds from anywhere - your phone, your MAC, your PC, and on and on. Podcasts are great too. Free education and entertainment abound. Most podcasts can be subscribed to via RSS. Google Reader is great for keeping up on the latest podcasts, but the interface sucks and I prefer to listen to podcasts on my MP3 player. I needed a good way to integrate Google Reader and my MP3 player. GReaderSync.pl is the result.

GReaderSync.pl serves two functions:

  • To download podcasts tagged with a user-configurable term to your PC, more than likely via a cron job
  • Sync your GReaderSync.pl downloads to your MP3 player automatically upon connection.


Sample Workflow

  • I'm bored, reading Google Reader on my phone. I see that The Linux Link Tech Show guys have put up a new podcast. Cool! I tag it with the term 'worklaptop', and go about my business.
  • My work laptop fires off GReaderSync.pl via cron. Using the excellent WebService::Google::Reader perl module, it logs into my Reader account, and sees that I have a new entry tagged with 'worklaptop'. It parses the entry looking for a link to the podcast itself, and downloads the podcast to my ~/podcasts directory. Once successfully downloaded, it removes the 'worklaptop' tag from Google Reader.
  • The next time I plug my mp3 player into my work laptop, it does a sync, copying the latest episode of TLLTS to my MP3 player - no intervention needed.


Download

Download GReaderSync.pl, copy it to /usr/local/bin, and mark it as executable:

wget http://www.sysadminsjourney.com/code/GReaderSync.pl
sudo cp GReaderSync.pl /usr/local/bin/
sudo chown 755 /usr/local/bin/


Installation and Setup

  • Install Prerequisites
    I have no Windows machines to play with, but I'm guessing the script won't work there. You need a few perl libraries installed. On Ubuntu, do the following:
    sudo apt-get install libxml-atom-perl libcrypt-ssleay-perl \
    libjson-any-perl libclass-accessor-perl
    
    sudo perl -MCPAN -e 'install WebService::Google::Reader'
    

    If you've never used CPAN before, you'll have to answer a few questions, 99% of which the defaults will be just fine.

  • Google Reader Setup
    Log into Google Reader, and tag some of your podcast entries with a custom tag - I use the hostname of the PC that will be doing the downloading. It doesn't matter what you use, only that you remember what you used. If you want a feed to test with, I suggest TLLTS's: http://www.thelinuxlink.net/tllts/tllts_ogg.rss
  • Configure GReaderSync.pl
    First, run GReaderSync.pl passing it in your username and password to Google Reader. GReaderSync.pl will cache your credentials in plain text, but in a file readable only by you. It will use SSL to communicate those credentials to Google.
    /usr/local/bin/GReaderSync.pl --user-id=mygoogleuserid --password=mygooglepassord
    

    This will cache your username and password, as well as create a sample config file for you at ~/.GReaderSync/config. Open that file in a text editor. The file is self-documented, but make sure you set 'podcast_dir' to wherever you want your podcasts stored, and set 'tags' to the tag you used in Step 1.

  • Test the downloading functionality of GReaderSync.pl
    /usr/local/bin/GReaderSync.pl --verbose
    

    This will download all the podcasts linked to from the Reader entries you previously tagged. Once it downloads the podcast, the script removes the tag from Google Reader, so it won't download it again unless you retag the entry.

    Have a look in your podcasts dir, you should see the file(s) there now.

  • Configure UDEV for automatic syncing to your MP3 Player
    You need to determine the model name of your player. If your player gets automatically mounted to /media/NAME OF PLAYER, then your model is 'NAME OF
    PLAYER
    '. Otherwise, follow this howto and use the value from ATTRS{model}.

    Once you have the model, then run the following to have the script generate the contents of the rule for you. DO NOT RUN THIS AS ROOT, RUN IT AS THE USER THAT WILL BE RUNNING THE SYNC!!!

    /usr/local/bin/GReaderSync.pl --make-rule='NAME OF PLAYER'
    

    Now take the output, and put it in a udev rule (you do have to be root to do this). As the output says, I recommend /etc/udev/rules.d/50-mp3player-sync.rules.

  • Test the sync
    At this point, you should have podcasts on your PC, so go ahead and plug the MP3 player in and with any luck at all you will end up with a sync. There is a logfile created at ~/.GReaderSync/player_sync.log.
  • Setup your crontab
    Fire off 'crontab -e', and add a job. Something like this should do nicely:
    0 */2 * * * /usr/local/bin/GReaderSync.pl

    This runs the sync once every two hours.

  • Enjoy!

Notes

I honestly didn't forsee releasing this script to the world, but it worked so well for me that I figured others might use it as well. The whole thing was hacked together in an afternoon, so I'm sure there's bugs and missing features everywhere. If you find any, please leave a comment and let me know about it!

Comments

[...] Google Reader + Podcasts + MP3Player == GReaderSync.pl [...]

Add new comment

Subscribe to SysAdmin's Journey RSS