SwitchOrCopyFields: Switches or Copies song data fields

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

Moderators: Peke, Gurus

Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

SwitchOrCopyFields: Switches or Copies song data fields

Post by Steegy »

SwitchOrCopyFields' own forum post.

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... :wink: )


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
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
Macarena
Posts: 642
Joined: Mon Oct 15, 2007 5:39 am
Location: Prague, Czech republic

Post by Macarena »

Hi,

using MM3, up to date. how can I play around with the <Path> tag stored in the library, too? I would like to store the path in <Custom 1>, let say...
latinmusiclover
Posts: 183
Joined: Tue Feb 27, 2007 11:31 pm

Problem With Switch or Copy Fields in MM3

Post by latinmusiclover »

Problem With Switch or Copy Fields in MM3
In MM2.5 you could type the first few letters of the field in the list box and the script filled in the field name. For example, "mo" gave you "Mood", "cu" gave you "Custom1". Then you clicked on "Switch" and the script worked.

In MM3, I noticed the following behaviour:
If you type the first few letter (as in the example above), you get the field names, but when you click on "Switch" nothing happens. By testing I found that you have to have the field name EXACTLY as it appears in the list. So, in the above example, you have to start with an upper-case "M" and "C", or you have to scroll down and select the field name.

I also noticed that in MM2.5 when you typed the first letter you could "arrow down" to the field name. For example, "M" gave "Medialabel". Then I used the arrow down to go to "Mood". In MM3, if you type the first letter then press the down arrow, the list goes back to the top of the list (begins with "A")
coolmalayalee
Posts: 30
Joined: Thu May 31, 2007 4:26 pm

Post by coolmalayalee »

Thanks. I installed it following the exact directions. I use MM3 in Windows Vista. When I execute the script I get the following error. I am also posting in the original script thread you pointed out.

Image

Can you help me figure out what is the problem?
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Post by nynaevelan »

When you installed the script, did you also install the two complimentary scripts listed in first post??

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
coolmalayalee
Posts: 30
Joined: Thu May 31, 2007 4:26 pm

Post by coolmalayalee »

Yes I did.
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Post by nynaevelan »

That line is referencing the Scripts\Utility_General.vbs script, did you name it exactly as it is in the switchorcopy script?

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
coolmalayalee
Posts: 30
Joined: Thu May 31, 2007 4:26 pm

Post by coolmalayalee »

It is exactly named as such.... those files I downloaded and saved directly into the scripts folder without any changes... and I checked it again.. the names are exactly as it is..
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Post by nynaevelan »

I think we are going to have to wait for Steegy or one of the other experts. One other suggestion, are you running MM as an administrator? Try closing it, going to Windows Explorer, navigating to the MM folder, right clicking on the mediamonkey.exe file and selecting run as administrator. I read in one of the other forums that this may resolve the permission issues. You could also try it with UAC turned off. I'm not sure if this is what is preventing the script from running because I always run it with UAC off. I think it was Spacefish who stated once you run MM one time as an administrator, the problems are resolved.

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
coolmalayalee
Posts: 30
Joined: Thu May 31, 2007 4:26 pm

Post by coolmalayalee »

I just switched of MM and restarted it as administrator. The problem still exists. I also downloaded and replaced the Utility_General and Utility_Controls again just in case... and the problem still persist...
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Post by nynaevelan »

I'm afraid I am out of my league, sorry :oops:

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
coolmalayalee
Posts: 30
Joined: Thu May 31, 2007 4:26 pm

Post by coolmalayalee »

No problem.. I will wait for someone else to respond... thank you so much for your response though.. I really appreciate that..
nohitter151
Posts: 23640
Joined: Wed Aug 09, 2006 10:20 am
Location: NJ, USA
Contact:

Post by nohitter151 »

coolmalayalee wrote:No problem.. I will wait for someone else to respond... thank you so much for your response though.. I really appreciate that..
I think I know the problem. If you click the links above and just download the files (instead of going manually and copying/pasting), you will download the wrong thing because the links are pointing to the wrong location.

Try these links instead:
http://home.scarlet.be/ruben.castelein/ ... ntrols.vbs
http://home.scarlet.be/ruben.castelein/ ... eneral.vbs
MediaMonkey user since 2006
Need help? Got a suggestion? Can't find something?

Please no PMs in reply to a post. Just reply in the thread.
coolmalayalee
Posts: 30
Joined: Thu May 31, 2007 4:26 pm

Post by coolmalayalee »

nohitter151 wrote: I think I know the problem. If you click the links above and just download the files (instead of going manually and copying/pasting), you will download the wrong thing because the links are pointing to the wrong location.

Try these links instead:
http://home.scarlet.be/ruben.castelein/ ... ntrols.vbs
http://home.scarlet.be/ruben.castelein/ ... eneral.vbs
Thanks.. it now works perfect... !!! Thanks for your help..
grayflannelsuit
Posts: 13
Joined: Sun Sep 30, 2007 12:29 pm
Contact:

Post by grayflannelsuit »

Great script! One small problem though - if I copy from Year to OriginalYear and the Year field has a date like 8/8/78, only the four-digit year gets copied.
Image
Post Reply