[General Questions and Answers] trey85stang:
Hey all-

I got tired of the ****ty transfer apps, on mac, for itunes to android. So I wrote an bash/awk script to do the job.

If anyone is interested it is posted here, I also have it on github and will be making updates to it.

First off - Im sure there are bugs, and this is probably version .01. I spent about 2 hours on it so far and it works fine for me at this point.

What it does -

Reads itunes, and lists playlists, choose your playlist... Then the transfer will start (it will not transfer files already on the device... can you believe that?).

github: search it2android (i cant post links)

Here are the scripts (just modify the DEVICEPATH line)

it2android.sh

#!/bin/bash

LIBRARY="$HOME/Music/iTunes/iTunes Music Library.xml"
DEVICEPATH="/Volumes/External/TESTING"
GETLIST_AWK="playlist.parse"
SONGINFO_AWK="getsonginfo.parse"
PLAYLIST_AWK="getplaylists.parse"

#test for device path...
#make sure device is mounted!!!
if [ ! -f "$DEVICEPATH" ]
then
echo "Creating device path..."
mkdir $DEVICEPATH
fi

#pick a playlist
awk -f "$GETLIST_AWK" "$LIBRARY" |
while read line
do
let cnt++
lists[$cnt]="${line}"
done

recnt=1
while [ $recnt -ne $cnt ]
do
echo "${recnt}) ${lists[$recnt]}"
let recnt++
done
read -p "choose a number: " PICK

echo "PLAYLIST=${lists[$PICK]}"
PLAYLIST="${lists[$PICK]}"

for f in $(awk -v PLAYLIST="$PLAYLIST" -f "$PLAYLIST_AWK" "$LIBRARY")
do
eval $(awk -v SONGID="$f" -f "$SONGINFO_AWK" "$LIBRARY")
#the real **** starts here...
if [ -f "$FILELOC" ]
then
#copy location...
TODIR="${DEVICEPATH}/${ARTIST/\//}/${ALBUM/\//}"
FILENAME="${TRACKNUM}-${NAME/\//}.${FILELOC##*.}"
echo "COPYING: ${TODIR}/${FILENAME}"
if [ ! -f "${TODIR}/${FILENAME}" ]
then
if [ ! -d "${TODIR}" ]
then
mkdir -p "${TODIR}"
fi
if ! cp -f "${FILELOC}" "${TODIR}/${FILENAME}"
then
echo "Failed to copy $FILENAME"
fi
else
echo "File already on device"
fi
fi
done

getplaylists.parse

BEGIN { marker=1 }
{
if( $0 ~ /<key>Playlists<\/key>/ ) {
marker=0
next
}
#print marker
if( marker == 0 ) {
if ( $0 ~ "<key>Name.*" ) {
sub("\t* *<key>Name</key><string>","",$0)
sub("</string>","",$0)
print $0
}
} else {
next
}
}

getsonginfo.parse

BEGIN {
marker=1
}

function del_crap (var)
{
sub("\t* *<[A-Za-z]*>.*<[0-9A-Za-z ]*>","",var)
sub("<.*","",var)
#print var
}

{
if ( marker == 1 )
{ if ( $0 ~ "<key>"SONGID"</key>" )
{ marker = 0
next
}
}
if ( marker == 0 )
{ if ( $0 ~ "</dict>" )
{ marker=1
} else {
#sub(/\t* *<key.*y><.*>/,"",$0)
#sub(/<.*>/,"",$0)
if ( $0 ~ /<key>Name/ )
{ sub("\t* *<[A-Za-z]*>.*<[0-9A-Za-z ]*>","",$0)
sub("<.*","",$0)
printf "export NAME=\"%s\"\n",$0
}
if ( $0 ~ /<key>Artist/ )
{ sub("\t* *<[A-Za-z]*>.*<[0-9A-Za-z ]*>","",$0)
sub("<.*","",$0)
printf "export ARTIST=\"%s\"\n",$0
}
if ( $0 ~ /<key>Album/ )
{ sub("\t* *<[A-Za-z]*>.*<[0-9A-Za-z ]*>","",$0)
sub("<.*","",$0)
printf "export ALBUM=\"%s\"\n",$0
}
if ( $0 ~ /<key>Disc Number/ )
{ sub("\t* *<[A-Za-z]*>.*<[0-9A-Za-z ]*>","",$0)
sub("<.*","",$0)
printf "export DISCNUM=\"%s\"\n",$0
}
if ( $0 ~ /<key>Disc Count/ )
{ sub("\t* *<[A-Za-z]*>.*<[0-9A-Za-z ]*>","",$0)
sub("<.*","",$0)
printf "export DISCTOT=\"%s\"\n",$0
}
if ( $0 ~ /<key>Track Number/ )
{ sub("\t* *<[A-Za-z]*>.*<[0-9A-Za-z ]*>","",$0)
sub("<.*","",$0)
printf "export TRACKNUM=\"%s\"\n",$0
}
if ( $0 ~ /<key>Track Count/ )
{ sub("\t* *<[A-Za-z]*>.*<[0-9A-Za-z ]*>","",$0)
sub("<.*","",$0)
printf "export TRACKTOT=\"%s\"\n",$0
}
if ( $0 ~ /<key>Location/ )
{ sub("\t* *<[A-Za-z]*>.*<[0-9A-Za-z ]*>","",$0)
sub("<.*","",$0)
gsub("%20"," ",$0)
sub("file:\/\/[a-zA-Z0-9]*","",$0)
printf "export FILELOC=\"%s\"\n",$0
}
}
}
}

getplaylists.parse

BEGIN {
marker=1
play_list_string=""
}

{ if ( marker == 1 )
{ if ( $0 ~ "<key>Name</key><string>"PLAYLIST"</string>" )
{ marker=0
next
}
}

if ( marker == 0 )
{ if ( $0 ~ "<key>Track ID</key><integer>" )
{ sub("\t* *<key>Track ID</key><integer>","",$0)
sub("</integer>","",$0)
print $0
} else {
if ( $0 ~ "</array>" )
{ exit
}
next
}
}
}

Directions, make a directory somewhere in your home directory, copy and paste the above files in it.

edit the DEVICEPATH to be your Music directory... ( start with a new directory... not an existing music directory or you will end up with duplicates.)

chmod +x it2andriod.sh

./it2adnroid

TODO:

I will be adding a few command line options. to supply a playlist, as well as options to pick how the name of the files stored to the device. (one directory two directory... file name.. blah blah).

If by random chance someone does actually use this.. let me know the problems you have and I will get them fixed.