• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Sync music via FTP from a Linux server

Good evening,

Part of why I bought a HTC Desire to replace my 2G iPhone was getting away from iTunes - piece of bloat required me to keep a Windows computer around, updating music was pesky, etc.

The plan with the HTC is to sync it over Wifi when it connects to my home network. The system it syncs with is a media server running Linux and storing my music collection.

I've gotten so far to have Tasker start FTPServer on connecting to Wifi, and have built a little script called every 10 minutes by cron that checks for presence of the phone. If it finds the phone, it connects and syncs a folder, then makes the ftp server on the phone shutdown, so it won't reconnect every 10 minutes.

So far, so good (I'll gladly share the bash script, if anybody wants to use. Needs some more polishing, though)

The bit that bugs me is playlists. I can create m3u playlists and copy them over fine, however once they are on the phone, they disappear from the Music folder and cannot be changed/deleted anymore - except by the built in music app. This is quite inconvenient, since I have a number of podcasts that get updated daily and that I'd like to take on the phone, with a playlist showing the newest episodes first. I can make the playlist easily on the computer, however the phone will end up with multiple copies of these playlists, which I can't get rid off.

Can anybody point me someplace that explains how Android handles playlists?

If there's no way, I'll work around by editing track/album MP3 tags and grouping my stuff together this way, but I'd prefer using simple playlists...
 
You can longpress-delete playlists in the Music app.

I was unaware the playlists get moved, though this explains a side effect I'm seeing. My script wipes out a /sdcard/audio directory and reloads music and timestamp-named playlists, but the old .m3u files continue to display in the playlist screen. I have to delete them as described above. If they are getting moved this explains why the wipe doesn't clear them.

Does the auto-genned "recently added" faux playlist do anything for you?

Looking forward to other podcast-related posts.
 
Upvote 0
You can longpress-delete playlists in the Music app.

Yes, I found out about that, too. But it's quite inconvenient to always have manually get rid of them.

I was unaware the playlists get moved, though this explains a side effect I'm seeing. My script wipes out a /sdcard/audio directory and reloads music and timestamp-named playlists, but the old .m3u files continue to display in the playlist screen. I have to delete them as described above. If they are getting moved this explains why the wipe doesn't clear them.

It does :)

I don't wipe, but use lftp's reverse mirror to just copy what's changed.

If I can't find how to get rid of the playlists, I'll use them server side to relabel ID3 tags and that way tie my stuff together. Make the album tag the playlist name, or something along these lines.

Does the auto-genned "recently added" faux playlist do anything for you?

I don't have that one.

Looking forward to other podcast-related posts.

Ah, not much, really. Using podcatcher to download them, then creating a playlist of the last 50 of them with find, sort and head. My music lives in a directory structure suitable for Squeeze Server, I just want a comfortable way to sync a tiny subset of it to the phone.
 
Upvote 0
Yes, I found out about that, too. But it's quite inconvenient to always have manually get rid of them.

I only sync after I've listened to all the 'casts so I'm deleting once a week or so. I can see how it would be a problem if syncing were more frequent.

Related: I suspect the .m3u is being converted to some kind of internal db on the device. I did a find on /sdcard for *.m3u and only found my original. Did the same on / in adb shell and found nothing.

Before I found the longpress deletion my workaround was to put a timestamp in the playlist name so I could tell them apart. :-o


I don't have that one.

Hmmm. Maybe it's a cyanomod thing. I thought his version of the Music app was stock; perhaps not. Claims to be v1.7.5.2 and the credits include Cyano, so I guess they hacked it.



Ah, not much, really. Using podcatcher to download them, then creating a playlist of the last 50 of them with find, sort and head. My music lives in a directory structure suitable for Squeeze Server, I just want a comfortable way to sync a tiny subset of it to the phone.

I meant in general. Music listeners seem to be the majority in media discussions. There probably are more of us who aren't talking much.

My setup looks like this:
  1. download - podracer does the downloads from a nightly cronjob, scripts do a bit of renaming and normalizing. I used to use hpodder but it disappeared from the ubuntu/debian repositories. I may have to find the source and roll my own. Weird-looking dependencies, though.
  2. script generates M3U and sync to G1

Do you listen to podcasts on the workstation mainly, and carry the subset on the phone for opportunistic listening? I wouldn't be able to keep track of what I had and hadn't listened to if I didn't do the total-wipe-and-load after listening to everything.
 
Upvote 0
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
 
  • Like
Reactions: jwood79
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones