Latest: Genstatic, my first sip of coffee

Content with Style

Web Technique

Buffalo NAS and iTunes - A weekend of nerding away

by Pascal Opitz on September 26 2010, 15:26

Thank you Apple, for messing up the compatibility between iTunes 10 and any NAS drive using firefly. You officially suck.

That said, there's no such thing as giving up, and here I am, coming up with an elaborate way to be able to listen to my music again.

Firefly broken

So firely doesn't get recognised by iTunes 10 anymore. What a bummer! Until now I had all the music on a NAS drive, and streamed it to itunes on my Mac MINI which is acting as TV (using an Elgato EyeTV USB thingy) and stereo.

There seems to be zero alternatives when it comes to DAAP players, apart from Songbird with a flaky plugin. Not my weapon of choice, really, especially because a search or scrolling or anything else makes Songbird hang for what feels like a minute.

Bottom line was that I went and bought a hard drive to wire up to the Mac Mini, and used rsync to copy all music on to that.


rsync -azv -e ssh user@nasdrive:/mnt/disk1/itunes /Volumes/NewHD/

Adding to the iTunes library

The next problem is that just because files are on the hard drive, iTunes doesn't necessarily know about them. Normally we drag and drop them in. With an automatically synced library is not an option. Apple script to the rescue. Make sure that you disable the options "Keep iTunes media folder organized" and "Copy files to iTunes media folder when adding to library" in the iTunes preferences, or this will really cause havoc.

Once you've done that though, adding a file twice should just ignore it, therefore there is no risk in running this script multiple times.


-- filename: /Users/tvmini/Desktop/itunes.scpt
property type_list : {"MPG3", "MIDI", "AIFF", "MPG4"}
property extension_list : {"mp3", "mid", "aif", "m4p", "m4a"}

on run
    scan_folder("NewHD:itunes:")
end run

on scan_folder(file_item)
    set folder_items to list folder file_item without invisibles
    repeat with i from 1 to the count of folder_items
        set this_item to alias ((file_item as text) & (item i of folder_items as text))
        set item_info to info for this_item
        if folder of the item_info is true then
            scan_folder(this_item)
        else if (alias of the item_info is false) and ¬
        ((the file type of the item_info is in the type_list) or ¬
        the name extension of the item_info is in the extension_list) then
            check_file(this_item)
        end if
    end repeat    
end scan_folder

on check_file(file_item)
    try
        tell application "iTunes"
            launch
            set this_track to add file_item to playlist "Library" of source "Library"
        end tell
    end try
end check_file    

This script was inspired by this one at dougscripts.com.

The Flac problem

Firefly was kind of neat, as it also managed to automatically transcode FLAC files into an MP3 stream. With this function gone, I am using a shell script to transcode the files:


#!/bin/sh
# filename: /Users/tvmini/Desktop/flac2mp3.sh

if [ "$1" ]
then
    find "$1" -name '*.flac' | while read fn;
    do
        basename=$(basename "$fn" .flac).mp3
        dirname=$(dirname "$fn")
        
        outfile="$dirname/$basename"
        
        if [ -e "$fn" ] && [ ! -e "$outfile" ];
        then
            id3title=$(metaflac --show-tag=TITLE "$fn" | perl -pe "s/^TITLE=(.*)/\$1/i")
            id3artist=$(metaflac --show-tag=ARTIST "$fn" | perl -pe "s/^ARTIST=(.*)/\$1/i")
            id3album=$(metaflac --show-tag=ALBUM "$fn" | perl -pe "s/^ALBUM=(.*)/\$1/i")
            id3date=$(metaflac --show-tag=DATE "$fn" | perl -pe "s/^DATE=(.*)/\$1/i")
            id3tracknumber=$(metaflac --show-tag=TRACKNUMBER "$fn" | perl -pe "s/^TRACKNUMBER=(.*)/\$1/i")
            id3genre=$(metaflac --show-tag=GENRE "$fn" | perl -pe "s/^GENRE=(.*)/\$1/i")
        
            flac -c -d "$fn" | \
            lame -h -m s -b 360 \
                --tt "$id3title" \
                --ta "$id3artist" \
                --tl "$id3album" \
                --ty "$id3date" \
                --tn "$id3tracknumber" \
                --tg "$id3genre" \
                - "$outfile"
        else
            echo >&2 ""$fn" -- skipping."
        fi
    done
else
    echo >&2 "Usage: "$(basename "$0")" DIRNAME"
    exit 1
fi

Note that I leave the flac file in place so that it won't get uploaded again every time I run the rsync command. The script then checks for a transcoded mp3 file that exists in the same directory and will only transcode again if this is not the case.

Inspiration for this came from mainly from this message on the Apple Support Forums.

Keeping things up to date

Calling the above scripts via cron job should keep everything up to date:


0 2 * * * rsync -azv -e ssh user@nasdrive:/mnt/disk1/itunes /Volumes/NewHD/
0 3 * * * osascript /Users/tvmini/Desktop/itunes.scpt
0 4 * * * sh /Users/tvmini/Desktop/flac2mp3.sh /Volumes/NewHD/itunes

Comments

  • Seems you weren't the only one working the weekend away:

    "iTunes 10.0.1 (22) fixed it for me on my original audio/firefly port install on FreeBSD 8.1-RELEASE. Thanks Apple and all for the patches that also fixed incompatibility. "

    http://discussions.apple.com/thread.jspa?threadID=2564925&start=105&tstart=0

    by Matthias Willerich on September 27 2010, 18:15 - #


Comments for this article are closed.