The SwitchFields script switches specified song data field pairs.
It is also possible to copy one field into another (instead of switching).
Utility functions Utility_General.vbs and Utility_Controls.vbs are necessary for the script to run.
You can download these from http://www.mediamonkey.com/forum/viewtopic.php?t=7921 and put them in MediaMonkey's Scripts folder.
The script consists of 1 script file ("SwitchOrCopyFields.vbs").
The script has been updated. You will need to update "Utility_Controls.vbs" too! (once, this will be done automaticly... )
SwitchOrCopyFields.vbs (for the Scripts folder)
Code: Select all
'==========================================================================
'
' MediaMonkey Script
'
' NAME: SwitchOrCopyFields v1.0
' DESCRIPTION:
' Switches specified song data field pairs: almost all possible song data fields in the library.
' (Change UpdateFileTags to True if you also want to update the file's tags)
' It is also possible to copy one field to another (instead of switching them)
'
' AUTHOR: Steegy aka RC
' DATE : 31.01.2006
' UPDATE: 16.02.2006
'
' INSTALL:
' - Copy script to MediaMonkey's "Scripts" folder and add the following in the
' file Scripts\Scripts.ini (remove the ' in front)
'
'[SwitchOrCopyFields]
'FileName=SwitchOrCopyFields.vbs
'ProcName=SwitchOrCopyFields
'Order=6
'DisplayName=Switch Or Copy Fields
'Description=Switch Or Copy Fields
'Language=VBScript
'ScriptType=0
'
'
'==========================================================================
'>> ForumURL: http://www.mediamonkey.com/forum/viewtopic.php?t=7920
'>> ScriptName: SwitchOrCopyFields
'>> VersionNumber: 1.0
'>> Author: Steegy aka RC (Ruben Castelein)
'>>>>EndOfProperties
Dim UpdateFileTags
UpdateFileTags = True
'=============================
' IMPORTS
'=============================
ExecuteGlobal GetFileContents(SDB.ApplicationPath & "Scripts\Utility_General.vbs")
ExecuteGlobal GetFileContents(SDB.ApplicationPath & "Scripts\Utility_Controls.vbs")
'=============================
' BUILD FORM
'=============================
Sub SwitchOrCopyFields
Dim mySongList
Set mySongList = SDB.SelectedSongList
If MySongList.Count = 0 Then
Set MySongList = SDB.AllVisibleSongList
If MySongList.Count = 0 Then
SDB.MessageBox "Nothing selected!", mtError, Array(mbOK)
Exit Sub
End If
End If
Set SDB.Objects("MySongList") = MySongList
Set Form = SDB.UI.NewForm
Form.Common.SetRect 100, 100, 360, 140
Form.BorderStyle = 3 ' Resizable
Form.FormPosition = 4 ' Screen Center
Form.Caption = "Switch or Copy Fields in Library/Files"
Dim DropDownValueSwitch1, DropDownValueSwitch2, SwitchValuesButton, CloseButton
Set DropDownValueSwitch1 = CreateDropDown(Form, 20, 20, 130, 20, "DropDownValueSwitch1")
Set DropDownValueSwitch2 = CreateDropDown(Form, 200, 20, 130, 20, "DropDownValueSwitch2")
Dim SwitchLabel
Set SwitchLabel = CreateLabel(Form, "<-->", 165, 23, 20, 20)
SwitchLabel.Common.ControlName = "SwitchLabel"
Dim CopyOnlyCheckBox
Set CopyOnlyCheckBox = CreateCheckBox(Form, "Copy only (instead of switch)", 165, 43, 200, 20)
CopyOnlyCheckBox.Common.ControlName = "CopyOnlyCheckBox"
Script.RegisterEvent CopyOnlyCheckBox.Common, "OnClick", "CopyOnlyCheckBoxClick"
Set SwitchValuesButton = CreateButton(Form, "Switch Fields", 20, 75, 150, 20, Script.ScriptPath, "SwitchFields_Action")
SwitchValuesButton.Default = True
SwitchValuesButton.Common.ControlName = "SwitchValuesButton"
Set CloseButton = CreateButton(Form, "Close", 182, 75, 150, 20, "", "")
CloseButton.Cancel = True
CloseButton.ModalResult = 2
FillDropDownFromArray DropDownValueSwitch1, SongDataFields
FillDropDownFromArray DropDownValueSwitch2, SongDataFields
Form.showModal
End Sub
Sub CopyOnlyCheckBoxClick(CheckBox)
Dim Form, SwitchLabel
Set Form = CheckBox.Common.TopParent.Common
Set SwitchLabel = Form.ChildControl("SwitchLabel")
If CheckBox.Checked Then
SwitchLabel.Caption = "---->"
Else
SwitchLabel.Caption = "<-->"
End If
End Sub
'=============================
' SWITCH SPECIFIED FIELDS
'=============================
Sub SwitchFields_Action(Btn)
Dim DropDownValueSwitch1, DropDownValueSwitch2
Set DropDownValueSwitch1 = Btn.Common.Parent.Common.ChildControl("DropDownValueSwitch1")
Set DropDownValueSwitch2 = Btn.Common.Parent.Common.ChildControl("DropDownValueSwitch2")
Dim TempString
Dim MySongList
Set MySongList = SDB.Objects("MySongList")
Dim Form, CopyOnlyCheckBox
Set Form = Btn.Common.TopParent.Common
Set CopyOnlyCheckBox = Form.ChildControl("CopyOnlyCheckBox")
Dim CopyOnly
CopyOnly = CopyOnlyCheckBox.Checked
If ArrayContains(SongDataFields, DropDownValueSwitch1.Text) Then
If ArrayContains(SongDataFields, DropDownValueSwitch2.Text) Then
Dim i, MySong
For i = 0 To MySongList.Count - 1
Set MySong = MySongList.Item(i)
If CopyOnly Then
Execute("MySong." & DropDownValueSwitch2.Text & " = MySong." & DropDownValueSwitch1.Text)
Else
Execute("TempString = MySong." & DropDownValueSwitch1.Text)
Execute("MySong." & DropDownValueSwitch1.Text & " = MySong." & DropDownValueSwitch2.Text)
Execute("MySong." & DropDownValueSwitch2.Text & " = TempString")
End If
MySong.UpdateDB
If UpdateFileTags = True Then
MySong.WriteTags
End If
Next
If CopyOnly Then
SDB.MessageBox "Copied " & DropDownValueSwitch1.Text & " to " & DropDownValueSwitch2.Text & " tags.", mtInformation, Array(mbOK)
Else
SDB.MessageBox "Switched " & DropDownValueSwitch1.Text & " and " & DropDownValueSwitch2.Text & " tags.", mtInformation, Array(mbOK)
End If
End If
End If
End Sub
'=============================
' SOME UTILITY FUNCTIONS
'=============================
Function GetFileContents(FilePath)
GetFileContents = ""
Dim ForReading, TristateUseDefault
ForReading = 1
TristateUseDefault = -2
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FileExists(FilePath) Then Exit Function
Dim File
Set File = FSO.GetFile(FilePath)
Dim FileStream
Set FileStream = File.OpenAsTextStream(ForReading, TristateUseDefault)
GetFileContents = FileStream.ReadAll
End Function