Simple Media Player Synchronization

December 4, 2021 - cat | grep

A few years ago I wrote up a simple bash script to automatically sync my portable music player1 with the music collection on my desktop. Here is the script as of the date of writing. The script's operation is pretty simple. First, an initial rsync is performed using the --dry-run option. I use this mostly as a sanity check to make sure

  1. My player is actually mounted.
  2. The script isn't about to (for whatever reason) overwrite the entire contents of my player.
If everything looks okay, simply say yes2 to the prompt, and all music files that are either new or have been updated will begin to transfer over. As a bonus, the script will also auto-eject the player if you fill out the partition-uuid and disk-uuid fields. You can use blkid to help you find these values.

I'm an avid user of last.fm. Lucky for me, Rockbox has the ability to keep track of all of my listening. I've hopped between a number of programs that are able to scrobble the log file generated by Rockbox. Currently I am using laspyt parse Rockbox's log file and upload my listens to last.fm.


#!/bin/bash

# top level media player path
IPODPATH=""
# media player's music folder
IPODMUSICPATH=""
# music library on computer
LIBRARY=""

echo
echo "Looking for changes..."
echo

rsync --dry-run --progress --update --delete -r $LIBRARY $IPODMUSICPATH


read -p "Proceed with sync? [Y/n] " userIn 
userIn=${userIn:-y}


if [ "$userIn" = "n" ]
then
    exit 0
else
    echo "Syncing Music..."
    echo
    rsync --progress --update --delete -r $LIBRARY $IPODMUSICPATH
    echo

    echo "Scrobbling Tracks..."
    echo
    laspyt.py -b -c -f $IPODPATH/.scrobbler.log
    echo

    echo "Unmounting..."
    echo
    udisksctl unmount -b /dev/disk/by-partuuid/[partition-uuid] && udisksctl power-off -b /dev/disk/by-uuid/[disk-uuid]
fi

1. An iPod Video 5.5 with an iFlash-Quad running Rockbox.

2. You can bypass this prompt by piping yes into the script.