The Musical Gardener's Tools #3: The Kitchen Sync
One of the potential downsides of obtaining your music from a large number of mixed quality sources is that your collection will be overrun by crap if you don't aggressively cull the crap. Since I listen to music on at least 4 machines (my laptop, my work desktop, my home desktop and my iAudio M5 hard drive player) synchronisation could become nightmarish: If I delete something from my laptop and I sync with any of the other machines, I don't want the deleted crap to reappear, but I do want new stuff I downloaded to get transferred. The way I solved this is with a few scripts using the wonderful rsync and a bit of self-discipline:
syncing between computers
I have two scripts on my work desktop called hello.sh and goodbye.sh. The former I run every day when I come into the office in the morning and this synchronizes all music from my laptop onto my desktop, including new, changed or deleted files:
#! /bin/sh
rsync -avz --delete laptop:~/ogg/ ~/ogg
~/ogg/mp3blogs/update
./rm_empty
rsync -avz --delete ~/ogg/ laptop:~/ogg
- synchronize files from laptop to desktop
- download new files from selected mp3blogs to the desktop
- remove any empty directories under the ogg directory on the desktop
- synchronize files from desktop to laptop
#! /bin/sh
./rm_empty
rsync -avz --delete ~/ogg/ laptop:~/ogg
- remove any empty directories under the ogg directory on the desktop
- synchronize files from desktop to laptop
syncing between a computer and a music player
For this I wrote a little Python script, mostly because I like Python syntax much better than whatever shell script syntax (yeah, I'm new school), but it could be easily solved differently. The use case here is: all the music on any one of my computers will never fit on the puny 20GB my music player sports. That's ok, because this is only meant to hold the music I *know* I like, and to which I like to relax on the train to and from home. So the problem is we want to synchronize a subset of the music on (for instance) my desktop. I made a script that does this:
#!/usr/bin/env python
from os.path import isdir
from os import listdir, system
local = '/home/eric/ogg'
iaudio = '/media/IAUDIO/MUSIC'
localdirs = listdir(local)
iaudiodirs = listdir(iaudio)
for entry in iaudiodirs:
iaudio_path = iaudio + '/' + entry
local_path = local + '/' + entry
if isdir(iaudio_path):
if entry not in localdirs:
print "synching %s from iaudo to local" % iaudio_path
system('rsync --size-only --delete --delete-excluded \
--exclude-from= /home/eric/.rsync/exclude -avz \
--no-group %s/ %s' % (iaudio_path, local_path))
else:
print "synching %s from local to iaudo" % entry
system('rsync --size-only --delete --delete-excluded \
--exclude-from= /home/eric/.rsync/exclude -avz \
--no-group %s/ %s' % (local_path, iaudio_path))
No comments:
Post a Comment