after some small scripts for personal purpose I wrote my first script whie may be interesting for other guys ..
My aim is to get better tags. Scripts like personal tag enhancer and tagging inconsistencies helped me a lot, but I found that typos give pain to me.
Thus I wrote a little script which lead to typos in the authors name. Simply copy it to the auto-folder. It creates a node "Files to edit". Since the script is a little slooooowwww, it treats only songs from the main window.
Songs can be treated with drag and drop.
Hints to make the script faster are welcome

Here is the script, have fun:
Code: Select all
'
' MediaMonkey Script
'
' NAME: Typo 0.1
'
' AUTHOR: GuHu
' DATE : 01/18/08
'
'
' INSTALL: Copy to Scripts/auto directory
'
Option Explicit
Dim Max : Max=4 ' max distance
Dim d(180,180) ' matrix here and not in function for performance
Dim Tree, Node, Subnode, Artistnode,Sartistnode
Sub OnStartup
'add node
Set Tree = SDB.MainTree
Set Node = Tree.CreateNode
Node.Caption = SDB.Localize("Typos")
Node.IconIndex = 49
Tree.AddNode Tree.Node_FilesToEdit, Node, 2
Node.HasChildren = True
'add Artists
set Subnode = Tree.CreateNode
Subnode.Caption = SDB.Localize("Artists")
Subnode.IconIndex = 0
Subnode.UseScript = Script.ScriptPath
Subnode.OnFillChildren = "FillArtists"
Tree.AddNode Node, Subnode, 3
Subnode.HasChildren = True
set Sartistnode = Tree.CreateNode
End Sub
' some needed functions
' partly (c) from levenshtein.de
' converted from VB to VBA by GuHu
'
'*******************************
'*** Get minimum of three values
'*******************************
Private Function Minimum(a,b,c)
Dim mi
mi = a
If b < mi Then
mi = b
End If
If c < mi Then
mi = c
End If
Minimum = mi
End Function
'********************************
'*** Compute Levenshtein Distance
'********************************
Public Function LD(s,t)
''Dim d(90,90) ' matrix (not here for performance reasons)
Dim m ' length of t
Dim n ' length of s
Dim i ' iterates through s
Dim j ' iterates through t
Dim s_i ' ith character of s
Dim t_j ' jth character of t
Dim cost ' cost
Dim Min ' minimum
' Step 1
n = Len(s)
m = Len(t)
If n = 0 Then
LD = m
Exit Function
End If
If m = 0 Then
LD = n
Exit Function
End If
' Step 2
For i = 0 To n
d(i, 0) = i
Next
For j = 0 To m
d(0, j) = j
Next
' Step 3
For i = 1 To n
s_i = Mid(s, i, 1)
Min=180
' Step 4
For j = 1 To m
t_j = Mid(t, j, 1)
' Step 5
If s_i = t_j Then
cost = 0
Else
cost = 1
End If
' Step 6
d(i, j) = Minimum(d(i - 1, j) + 1, d(i, j - 1) + 1, d(i - 1, j - 1) + cost)
if Min>d(i,j) then
Min=d(i,j)
end if
Next
if not (Min<Max) then
LD=Min
exit function
end if
Next
' Step 7
LD = d(n, m)
'' Erase d (for performance reasons)
End Function
Sub FillTracks(Node)
Dim sql,Tracks
Set Tracks = SDB.MainTracksWindow
sql = "WHERE Songs.Artist = """ & Node.Caption & """"
Tracks.AddTracksFromQuery(sql)
Tracks.FinishAdding
End Sub
Function TrackDragDrop( destNode, srcNode, SongList, DropType, Test)
if Test then
TrackDragDrop = 2
else
Dim i, itm
For i=0 To SongList.Count-1
Set itm = SongList.Item(i)
if itm.ArtistName=itm.AlbumArtistName then
itm.AlbumArtistName = destNode.Caption
end if
itm.ArtistName = destNode.Caption
itm.UpdateDB
itm.UpdateArtist
Next
end if
End Function
Sub FillArtists(Subnode)
Dim list,artlist,i,j,art1,art2,dd,a1,a2,res,isnode
Dim Progress
Set Tree = SDB.MainTree
'Set list = SDB.CurrentSongList
Set list = SDB.AllVisibleSongList
Set artlist = list.Artists
Set Progress = SDB.Progress
Progress.Text = SDB.Localize("Find similar Artists ...")
Progress.MaxValue = artlist.count
for i= 0 to artlist.count - 1
Progress.Value = i+1
if Progress.Terminate then
exit for
end if
set art1=artlist.item(i)
a1=art1.Name
isnode = False
for j=i+1 to artlist.count-1
set art2=artlist.item(j)
a2=art2.Name
dd=LD(a1,a2)
if (dd < Minimum(Max,Len(a1)*0.5,Len(a2)*0.5)) then
if Not (isnode) then
isnode=True
Set Artistnode = Tree.CreateNode
Artistnode.Caption = a1
Tree.AddNode Subnode, Artistnode, 3
Artistnode.HasChildren = True
Set Sartistnode = Tree.CreateNode
Sartistnode.Caption = a1
Sartistnode.OnDragDrop = "TrackDragDrop"
Sartistnode.OnFillTracksFunct = "FillTracks"
Sartistnode.UseScript = Script.ScriptPath
Tree.AddNode Artistnode, Sartistnode, 3
end if
Set Sartistnode = Tree.CreateNode
Sartistnode.Caption = a2
Sartistnode.OnDragDrop = "TrackDragDrop"
Sartistnode.OnFillTracksFunct = "FillTracks"
Sartistnode.UseScript = Script.ScriptPath
Tree.AddNode Artistnode, Sartistnode, 3
end if
next
next
End Sub