
As always the installer can be downloaded from my website, and the code is below...
Codice: Seleziona tutto
'
' MediaMonkey Script
'
' NAME: Bookmarker 2.0
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 20/04/2010
'
Option Explicit
Sub OnStartup()
  Dim ini : Set ini = SDB.IniFile
  Dim ind : ind = 0
  If ini.ValueExists("Bookmarker","Index") Then
    ind = ini.IntValue("Bookmarker","Index") 
  Else
    ini.IntValue("Bookmarker","Index") = 0
  End If   
  
  'create tree
  Dim tree : Set tree = SDB.MainTree
  Dim root : Set root = SDB.Objects("BookmarkerRoot")
  If Not (root Is Nothing) Then
    Call tree.RemoveNode(root) 
  End If     
  Set root = tree.CreateNode
  root.Caption = "Bookmarks"
  root.IconIndex = 19
  root.UseScript = Script.ScriptPath
  root.OnFillChildren = "FillBookmarks"
  Call tree.AddNode(tree.Node_Library,root,1) 'add after library
  root.HasChildren = True
  Set SDB.Objects("BookmarkerRoot") = root
End Sub
Sub FillBookmarks(root)
  root.HasChildren = False
  Dim tree : Set tree = SDB.MainTree
  Dim node : Set node = tree.CreateNode
  node.Caption = "Add new..."
  node.IconIndex = 6
  node.UseScript = Script.ScriptPath
  node.OnFillChildren = "FillAddNew"
  Call tree.AddNode(root,node,2) 'add child of bookmarks
  node.HasChildren = True
  
  Dim ini : Set ini = SDB.IniFile  
  Dim keys : Set keys = ini.Keys("Bookmarker")
  Dim i : i = 0
  For i = 0 To keys.Count-1
    Dim k : k = keys.Item(i)
    If Left(k,1) = "#" Then
      Dim j : j = InStr(k,"=")
      Dim bid : bid = Mid(k,2,j-2)
      Dim cap : cap = Mid(k,j+1)      
      Dim a : a = Split(ini.StringValue("Bookmarker","@"&bid)," ")
      Set node = tree.CreateNode
      node.Caption = cap
      node.CustomNodeId = bid
      node.CustomDataId = a(0) 'songs.id        
      node.CustomData = a(1) 'position        
      node.IconIndex = 3
      Call tree.AddNode(root,node,3) 'add child of bookmarks
      Call Script.RegisterEvent(node,"OnFillChildren","FillChildren")
      Call Script.RegisterEvent(node,"OnFillTracks","FillTracks")
      Call Script.RegisterEvent(node,"OnCanEditNode","EditNode")
      Call Script.RegisterEvent(node,"OnNodeEditText","OrigName")
      Call Script.RegisterEvent(node,"OnNodeEdited","EditName")
      Call Script.RegisterEvent(node,"OnShowMenuItem","ShowMenu")
      Call Script.RegisterEvent(node,"OnExecMenuItem","ExecMenu")        
      node.HasChildren = True
    End If
  Next
      
  root.HasChildren = True
End Sub
Sub FillAddNew(node)
  node.HasChildren = False
  
  'initialise
  Dim root : Set root = SDB.Objects("BookmarkerRoot")
  If root Is Nothing Then
    Call SDB.MessageBox("Bookmarker - root node is missing!",mtError,Array(mbOk))    
    Exit Sub  
  End If  
  Dim itm : Set itm = SDB.Player.CurrentSong
  If itm Is Nothing Then
    Call SDB.MessageBox("Bookmarker - there is no current song to bookmark!",mtError,Array(mbOk))    
    Exit Sub  
  End If  
  If (itm.ID < 1) Or (itm.IsntInDB) Then
    Call SDB.MessageBox("Bookmarker - song must be in the library to bookmark!",mtError,Array(mbOk))    
  End If
      
  'add to ini file
  Dim ini : Set ini = SDB.IniFile
  Dim ind : ind = ini.IntValue("Bookmarker","Index")+1
  Dim pbt : pbt = SDB.Player.PlaybackTime  
  Dim sid : sid = itm.ID
  Dim cap : cap = itm.Title&" ("&FormatTime(pbt)&")"
  ini.StringValue("Bookmarker","#"&ind) = cap
  ini.StringValue("Bookmarker","@"&ind) = sid&" "&pbt
  ini.IntValue("Bookmarker","Index") = ind
  
  'create node
  Dim tree : Set tree = SDB.MainTree
  Dim subn : Set subn = tree.CreateNode
  subn.Caption = cap
  subn.CustomNodeId = ind 
  subn.CustomDataId = sid 'songs.id               
  subn.CustomData = pbt 'position        
  subn.IconIndex = 3
  Call tree.AddNode(root,subn,3) 'add child of bookmarks
  Call Script.RegisterEvent(subn,"OnFillChildren","FillChildren")
  Call Script.RegisterEvent(subn,"OnFillTracks","FillTracks")  
  Call Script.RegisterEvent(subn,"OnCanEditNode","EditNode")
  Call Script.RegisterEvent(subn,"OnNodeEditText","OrigName")
  Call Script.RegisterEvent(subn,"OnNodeEdited","EditName")
  Call Script.RegisterEvent(subn,"OnShowMenuItem","ShowMenu")
  Call Script.RegisterEvent(subn,"OnExecMenuItem","ExecMenu")          
  subn.HasChildren = True
        
  tree.CurrentNode = tree.Node_NowPlaying         
  node.HasChildren = True
