von chyron8472 » Mo Apr 22, 2013 4:25 pm
So...
from the RegExpReplace.vbs, I found:
Code: Alles auswählen
Function RegSub(sExpr, sPattern, sReplace)
Dim RE2
Set RE2 = New RegExp
RE2.Pattern = sPattern
RE2.Global = True
If bMatchCase Then
RE2.IgnoreCase = False
Else
RE2.IgnoreCase = True
End If
RegSub = RE2.Replace(sExpr, sReplace)
End Function
"[...later in file]
"<td><code>RegSub(string, pattern, replace)</code></td>" & _
"<td>Performs substitution based on pattern matching. Preset example: ""Copy the Artist name to the Custom 3 field..."".</td>" & _
Which seems to me to be the code for manually doing what I want.
And the code for that CleanImport.vbs, which runs on adding a new track, is:
Code: Alles auswählen
Option Explicit
Const SCRIPT_NAME = "CleanImport"
Dim AllowCleaning
Dim OptionSheetID
Dim Fields
Dim EmptyValues
Dim ClearByDefault
Dim ClearByChoice
Sub OnStartup
Fields = Array("Author", "Band", "Conductor", "InvolvedPeople", "Grouping", "Bookmark", "Genre", "Comment", "Lyrics", "Rating", "RatingString", "Tempo", "Quality", "Occasion", "Mood", "Publisher", "ISRC", "Encoder", "Copyright", "Lyricist", "OriginalLyricist")
EmptyValues = Array("","","","","","0","","","","-1","","","","","","","","","","","")
ClearByDefault = Array(True, True, True, True, True, True, False, True, False, True, True, True, True, True, True, True, True, True, True, True, True)
ClearByChoice = ClearByDefault
Dim i
For i = 0 To UBound(Fields)
If Not SDB.IniFile.ValueExists(SCRIPT_NAME, "Clear_" & Fields(i)) Then
SDB.IniFile.BoolValue(SCRIPT_NAME, "Clear_" & Fields(i)) = ClearByDefault(i)
Else
ClearByChoice(i) = SDB.IniFile.BoolValue(SCRIPT_NAME, "Clear_" & Fields(i))
End If
Next
If SDB.IniFile.BoolValue(SCRIPT_NAME, "AlwaysAllowCleaning") = True Then AllowCleaning = True
Script.RegisterEvent SDB, "OnTrackAdded", "CleanImportedTags"
OptionSheetID = SDB.UI.AddOptionSheet("CleanImport", Script.ScriptPath, "InitSheet1", "SaveSheet1", -3)
End Sub
Sub CleanImportedTags(NewTrack)
Dim Msg
Msg = "Allow the CleanImport script to clean out the tags specified in the options?" & vbNewLine & _
vbNewLine & _
" Yes: Yes for now. Ask me again next session." & vbNewLine & _
"Yes To All: Yes, and don't ask me again." & vbNewLine & _
" No: No for now. Ask me again next session."
If IsEmpty(AllowCleaning) Then
Dim Result : Result = SDB.MessageBox(Msg, mtWarning, Array(mbYesToAll,mbYes,mbNo))
If Result = mrYesToAll Then
SDB.IniFile.BoolValue(SCRIPT_NAME, "AlwaysAllowCleaning") = True
AllowCleaning = True
ElseIf Result = mrYes Then
AllowCleaning = True
Else
AllowCleaning = False
End If
End If
If Not AllowCleaning Then Exit Sub
Dim i
For i = 0 To UBound(Fields)
If ClearByChoice(i) Then Execute("NewTrack." & Fields(i) & " = """ & EmptyValues(i) & """")
Next
NewTrack.UpdateDB
End Sub
Sub InitSheet1(Sheet1)
Dim Label1 : Set Label1 = SDB.UI.NewLabel(Sheet1)
Label1.Common.SetRect 18,27,500,17
Label1.Common.ControlName = "Label1"
Label1.Caption = "When adding a new track to MediaMonkey, clear the following fields:"
Dim i, chk, xpos, ypos
xpos = 40
ypos = 60
For i = 0 To UBound(Fields)
Set chk = SDB.UI.NewCheckBox(Sheet1)
chk.Caption = Fields(i)
chk.Checked = ClearByChoice(i)
chk.Common.SetRect xpos,ypos,100,20
chk.Common.ControlName = "Clear_" & Fields(i)
ypos = ypos + 20
If ypos > 300 Then
ypos = 60
xpos = xpos + 150
End If
Next
Dim chk2
Set chk2 = SDB.UI.NewCheckBox(Sheet1)
chk2.Caption = "Ask confirmation before clearing the fields."
chk2.Checked = IsEmpty(AllowCleaning)
chk2.Common.SetRect 60,360,400,20
chk2.Common.ControlName = "AskConfirmation"
End Sub
Sub SaveSheet1(Sheet1)
Dim i
For i = 0 To UBound(Fields)
If Sheet1.Common.ChildControl("Clear_" & Fields(i)).Checked <> ClearByChoice(i) Then
ClearByChoice(i) = Not ClearByChoice(i)
SDB.IniFile.BoolValue(SCRIPT_NAME, "Clear_" & Fields(i)) = ClearByChoice(i)
End If
Next
If Sheet1.Common.ChildControl("AskConfirmation").Checked Then
AllowCleaning = Empty
SDB.IniFile.BoolValue(SCRIPT_NAME, "AlwaysAllowCleaning") = False
Else
AllowCleaning = True
End If
End Sub
Sub Uninstall
DoCleanup
Dim MsgDeleteSettings : MsgDeleteSettings = "Uninstalling " & SCRIPT_NAME & "." & vbNewLine & _
"Do you want to remove the settings as well?" & vbNewLine & _
"If you click No, script settings will be left in MediaMonkey.ini"
If (Not SDB.IniFile Is Nothing) and (MsgBox(MsgDeleteSettings, vbYesNo, SCRIPT_NAME) = vbYes) Then
SDB.IniFile.DeleteSection(SCRIPT_NAME)
End If
End Sub
Sub DoCleanup
If IsEmpty(OptionSheetID) Then Exit Sub
SDB.UI.DeleteOptionSheet OptionSheetID
Script.UnRegisterAllEvents
End Sub
What do I pull out of that to get what I want? I'm not really that adept at coding.
[quote="nohitter151"][quote="chyron8472"]Well, the wiki does say how to have a script run each time on startup:
http://www.mediamonkey.com/wiki/index.php/Introduction_to_scripting#How_to_create_an_auto-script
But I don't need it to run on all files every time I open MM.
Is there a way to have a script automatically be performed on a file when I add it to the Library?[/quote]
Yes, if you're looking for example code you could find it from this script: http://www.mediamonkey.com/forum/viewtopic.php?f=2&t=58546&p=354440#p300742[/quote]
So...
from the RegExpReplace.vbs, I found:
[code]Function RegSub(sExpr, sPattern, sReplace)
Dim RE2
Set RE2 = New RegExp
RE2.Pattern = sPattern
RE2.Global = True
If bMatchCase Then
RE2.IgnoreCase = False
Else
RE2.IgnoreCase = True
End If
RegSub = RE2.Replace(sExpr, sReplace)
End Function
"[...later in file]
"<td><code>RegSub(string, pattern, replace)</code></td>" & _
"<td>Performs substitution based on pattern matching. Preset example: ""Copy the Artist name to the Custom 3 field..."".</td>" & _[/code]
Which seems to me to be the code for manually doing what I want.
And the code for that CleanImport.vbs, which runs on adding a new track, is:
[code]Option Explicit
Const SCRIPT_NAME = "CleanImport"
Dim AllowCleaning
Dim OptionSheetID
Dim Fields
Dim EmptyValues
Dim ClearByDefault
Dim ClearByChoice
Sub OnStartup
Fields = Array("Author", "Band", "Conductor", "InvolvedPeople", "Grouping", "Bookmark", "Genre", "Comment", "Lyrics", "Rating", "RatingString", "Tempo", "Quality", "Occasion", "Mood", "Publisher", "ISRC", "Encoder", "Copyright", "Lyricist", "OriginalLyricist")
EmptyValues = Array("","","","","","0","","","","-1","","","","","","","","","","","")
ClearByDefault = Array(True, True, True, True, True, True, False, True, False, True, True, True, True, True, True, True, True, True, True, True, True)
ClearByChoice = ClearByDefault
Dim i
For i = 0 To UBound(Fields)
If Not SDB.IniFile.ValueExists(SCRIPT_NAME, "Clear_" & Fields(i)) Then
SDB.IniFile.BoolValue(SCRIPT_NAME, "Clear_" & Fields(i)) = ClearByDefault(i)
Else
ClearByChoice(i) = SDB.IniFile.BoolValue(SCRIPT_NAME, "Clear_" & Fields(i))
End If
Next
If SDB.IniFile.BoolValue(SCRIPT_NAME, "AlwaysAllowCleaning") = True Then AllowCleaning = True
Script.RegisterEvent SDB, "OnTrackAdded", "CleanImportedTags"
OptionSheetID = SDB.UI.AddOptionSheet("CleanImport", Script.ScriptPath, "InitSheet1", "SaveSheet1", -3)
End Sub
Sub CleanImportedTags(NewTrack)
Dim Msg
Msg = "Allow the CleanImport script to clean out the tags specified in the options?" & vbNewLine & _
vbNewLine & _
" Yes: Yes for now. Ask me again next session." & vbNewLine & _
"Yes To All: Yes, and don't ask me again." & vbNewLine & _
" No: No for now. Ask me again next session."
If IsEmpty(AllowCleaning) Then
Dim Result : Result = SDB.MessageBox(Msg, mtWarning, Array(mbYesToAll,mbYes,mbNo))
If Result = mrYesToAll Then
SDB.IniFile.BoolValue(SCRIPT_NAME, "AlwaysAllowCleaning") = True
AllowCleaning = True
ElseIf Result = mrYes Then
AllowCleaning = True
Else
AllowCleaning = False
End If
End If
If Not AllowCleaning Then Exit Sub
Dim i
For i = 0 To UBound(Fields)
If ClearByChoice(i) Then Execute("NewTrack." & Fields(i) & " = """ & EmptyValues(i) & """")
Next
NewTrack.UpdateDB
End Sub
Sub InitSheet1(Sheet1)
Dim Label1 : Set Label1 = SDB.UI.NewLabel(Sheet1)
Label1.Common.SetRect 18,27,500,17
Label1.Common.ControlName = "Label1"
Label1.Caption = "When adding a new track to MediaMonkey, clear the following fields:"
Dim i, chk, xpos, ypos
xpos = 40
ypos = 60
For i = 0 To UBound(Fields)
Set chk = SDB.UI.NewCheckBox(Sheet1)
chk.Caption = Fields(i)
chk.Checked = ClearByChoice(i)
chk.Common.SetRect xpos,ypos,100,20
chk.Common.ControlName = "Clear_" & Fields(i)
ypos = ypos + 20
If ypos > 300 Then
ypos = 60
xpos = xpos + 150
End If
Next
Dim chk2
Set chk2 = SDB.UI.NewCheckBox(Sheet1)
chk2.Caption = "Ask confirmation before clearing the fields."
chk2.Checked = IsEmpty(AllowCleaning)
chk2.Common.SetRect 60,360,400,20
chk2.Common.ControlName = "AskConfirmation"
End Sub
Sub SaveSheet1(Sheet1)
Dim i
For i = 0 To UBound(Fields)
If Sheet1.Common.ChildControl("Clear_" & Fields(i)).Checked <> ClearByChoice(i) Then
ClearByChoice(i) = Not ClearByChoice(i)
SDB.IniFile.BoolValue(SCRIPT_NAME, "Clear_" & Fields(i)) = ClearByChoice(i)
End If
Next
If Sheet1.Common.ChildControl("AskConfirmation").Checked Then
AllowCleaning = Empty
SDB.IniFile.BoolValue(SCRIPT_NAME, "AlwaysAllowCleaning") = False
Else
AllowCleaning = True
End If
End Sub
Sub Uninstall
DoCleanup
Dim MsgDeleteSettings : MsgDeleteSettings = "Uninstalling " & SCRIPT_NAME & "." & vbNewLine & _
"Do you want to remove the settings as well?" & vbNewLine & _
"If you click No, script settings will be left in MediaMonkey.ini"
If (Not SDB.IniFile Is Nothing) and (MsgBox(MsgDeleteSettings, vbYesNo, SCRIPT_NAME) = vbYes) Then
SDB.IniFile.DeleteSection(SCRIPT_NAME)
End If
End Sub
Sub DoCleanup
If IsEmpty(OptionSheetID) Then Exit Sub
SDB.UI.DeleteOptionSheet OptionSheetID
Script.UnRegisterAllEvents
End Sub[/code]
What do I pull out of that to get what I want? I'm not really that adept at coding.