Page 1 of 2

Autosave Playlist

Posted: Wed Oct 22, 2008 9:18 am
by Belial
hi

i want to write a script which saves my actual playlist after some event occurs, e.g. a new song is added or after a period of time. the same routine MM do after exit itself.
i hope you understand my problem ;)

i´m new in scripting and so my snippet looks like this

Code: Select all

songcount = 0

Sub OnStartup
   Set Tmr = SDB.CreateTimer( 20000)
   Script.RegisterEvent Tmr, "OnTimer", "CheckSongCount"
   CheckSongCount()
End Sub


Sub CheckSongCount
   songtemp = SDB.Player.PlaylistCount
   If(songtemp =Not 0) Then
      songcount = songtemp
      SavePlaylist()
   End If
End Sub

Sub SavePlaylist
//some code here
End Sub
startup of the script makes no problem. but after the timer expires and the event is fired i get the error:
"error executing script event" :-?
i have NO idea where´s the error....or whats wrong. have you some hints?

Re: Autosave Playlist

Posted: Wed Oct 22, 2008 3:32 pm
by MoDementia
First line

Code: Select all

Sub CheckSongCount(Tmr)
   songtemp = SDB.Player.PlaylistCount
   If(songtemp =Not 0) Then
      songcount = songtemp
      SavePlaylist()
   End If
End Sub

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 3:15 am
by Belial
yeah...that´s it! thx
but now i´ve another problem. the if-statement is always false so the routine is never entered. why?

Code: Select all

Sub CheckSongCount(Tmr)
   songtemp = SDB.Player.PlaylistCount
   If(songtemp =Not songcount) Then       
      songcount = songtemp
      SavePlaylist()
   End If
End Sub

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 4:11 am
by MoDementia

Code: Select all

    Sub CheckSongCount(Tmr)
       songtemp = SDB.Player.PlaylistCount
       If songtemp<>songcount Then       
          songcount = songtemp
          SavePlaylist()
       End If
    End Sub

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 6:02 am
by Belial
thx MoDementia...
i´m done with my first MM-script

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 6:41 am
by MoDementia
Grats

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 7:35 am
by nynaevelan
Belial wrote:thx MoDementia...
i´m done with my first MM-script
I do hope you are planning on sharing, I like the possibilities your script will offer? :wink:

Nyn

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 8:06 am
by Belial
here´s my autosave script

Code: Select all

'
' MediaMonkey Script
'
' NAME: Playlist Autosave
'
' AUTHOR: Belial
' DATE : 22/10/2008
'
' INSTALL: Copy to Scripts\Auto directory
'
' CONFIG: 
' 1. define timer variable e.g. 5 min --> 300000ms
' 2. set M3UPath to your MediaMonkey config 
'    on WinXP C:\Documents and Settings\USERNAME\Local Settings\Application Data\MediaMonkey
'    the auto-playlist is always named as "mediamonkey.m3u"
'


M3UPath = "C:\Documents and Settings\USERNAME\Local Settings\Application Data\MediaMonkey\mediamonkey.m3u"
songcount = 0
time = 300000 

Sub OnStartup
   Set Tmr = SDB.CreateTimer(time)
   Script.RegisterEvent Tmr, "OnTimer", "CheckSongCount"
   songcount = SDB.Player.PlaylistCount
   CheckSongCount(Tmr)
End Sub


Sub CheckSongCount(Tmr)
   songtemp = SDB.Player.PlaylistCount
   If songtemp <> songcount Then
      songcount = songtemp
      SavePlaylist(SDB.Player.CurrentPlaylist)
   End If
End Sub


Sub SavePlaylist(Tracks)
    Dim iniF : Set iniF = SDB.IniFile
    
    ' Connect to the FileSystemObject
    Dim fso: Set fso = SDB.Tools.FileSystem  

    Dim fOut : Set fOut = fso.CreateTextFile(M3UPath, True)
    fOut.WriteLine "#EXTM3U"

    Dim i, Track, tLen, tArt, tTit
    For i = 0 To Tracks.Count - 1
        Set Track = Tracks.Item(i)
        tLen = Track.SongLength
        tArt = Track.ArtistName
        tTit = Track.Title
        
	  fOut.WriteLine("#EXTINF:" & tLen \ 1000 & "," & tArt & " - " & tTit)
        fOut.WriteLine Track.Path
    Next
    fOut.Close