End Sub
Sub FillChildren(node)
  node.HasChildren = False
  
  'find song in now playing
  Dim list : Set list = SDB.Player.CurrentSongList
  Dim add : add = True
  Dim sid : sid = node.CustomDataId
  Dim pbt : pbt = node.CustomData
  If SDB.Player.CurrentSong.ID = sid Then
    add = False
  Else
    Dim i : i = 0
    For i = 0 To list.Count-1
      Dim itm : Set itm = list.Item(i)
      If itm.ID = sid Then
        SDB.Player.CurrentSongIndex = CLng(i)
        add = False
        Exit For
      End If
    Next
  End If  
  
  'add song to now playing
  If add Then
    Dim iter : Set iter = SDB.Database.QuerySongs("AND (Songs.ID="&sid&")")
    If Not iter.EOF Then 
      SDB.Player.PlaylistAddTrack(iter.item)
      SDB.Player.CurrentSongIndex = list.Count
    End If
    Set iter = Nothing
  End If
  
  'play song
  SDB.Player.Play
  While SDB.Player.IsStartingPlayback
    SDB.ProcessMessages
  WEnd  
  SDB.Player.PlaybackTime = pbt
  
  Dim tree : Set tree = SDB.MainTree
  tree.CurrentNode = tree.Node_NowPlaying
  node.HasChildren = True
End Sub
Sub FillTracks(node)
  node.HasChildren = False
    
  Dim main : Set main = SDB.MainTracksWindow
  main.AddTracksFromQuery("WHERE Songs.Id="&node.CustomDataId)
  main.FinishAdding  
  
  node.HasChildren = True  
End Sub
Function ShowMenu(mode)
  If mode = 5 Then
    ShowMenu = True
  Else
    ShowMenu = False
  End If    
End Function
Function ExecMenu(mode)
  If mode = 5 Then  
    Dim tree : Set tree = SDB.MainTree
    Dim node : Set node = tree.CurrentNode
    Dim ind : ind = node.CustomNodeId
    Call SDB.IniFile.DeleteKey("Bookmarker","#"&ind)
    Call SDB.IniFile.DeleteKey("Bookmarker","@"&ind)
    Call tree.RemoveNode(node)                
    ExecMenu = True
  Else  
    ExecMenu = False
  End If
End Function
Function EditNode(node)
  EditNode = True
End Function
Function OrigName(node)
  OrigName = SDB.IniFile.StringValue("Bookmarker","#"&node.CustomNodeId)
End Function    
Sub EditName(node,cap)
  SDB.IniFile.StringValue("Bookmarker","#"&node.CustomNodeId) = cap
  node.Caption = cap
End Sub
Function FormatTime(mil)
  Dim intLength : intLength = CCur(mil/1000)
  Dim datLength : datLength = TimeSerial(11,11,11)
  Dim strLength : strLength = FormatDateTime(datLength,vbshorttime)
  Dim strTimeSeparator : strTimeSeparator = Left(Replace(strLength,"1",""),1)
  Dim intLengthHeures : intLengthHeures = Int((intLength / 60) / 60)
  Dim intLengthMinutes : intLengthMinutes = Int((intLength / 60) Mod 60)
  Dim intLengthSecondes : intLengthSecondes = Int(intLength Mod 60)
  strLength = intLengthHeures&strTimeSeparator
  If intLengthMinutes < 10 Then 
    strLength = strLength&"0"
  End If
  strLength = strLength&intLengthMinutes&strTimeSeparator
  If intLengthSecondes < 10 Then 
    strLength = strLength&"0"
  End If
  FormatTime = strLength&intLengthSecondes
End Function