PDA

View Full Version : Playlist synch with Linux and Windows



Peterb
2005-10-03, 05:32
I have a Slimserver running on Linux and a Windows workstation that is used to rip music and organize playlists with Media Jukebox. All music is stored on a Samba Share on the Linux box and works fine since the slimserver uses the same directory.

However one problem is that the playlists that I export from MJ in .m3u format doesn't work. The problem is that the workstation sees that path to the music as M:\ and the Server sees it as /usr/mp3. The workstation uses \ where the server uses / in the path.

I've noticed that a lot of people seem to have similar problems but I really haven't found a good solution so I did a quick-and-dirty solution that works ok for me. It's a small script on the Linux-server that looks like this:

ls /usr/playlists/*.m3u | while read -e FNAME
do
sed -e 's/M:\\/\/usr\/mp3\//g' "$FNAME" > "${FNAME}2"
rm -f "$FNAME"
sed -e 's/\\/\//g' "${FNAME}2" > "$FNAME"
rm -f "${FNAME}2"
done

The first sed line changes the M:\ to /usr/mp3 and the second one changes \ to /. Whenever the script is run it changes this for all files named .m3u in the playlist directory. Every time I've exported a playlist I run the scripts. It can also be scheduled.

To make it work for another setup the paths (M:\ and /usr/mp3) needs to be changed. Hope someone finds it useful. It's been at least 10 years since I did any shell programming so it's not exactly beautiful but it works. Any suggestions on improvements are welcome

I briefly checked what other possible solution might exist and I found two roads that might be better.

1) Using a Samba VFS (Virtual File System) and change the read and write functions so that these changes are being made during read and write. Possibly this could work both ways so that the files could be both opened and writtten to from the workstation.

2) Also there is a sw called FAM (File Alteration Maonitor) that possibly could be used to automate file changes as soon as a file is dropped in the playlist directory.

If anyone have had success with these two options please share your experences. Even better would of course be if something similar could be built in to the slimserver. Maybe a configurable importfilter for playlists that can change the playlists as they are imported and exported.

/ Peter

Niek Jongerius
2005-10-03, 06:26
> ls /usr/playlists/*.m3u | while read -e FNAME
> do
> sed -e 's/M:\\/\/usr\/mp3\//g' "$FNAME" > "${FNAME}2"
> rm -f "$FNAME"
> sed -e 's/\\/\//g' "${FNAME}2" > "$FNAME"
> rm -f "${FNAME}2"
> done
>
> Any suggestions on improvements are welcome

A few points:

- The '-e' is not necessary (and it even seems syntactically wrong,
as it should expect a script file to read).
- The first char right after the 's' in the sed command is the field
separator. You have it set to '/', which then forces you to escape
it when you want to use it as part of the string. If you instead
choose a different separator, your sed command will become more
readable.
- You could use a generic temp file, which makes the code more readable.

Result:

TMPFILE=/tmp/script.$$
ls /usr/playlists/*.m3u | while read -e FNAME
do
sed 's|M:\\|/usr/mp3/|g' "$FNAME" > "${TMPFILE}"
sed 's|\\|/|g' "${TMPFILE}" > "${FNAME}"
done
rm -f "${TMPFILE}"

Niek.

Peterb
2005-10-04, 06:17
for the suggestions Niek. They make the code much more readable.