Script to copy classifications text value to Custom3

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

W. Kyle White
Posts: 8
Joined: Sat Apr 30, 2005 1:32 pm

Script to copy classifications text value to Custom3

Post by W. Kyle White » Wed May 04, 2005 8:50 pm

Here's a quick and dirty script I threw together to copy the text values of any of the classifications to the custom3 attribute. Classifications are represented in MediaMonkey internally in the database as numeric values which are linked to the classification names. Copying them to custom fields allows them to be saved in the file tags, and also make the text names available for sorting/renaming/etc.
The SQL query could also be used in other scripts to retrieve classification text for individual songs.
The dialog box is hacked directly from MagicNodes 1.3 (thanks/sorry Pablo, post a comment if you have any concerns). Just read the comments at the top of the code for how to use it.

Code: Select all

'BackupClassificationToCustom3.vbs by W. Kyle White 
' A simple script that runs SQL queries for all songs selected and puts the 
' specified classification's text value into the Custom3 tag 
' The interface component is entirely hacked from Pablo's excellent MagicNodes script - 
' http://students.washington.edu/~shmerkin/magic_nodes 
' 
'Usage 
' *Use at your own risk 
' Select a song or songs and then run the script, it will request that you 
' specify the classification to copy to custom3, write the name as it appears in 
' MediaMonkey's classification node (not case sensitive) 
' The text for that classification will be placed into custom3 of each of the 
' songs 
'  i.e. type in "mood" without the quotes to put mood names
'  (such as "mellow" and "comatose") into the custom3 field
' Note that this does not write the ID3 tags directly 
' 
'Place this into the scripts.ini 
'------------------------------------------------- 
' [BackupClassificationToCustom3] 
' FileName=BackupClassificationToCustom3.vbs 
' ProcName=BackupClassificationToCustom3 
' Order=6 
' DisplayName=Copy Specified Classification -> Custom3 
' Description=Copy Specified Classification -> Custom3 
' Language=VBScript 
' ScriptType=0 
'------------------------------------------------- 
Function Cond(test, a, b)   ' Returns a if test evaluates to true, b otherwise
	If test Then
		Cond = a
	Else
		Cond = b
	End If
End Function


Function CurrentVersion
	CurrentVersion = 100 * SDB.VersionHi + SDB.VersionLo
End Function

Function SkinnedInputBox(text, caption, input) 

   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  = 2   ' Resizable 
   Form.FormPosition = 4   ' Screen Center 
   Form.SavePositionName = "Remember position" 
   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.NewEdit(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 
   Edt.Text = Input 
       
   ' 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 
   If currentVersion() >= 204 Then 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 
   If currentVersion() >= 204 Then BtnCancel.Cancel = True
   BtnCancel.ModalResult = 2 
       
   modalResult = Form.showModal 
       
   SkinnedInputBox = Cond(modalResult=1, Edt.Text, "") 
       
End Function 


Set ClassificationDict = CreateObject("Scripting.Dictionary") 
With ClassificationDict 
	.Add "TEMPO", "1"
	.Add "MOOD", "2"
	.Add "OCCASION", "3"
	.Add "QUALITY", "4"
End With



Sub BackupClassificationToCustom3
  ' Define variables
  Dim list, iter, itm, i, tmp, classification

  classification = UCase(SkinnedInputBox("Enter the classification to back up", "Define Classification", "MOOD"))
	if (classification = "") then
		Exit Sub
	End If
	
  ' Get list of selected tracks from MediaMonkey
  Set list = SDB.SelectedSongList
  If list.count=0 Then
  Set list = SDB.AllVisibleSongList
  End If  

  ' Process all selected tracks
  For i=0 To list.count-1
    Set itm = list.Item(i)
    Set Iter = SDB.Database.OpenSQL("SELECT Lists.TextData FROM Songs,AddSongInfoInt,Lists WHERE Lists.idListType = "&ClassificationDict.Item(classification)&" AND Lists.Id = AddSongInfoInt.intData AND AddSongInfoInt.idSong = "&itm.ID)

    ' Swap the fields
    itm.Custom3 = Iter.StringByName("TextData")

    ' Update the changes in DB
    itm.UpdateDB

    Iter.next
  Next
End Sub
Last edited by W. Kyle White on Sun May 08, 2005 10:52 am, edited 2 times in total.

Guest

Re: Script to copy category's text value to Custom3

Post by Guest » Sun May 08, 2005 1:27 am

W. Kyle White wrote: The dialog box is hacked directly from MagicNodes 1.3 (thanks/sorry Pablo, post a comment if you have any concerns).
No problem. In fact, the code for the dialog box was essentially written by Octopod and improved with suggestions from several people :) .

And thanks for the script! 8) .

Pablo
Posts: 554
Joined: Sun Feb 22, 2004 2:59 am

Post by Pablo » Sun May 08, 2005 1:29 am

That was me. Erased my cookies and forgot to login :oops: .

Post Reply