View Single Post
Old October 13th, 2010, 02:02 AM   #9 (permalink)
johnnychicago
New Member
Thread Author (OP)
 
Join Date: Sep 2010
Posts: 4
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by jwood79 View Post
Really!? Great, could you possibly share with me? Out of interest, what flavour of linux are you running on your mediaserver?

Course, here you go:

I'm running FTPServer on the phone, being started at connection to my home wifi - trust you get along to set this up yourself. In order to facilitate life, I've told my wireless router to always hand out the same IP to the phone.

I have a music directory with mp3-files (and folders) that is being mirrored to the phone, as well as a sync directory in which I put M3U-Playlists (that I generate e.g. for my podcasts). Those playlists have the mp3-files with full pathnames, and the script copies those files to the music directory, and changes album information (on the copies) to reflect the playlist.

Script runs from cron every half hour and checks if the phone's there. If so, it compiles the playlist albums, mirrors the music folder to the phone, and switches off the FTPServer on the phone (to prevent it from resyncing every half hour).

Dependencies are netcat, id3v2 and lftp - probaby apt-gettable pretty much anywhere. My distribution is Debian.

Code:
#!/bin/bash

# settings

HOST="192.168.x.y"   #this is the phone's IP address
PORT="2222"
USER="abc"   #for FTPserver on phone
PASSWD="XXXXXXX"
SYNC_DIR="/mnt/sync/music"  # on the computer
PL_DIR="/mnt/sync"
PL_PREFIX="_Playlist-"
PHONE_DIR="/sdcard/Music"  # where the phone keeps its music
LOCKFILE="/var/lock/sync_android"

# first, scan the phone to see if it is there. If not, exit

nc -z "$HOST" "$PORT" || exit;


# lockfile

if [ ! -e $LOCKFILE ]; then
        trap "rm -f $LOCKFILE; exit" INT TERM EXIT
        touch $LOCKFILE
else
        exit
fi


# create folders for playlists

for PLFILE in "$PL_DIR"/*.m3u ; do
        PL_DIR_NAME="$SYNC_DIR/$PL_PREFIX$(basename "$PLFILE" .m3u)"
        mkdir "$PL_DIR_NAME" || rm "$PL_DIR_NAME"/*
        COUNTER="1"
        egrep -v "^#" "$PLFILE" |  while read LINE
        do
                cp "$LINE" "$PL_DIR_NAME"
                id3v2 -A "$PL_PREFIX-$(basename "$PLFILE" .m3u)" -T "$COUNTER" "$PL_DIR_NAME/$(basename "$LINE")"
                let "COUNTER+=1"
        done
done

# delete all m3u playlists now so they don't get to phone

rm -rf "$SYNC_DIR"/*.m3u
rm -f "$PL_DIR"/*.m3u

# since this may have taken a while, check again if phone is there

nc -z "$HOST" "$PORT" || exit;

# access phone by ftp, mirror the phone directory to the sync directory
# and shutdown the phone ftp server

lftp -p "$PORT" -u "$USER","$PASSWD" "$HOST" <<END_SCRIPT
mirror --reverse --delete-first --only-newer --verbose "$SYNC_DIR"  "$PHONE_DIR"
quote site shutdown
quit
END_SCRIPT

rm $LOCKFILE
exit 0
johnnychicago is offline  
Reply With Quote
The Following User Says Thank You to johnnychicago For This Useful Post:
jwood79 (October 13th, 2010)