koldfront

Transferring podcasts automatically #podcast

I found that I often went through the same ritual:

I wonder how people do this seamlessly.

The first thing I did, quite a while ago, was to avoid the "Run hpodder" step.

I set up downloading podcasts - with hpodder to ~/sound/podcasts/ - to happen automatically when my desktop machine is booted:

 @reboot sleep 60s; (/usr/bin/hpodder > /dev/null)

And at regular times during the day, sort of before I expect to plug in my phone:

 0 17,18,22 * * * /usr/bin/hpodder > /dev/null

Now today I got annoyed about the remaining two needlessly manual steps:

What to do... Hm, first I created a script that looks on the harddisk to see if there are any podcasts waiting to be moved to the phone. If there are, it checks to see if the phone happens to be connected, and if so, the podcasts are transferred and the playlist is updated.

First step then is to have that run after each invocation of hpodder. Easily done; have cron call run_hpodder which in turn just runs hpodder and then transfer_podcasts.

Fine, now every time the machine has fetched podcasts it checks for phone presence and moves them over.

But that only gives any benefit if the phone happens to be connected at one of those times...

If I could run transfer_podcasts when the phone is connected, then the combination would solve the problem.

The Gnome System → Preferences → Removable Drives and Media-thing allows you to configure programs to run when certain devices appear, but - alas - not when a new disk appears (which is what the phone looks like).

Enter incron - just adding a IN_CREATE watch on /media/ and then running transfer_podcasts ought to do the trick:

 /media/ IN_CREATE /home/asjo/bin/transfer_podcasts

Hm. It does indeed run when a new folder appears in /media/, but the folder is created and then the phone is mounted - enough time for transfer_podcasts to win the race and not see the destination. Meh.

Okay, the ugly solution: add --sleep 2 to transfer_podcasts, so it'll just wait a little bit and hopefully avoid the race condition.

Et voilà.

Add comment?

Title:

Name:

Email (won't be displayed online):

Text:

0.0128 s
webcustodian@koldfront.dk