Sync All Tracks - Created 01/09/2013

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Sync All Tracks - Created 01/09/2013

Postby trixmoto » Sun Sep 01, 2013 4:05 pm

This script, as requested, will allow you to select one of the active devices, and trigger the automatic synchronisation process manually. It was built specially to someone's specifications, but I've finally got round to releasing it to the community. If you know the device ID and always want to synchronise this device, then you can modify the script to hard code the ID and avoid the device selection popup. You need to be on MM build 1628 at least for this to work.

The installation package can be downloaded from my website. Or here is the code for your perusal...

Code: Select all
'
' MediaMonkey Script
'
' NAME: SyncAllTracks 1.0
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 10/04/2013
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini
'          Don't forget to remove comments (') and set the order appropriately
'
' [SyncAllTracks]
' FileName=SyncAllTracks.vbs
' ProcName=SyncAllTracks
' Order=1
' DisplayName=Sync All Tracks
' Description=Sync All Tracks
' Language=VBScript
' ScriptType=0
'

Option Explicit

Dim DeviceID : DeviceID = "" 'device ID - popup will appear if blank
Dim UseAuto : UseAuto = True 'use auto sync option (if MM4.1 or higher)
Dim Notify : Notify = True 'create notification file when sync complete

Sub SyncAllTracks
  DeviceID = ""
 
  Dim list : Set list = SDB.Device.ActiveDeviceList("")
  If list.Count = 0 Then
    Call SDB.MessageBox(SDB.Localize("No active devices. [1]"),mtError,Array(mbOk))
    Exit Sub
  End If
 
  Dim inds : inds = ""
  Dim nams : nams = ""
  Dim boo : boo = False
  Dim i : i = 0
  For i = 0 To list.Count-1
    If list.DeviceHandle(i) > -1 Then
      Dim indx : indx = list.DeviceID(i)
      Dim sqls : sqls = "SELECT DeviceCaption FROM Devices WHERE DetailedUSBID LIKE '%"&indx&"%'"
      Dim iter : Set iter = SDB.Database.OpenSQL(sqls)
      If Not iter.EOF Then 
        If DeviceID = "" Then
          inds = inds&"~|~"&indx
          nams = nams&"~|~"&iter.StringByIndex(0)
        ElseIf DeviceID = indx Then
          boo = True
          i = list.Count
        End If
      End If
      Set iter = Nothing
    End If
  Next

  If DeviceID = "" Then 
    If inds = "" Then
      Call SDB.MessageBox(SDB.Localize("No active devices. [4]"),mtError,Array(mbOk))
      Exit Sub   
    Else
      inds = Mid(inds,4)
      If InStr(inds,"~|~") > 0 Then
        nams = Mid(nams,4)
        DeviceID = SkinnedDropdown(SDB.Localize("Device:"),"Sync All Tracks",inds,nams,"SyncAllTracks")
      Else
        DeviceID = inds
      End If       
    End If
  Else
    If Not boo Then
      Call SDB.MessageBox(SDB.Localize("Specified device is not active. [5]"),mtError,Array(mbOk))
      Exit Sub       
    End If
  End If
 
  If DeviceID = "" Then
    Call SDB.MessageBox(SDB.Localize("No device specified. [6]"),mtError,Array(mbOk))
    Exit Sub       
  End If 
 
  Set list = SDB.Device.ActiveDeviceList(DeviceID)
  If list.Count <> 1 Then
    Call SDB.MessageBox(SDB.Localize("Specified device is not active. [7]"),mtError,Array(mbOk))
    Exit Sub
  End If
 
  Dim hand : hand = list.DeviceHandle(0)
  If hand < 0 Then
    Call SDB.MessageBox(SDB.Localize("Specified device is not active. [8]"),mtError,Array(mbOk))
    Exit Sub
  End If
 
  If Notify Then
    Call Script.RegisterEvent(SDB,"OnDeviceSyncCompleted","SyncComplete")
  End If 
 
  If UseAuto Then
    Call SDB.Device.StartAutoSynch(hand)
  Else
    Dim trax : Set trax = SDB.NewSongList
    Dim sitr : Set sitr = SDB.Database.QuerySongs("")
    While Not sitr.EOF
      Call trax.Add(sitr.Item)
      sitr.Next
    WEnd
    Set sitr = Nothing
    Call SDB.Device.StartSynch(hand,trax)
  End If
End Sub

Function SkinnedDropdown(Text,Caption,inds,nams,PositionName)
  Dim Form, Label, Edt, btnOk, btnCancel, modalResult

  ' Create the window to be shown
  Set Form = SDB.UI.NewForm
  Form.Common.SetRect 100, 100, 360, 130
  Form.BorderStyle  = 4   ' Resizable
  Form.FormPosition = 4   ' Screen Center
  Form.SavePositionName = PositionName
  Form.Caption = Caption
     
  ' Create a button that closes the window
  Set Label = SDB.UI.NewLabel(Form)
  Label.Caption = Text
  Label.Common.Left = 5
  Label.Common.Top = 10
     
  Set Edt = SDB.UI.NewDropDown(Form)
  Edt.Common.Left = Label.Common.Left
  Edt.Common.Top = Label.Common.Top + Label.Common.Height + 5
  Edt.Common.Width = Form.Common.Width - 20
  Edt.Common.ControlName = "Edit1"
  Edt.Common.Anchors = 1+2+4 'Left+Top+Right
  Call Edt.AddItem("Please select...")
  Edt.ItemIndex = 0
 
  Dim dic : Set dic = CreateObject("Scripting.Dictionary")
  Dim ari : ari = Split(inds,"~|~") 
  Dim arn : arn = Split(nams,"~|~")
  Dim i : i = 0
  For i = 0 To UBound(ari)
    Call Edt.AddItem(arn(i))
    dic.Item(arn(i)) = ari(i)
  Next
       
  ' Create a button that closes the window
  Set BtnOk = SDB.UI.NewButton(Form)
  BtnOk.Caption = "OK"
  BtnOk.Common.Top = Edt.Common.Top + Edt.Common.Height + 10
  BtnOk.Common.Hint = "OK"
  BtnOk.Common.Anchors = 4   ' Right
  BtnOk.UseScript = Script.ScriptPath
  BtnOk.Default = True
  BtnOk.ModalResult = 1
   
  Set BtnCancel = SDB.UI.NewButton(Form)
  BtnCancel.Caption = "Cancel"
  BtnCancel.Common.Left = Form.Common.Width - BtnCancel.Common.Width - 15
  BtnOK.Common.Left = BtnCancel.Common.Left - BtnOK.Common.Width - 10
  BtnCancel.Common.Top = BtnOK.Common.Top
  BtnCancel.Common.Hint = "Cancel"
  BtnCancel.Common.Anchors = 4   ' Right
  BtnCancel.UseScript = Script.ScriptPath
  BtnCancel.Cancel = True
  BtnCancel.ModalResult = 2
       
  SkinnedDropdown = ""
  If Form.showModal = 1 Then
    Dim nam : nam = Edt.SelText
    If nam <> "Please select..." Then     
      SkinnedDropdown = dic.Item(nam)
    End If
  End If 
End Function

Sub SyncComplete(hand)
  Call Script.UnRegisterHandler("SyncComplete")
  Dim fso : Set fso = SDB.Tools.FileSystem
  Dim path : path = Script.ScriptPath&".txt"
  Dim fout : Set fout = fso.CreateTextFile(path,True)
  Call fout.WriteLine(hand&" - sync complete")
  Call fout.Close()
End Sub

Sub Install()
  If SDB.VersionBuild < 1628 Then
    Call SDB.MessageBox(SDB.Localize("Must have version 4.1.0.1628 or higher for this script to work."),mtError,Array(mbOk))
    Exit Sub   
  End If
 
  Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
  Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  If Not (inif Is Nothing) Then
    inif.StringValue("SyncAllTracks","Filename") = "SyncAllTracks.vbs"
    inif.StringValue("SyncAllTracks","Procname") = "SyncAllTracks"
    inif.StringValue("SyncAllTracks","Order") = "1"
    inif.StringValue("SyncAllTracks","DisplayName") = "Sync All Tracks"
    inif.StringValue("SyncAllTracks","Description") = "Sync All Tracks"
    inif.StringValue("SyncAllTracks","Language") = "VBScript"
    inif.StringValue("SyncAllTracks","ScriptType") = "0"
    SDB.RefreshScriptItems
  End If
End Sub
Download my scripts at trixmoto.net.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE
trixmoto
 
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK

Return to Need Help with Addons?

Who is online

Users browsing this forum: No registered users and 23 guests