auto export and transform madsonic playlists

Scripts for Madsonic

auto export and transform madsonic playlists

Unread postby jay3712 » 18 Feb 2014, 19:15

Hi all,
I am attempting to unify my playlists so that I can maintain them on one system (madsonic) and have them automatically transformed and maintained on my other systems (primarily Sonos, maybe XBMC and Plex). To accomplish this I wanted to create a script that will transform my playlists and automatically save them in another folder, after I have created them in madsonic.

/mnt/music/playlists/madsonic/ <--I want to auto-export all playlists created to this folder (every 5 minutes should be fine). I have the option set in Madsonic > Settings > General under export playlists to, but the playlists don't get exported unless use Export Playlists under Settings > Playlist. Any way to schedule this to run automatically? Also the playlists are in .m3u8 format. It appears that I can simply rename them to .m3u with no problems so I was just planning to do that with the script below.

Then (using cron) run this script every 5 minutes or so. The purpose here is to change (for all .m3u8 files in /mnt/music/playlists/madsonic) the paths from /mnt to //10.0.10.91 and save the new (.m3u) file to /mnt/music2. I need some help getting this finished - the sed rename part works when I run it for one file, but I am not sure how to make it run for each .m3u* file in a given directory and save them with the same names in another directory:

Code: Select all
#!/bin/sh
MADSONICPLAYLISTS=/mnt/music/playlists/madsonic/*
for *.m3u8 in $MADSONICPLAYLISTS
   sed -n '
      s|
      /mnt|
      //10.0.10.91|
      gpw '/mnt/music2/$MADSONICPLAYLISTS.m3u' $MADSONICPLAYLISTS.m3u
done


Once the file is transformed and saved to /mnt/music2, Sonos will automatically pick it up from here. If the playlist already exists in /mnt/music2, I would like the script to overwrite the old version with the new. This will be one way sync only.

Madsonic 5.0.3830 running on dedicated Debain 7.3 vm.

Thanks in advance for any assistance!
Jason
jay3712
 
Posts: 3
Joined: 01 Oct 2013, 23:38
Has thanked: 0 time
Been thanked: 1 time

Re: auto export and transform madsonic playlists

Unread postby jay3712 » 19 Feb 2014, 00:21

Perhaps this belongs in support, as it is not a completed script... Please move as needed!
jay3712
 
Posts: 3
Joined: 01 Oct 2013, 23:38
Has thanked: 0 time
Been thanked: 1 time

Re: auto export and transform madsonic playlists

Unread postby jay3712 » 26 Mar 2014, 19:46

Alright, with the assistance of some very nice people at unix.org, I now have a working script to share. My process is as follows:

All playlists are created and managed in Madsonic. It is the "master" and single point of modification and input. Madsonic playlists are set to export to /mnt/music/playlists/madsonic and the playlist will be transformed and saved to /mnt/music2 where they will be readable and discovered by Sonos players.

First I delete any existing .m3u8 playlist files in /mnt/music/playlists/madsonic and .m3u playlists from /mnt/music2. This will make sure that the files are all the latest versions, and if I delete a playlist in Madsonic it will be deleted in Sonos.
Then I "hit" the url for exporting playlists in Madsonic. I know this is inelegant and hackey, so if there is a better way to kick off the "export playlists" function please let me know. This results in an output file that is immediately deleted.
Then the fun part begins. fIn is the directory where the script looks for files that end in m3u8.
The output destination is set with fOut and output extension set to m3u.
Then, for each file we cut off the path and the extension, run it through sed to find & replace /mnt with //10.0.10.91 and drop the new file in the correct directory to be discovered by Sonos.

The script is stored on my Madsonic VM (Debian) and run with crontab every 5 minutes.

Code: Select all
#! /bin/bash
rm /mnt/music/playlists/madsonic/*.m3u8
rm /mnt/music2/*.m3u

wget xxxxxxxxx.com/madsonic/playlistSettings.view?exportPlaylists --user=jason --password=xxxxxxxx
wait
rm playlistSettings.view\?exportPlaylist*
wait

typeset fIn="/mnt/music/playlists/madsonic"
typeset chExtIn="m3u8"
typeset fOut="/mnt/music2"
typeset chExtOut="m3u"
typeset chFile=""

for chFile in "$fIn"/*"$chExtIn" ; do
        #echo "$chFile"
        chFile="${chFile##*/}"                  # cut off path, leaving filename.ext
        chFile="${chFile%.*}"                   # cut off extenstion, leaving filename
        #echo "input: ${fIn}/${chFile}.${chExtIn} /// output: ${fOut}/${chFile}.${chExtOut}"
        sed 's/^\/mnt/\/\/10.0.10.91/' "${fIn}/${chFile}.${chExtIn}" > "${fOut}/${chFile}.${chExtOut}"

done


In addition, I created a simple "backup" script to copy the playlists in a different directory, so that if all my playlists are deleted and the script runs, I will have backups that I can easily import back to Madsonic and get rolling again. This one runs every day at 4am.
Code: Select all
#! /bin/bash
cp /mnt/music/playlists/madsonic/*.m3u8 /mnt/data/playlists/madsonic
cp /mnt/music2/*.m3u /mnt/data/playlists/sonos


So now my playlists can be easily managed in Madsonic, and when I want to play one of them in Sonos, it's already there and waiting. The only other system that very rarely plays music is XBMC, so next I am going to look at having the xbmc systems look here for playlists as well.

Hope this helps someone, let me know if any questions!
jay3712
 
Posts: 3
Joined: 01 Oct 2013, 23:38
Has thanked: 0 time
Been thanked: 1 time

Re: auto export and transform madsonic playlists

Unread postby Clifford » 15 Apr 2014, 16:01

I would love to have my windows based madsonic playlists available to my Plex client. Any thoughts of directing some effort in that area?
Clifford
 
Posts: 21
Joined: 07 Nov 2013, 17:03
Has thanked: 0 time
Been thanked: 9 times


Return to Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

cron