End Sub

Enjoy!

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 8:49 am
by nynaevelan
Can I set it up to autosave the now playing list or does it have to be one of the static playlists?? Will the playlist be available within MM or will I have to import it in to be available?

Nyn

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 9:22 am
by Belial
it´s only for the now playing playlist....which will be openend automatically at MM-start

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 9:27 am
by nynaevelan
Belial wrote:it´s only for the now playing playlist....which will be openend automatically at MM-start
PERFECT :D :D because that is exactly what I want to autosave. I cannot tell you how many times I have lost my now playing list because my MM crashed on me. I will give it a test run and let you know if I have any problems.

Nyn

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 9:57 am
by nynaevelan
I get the following error when restarting MM:

Image

Nyn

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 11:03 am
by Belial
hey
sry it´s nooby mistake :cry:

"time" (my variable) is a build-in function in VBScript...therefore the error is fired
rename the variable "time" to "pause" then it will work perfectly :)
here´s the whole code

Code: Select all

' MediaMonkey Script
'
' NAME: Playlist Autosave
'
' AUTHOR: Belial
' DATE : 22/10/2008
'
' INSTALL: Copy to Scripts\Auto directory
'
' CONFIG:
' 1. define timer variable e.g. 5 min --> 300000ms
' 2. set M3UPath to your MediaMonkey config
'    on WinXP C:\Documents and Settings\USERNAME\Local Settings\Application Data\MediaMonkey
'    the auto-playlist is always named as "mediamonkey.m3u"
'


M3UPath = "C:\Documents and Settings\USERNAME\Local Settings\Application Data\MediaMonkey\mediamonkey.m3u"
songcount = 0
pause = 300000

Sub OnStartup
   Set Tmr = SDB.CreateTimer(pause)
   Script.RegisterEvent Tmr, "OnTimer", "CheckSongCount"
   songcount = SDB.Player.PlaylistCount
   CheckSongCount(Tmr)
End Sub


Sub CheckSongCount(Tmr)
   songtemp = SDB.Player.PlaylistCount
   If songtemp <> songcount Then
      songcount = songtemp
      SavePlaylist(SDB.Player.CurrentPlaylist)
   End If
End Sub


Sub SavePlaylist(Tracks)
    Dim iniF : Set iniF = SDB.IniFile
   
    ' Connect to the FileSystemObject
    Dim fso: Set fso = SDB.Tools.FileSystem 

    Dim fOut : Set fOut = fso.CreateTextFile(M3UPath, True)
    fOut.WriteLine "#EXTM3U"

    Dim i, Track, tLen, tArt, tTit
    For i = 0 To Tracks.Count - 1
        Set Track = Tracks.Item(i)
        tLen = Track.SongLength
        tArt = Track.ArtistName
        tTit = Track.Title
       
     fOut.WriteLine("#EXTINF:" & tLen \ 1000 & "," & tArt & " - " & tTit)
        fOut.WriteLine Track.Path
    Next
    fOut.Close
End Sub

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 12:06 pm
by nynaevelan
Ok, when I put in this I get no error but the now playing is not saving:

Code: Select all

M3UPath = "C:\Documents and Settings\m.thomas.JUNGLE\Local Settings\Application Data\MediaMonkey\mediamonkey.m3u"
songcount = 0
pause = 300000
When I put in this I get the same type of startup error:

Code: Select all

M3UPath = "C:\Documents and Settings\m.thomas.JUNGLE\Local Settings\Application Data\MediaMonkey\mediamonkey.m3u"
songcount = 0
pause = 300000ms
Any ideas??

Nyn

Re: Autosave Playlist

Posted: Thu Oct 23, 2008 12:43 pm
by Belial
the last code i posted works fine for me.
copy it and set only the M3UPath....you´ll see: it will work for you too :)