Autosave Playlist

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

Belial

Autosave Playlist

Post 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?
MoDementia
Posts: 1321
Joined: Thu Jun 15, 2006 3:26 pm
Location: Geelong, Victoria, Australia

Re: Autosave Playlist

Post 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
Belial

Re: Autosave Playlist

Post 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
MoDementia
Posts: 1321
Joined: Thu Jun 15, 2006 3:26 pm
Location: Geelong, Victoria, Australia

Re: Autosave Playlist

Post by MoDementia »

Code: Select all

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

Re: Autosave Playlist

Post by Belial »

thx MoDementia...
i´m done with my first MM-script
MoDementia
Posts: 1321
Joined: Thu Jun 15, 2006 3:26 pm
Location: Geelong, Victoria, Australia

Re: Autosave Playlist

Post by MoDementia »

Grats
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: Autosave Playlist

Post 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
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
Belial

Re: Autosave Playlist

Post 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!
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: Autosave Playlist

Post 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
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
Belial

Re: Autosave Playlist

Post by Belial »

it´s only for the now playing playlist....which will be openend automatically at MM-start
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: Autosave Playlist

Post 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
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: Autosave Playlist

Post by nynaevelan »

I get the following error when restarting MM:

Image

Nyn
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
Belial

Re: Autosave Playlist

Post 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
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: Autosave Playlist

Post 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
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
Belial

Re: Autosave Playlist

Post 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 :)
Post Reply