Sync iTunes music & playlists with Synology Diskstation

I use Synology’s DiskStation as my central media server which streams via UPnP to my media renderer (T+A E-Series music player) and Sonos. Read on how I keep playlists and songs in sync between my iTunes on Mac and my NAS.

As described in my previous posts I use rsync to mirror all files on my laptop to my NAS. Please do the steps described there first. Please also make sure first to have done all steps the enable SSH access without password in this post. Then, the simple command for keeping music in sync is

/usr/local/bin/rsync -rlptD –iconv=UTF8-MAC,UTF-8 -e ssh –delete –progress –exclude ‘?eaDir’ /Users/USERNAME/Music/ root@’/volume1/music/Backup/’ 

In order to make the Synology NAS recognize all playlists, please install Eric Daugherty’s iTunes Export java tool. I moved the java files into a subfolder Applications/Multimedia. Now the code

rm -r /tmp/playlists
mkdir /tmp/playlists

java -jar /Applications/Multimedia/iTunesExportScala-2.2.2/itunesexport.jar -outputDir=/tmp/playlists/ -includeBuiltInPlaylists  -fileTypes=ALL

for x in /tmp/playlists/*.m3u do
iconv -f UTF8-MAC -t UTF8 “$x” > “$x”.utf8 rm “$x”

sed -e “s/\/Users\/USERNAME\/Music/\/volume1\/music\/Backup/g” “$x”.utf8 > “$x”
rm “$x”.utf8

For whatever reason Eric’s tool does not replace the path as it should thus I had to add an additional line with the sed command. Thank you also to the posters at Synology forum.

Unfortunately, the Synology DiskStation does not recognize new files added via rsync for its media index. And re-indexing the database takes days, thus we need a better solution that only tells the DiskStation to add new files. Gerd Naschenweng posted a good way which I adapted to music files. Just put the following file onto your DiskStation and run it remotely via ssh root@ perl “/volume1/public/pathtofile/”.


# Synology Media Indexer
# The Synology’s synoindexd service will only index files if those have been copied to the media
# directory via FTP, SMB, AFP. If you move or copy media files via Telnet/SSH, the indexer is not
# aware of those, and you would have to manually reindex (which is time-consuming).
# This script will scan the video directory for modified files over the last two days and will then
# query the synoindex-service if the file was already indexed. If the file does not exist in the index
# database, the script will manually add it for immediate indexing.
# I have included my most common media types in the script, but if I missed something, you are welcome
# to extend the script (and let me know what types I have missed).
# Usage: perl /volume1/video
# Or add to crontab:
# */10 * * * * root perl /volume1/Extensions/scripts/ /volume1/video
# (C) 2010 by Gerd W. Naschenweng ( /

@include_files = (“MP3″,”M4A”,”M3U”);

# message of synoindex indicating that file is not indexed
# for English this is: “Failed to get MediaInfo.”
# You can get the message in your locale with the following command (execute as is): synoindex -g “myfile.test” -t video
my $SYNO_ERROR_MSG = “Failed to get MediaInfo.”;

my $scan_dir = shift;

if (!$scan_dir) {

### Search for files which have changed during the last two days (adjust if necessary to shorter/longer intervals)
my @files = `find $scan_dir -type f -mtime -30`;
my $files_indexed = 0;

foreach (@files) {
my $file = $_;
my $ext = ($file =~ m/([^.]+)$/)[0];

### Check if the file-name extension is a valid media file
if (grep {lc $_ eq lc $ext} @include_files) {
my $result = `synoindex -g \”$file\” -t music`;

if ($result =~ m/^$SYNO_ERROR_MSG/i) {
print “Adding file to index: $file\n”;
my @synorc = `synoindex -a \”$file\”`;

if ($files_indexed) {
print “Synology Media Indexer added $files_indexed new media file(s)\n”;
} else {
print “Synology Media Indexer did not find any new media/n”;


The whole code is embedded in an Automator program thus I can easily double-click and all synchronization is done in the background.

Tags: , ,

1 comment

  1. […] Check out my instructions at and subsequent articles for syncing music and iTunes playlist with your Synology using rsync.iTunes playlist sync: […]

Leave a Reply

Your email address will not be published. Required fields are marked *