by farallon » Thu Mar 25, 2004 5:57 am
I've been looking for a Search and Replace function in MM, but the omly place I found it was in the Wishlist. So I decided to write a little script for it.
It's working correct right now, but I'dd like to know if there is a way to make a custom input screen with s&r fields and boxes where you can select which tags you want to edit. Just to make it a bit more user-friendly, rather than having a huge list of options in yout scripts tab.
SearchReplace.vbs:
Code: Select all
' Script for Search and Replace function.
' I only know Perl, so most of the credit goes to Jiri and Toby Gramm
' The other part (pressing Ctrl-C and Ctrl-V multiple times) goes to me :-)
Function SearchAndReplace(s, Str1, Str2)
Dim pos
s = s & "" 'Fix Null
pos = InStr(s, Str1)
While pos > 0
s = Mid(s, 1, pos - 1) & Str2 & Mid(s, pos + Len(Str1))
pos = InStr(pos, s, Str1)
Wend
SearchAndReplace = s
End Function
Sub SRArtist
' Define variables
Dim list, itm, i, tmp, search, replace, s
search = inputbox("Search:", "Search")
If search = "" Then
Exit Sub
End If
replace = inputbox("Replace With:", "Replace")
If replace = "" 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)
itm.ArtistName = SearchAndReplace(itm.ArtistName,search,replace)
' Update the changes in DB
itm.UpdateDB
Next
End Sub
Sub SRTitle
' Define variables
Dim list, itm, i, tmp, search, replace, s
search = inputbox("Search:", "Search")
If search = "" Then
Exit Sub
End If
replace = inputbox("Replace With:", "Replace")
If replace = "" 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)
itm.Title = SearchAndReplace(itm.Title,search,replace)
' Update the changes in DB
itm.UpdateDB
Next
End Sub
Sub SRGenre
' Define variables
Dim list, itm, i, tmp, search, replace, s
search = inputbox("Search:", "Search")
If search = "" Then
Exit Sub
End If
replace = inputbox("Replace With:", "Replace")
If replace = "" 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)
itm.Genre = SearchAndReplace(itm.Genre,search,replace)
' Update the changes in DB
itm.UpdateDB
Next
End Sub
Sub SRAlbum
' Define variables
Dim list, itm, i, tmp, search, replace, s
search = inputbox("Search:", "Search")
If search = "" Then
Exit Sub
End If
replace = inputbox("Replace With:", "Replace")
If replace = "" 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)
itm.itm.AlbumName = SearchAndReplace(itm.itm.AlbumName,search,replace)
' Update the changes in DB
itm.UpdateDB
Next
End Sub
Sub SRAll
' Define variables
Dim list, itm, i, tmp, search, replace, s
search = inputbox("Search:", "Search")
If search = "" Then
Exit Sub
End If
replace = inputbox("Replace By:", "Replace")
If replace = "" 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)
itm.ArtistName = SearchAndReplace(itm.ArtistName,search,replace)
itm.Title = SearchAndReplace(itm.Title,search,replace)
itm.Genre = SearchAndReplace(itm.Genre,search,replace)
itm.AlbumName = SearchAndReplace(itm.AlbumName,search,replace)
' Update the changes in DB
itm.UpdateDB
Next
End Sub
And the scripts.ini addition:
Code: Select all
[SRAlbum]
FileName=SearchReplace.vbs
ProcName=SRAlbum
order=5
DisplayName=Album Search and Replace
Description=Album Search and Replace
Language=VBScript
ScriptType=0
[SRArtist]
FileName=SearchReplace.vbs
ProcName=SRArtist
order=6
DisplayName=Artist Search and Replace
Description=Artist Search and Replace
Language=VBScript
ScriptType=0
[SRGenre]
FileName=SearchReplace.vbs
ProcName=SRGenre
order=7
DisplayName=Genre Search and Replace
Description=Genre Search and Replace
Language=VBScript
ScriptType=0
[SRTitle]
FileName=SearchReplace.vbs
ProcName=SRTitle
order=8
DisplayName=Title Search and Replace
Description=Title Search and Replace
Language=VBScript
ScriptType=0
[SRAll]
FileName=SearchReplace.vbs
ProcName=SRAll
order=9
DisplayName=Search and Replace All
Description=Search and Replace All
Language=VBScript
ScriptType=0
I've been looking for a Search and Replace function in MM, but the omly place I found it was in the Wishlist. So I decided to write a little script for it.
It's working correct right now, but I'dd like to know if there is a way to make a custom input screen with s&r fields and boxes where you can select which tags you want to edit. Just to make it a bit more user-friendly, rather than having a huge list of options in yout scripts tab.
SearchReplace.vbs:
[code]
' Script for Search and Replace function.
' I only know Perl, so most of the credit goes to Jiri and Toby Gramm
' The other part (pressing Ctrl-C and Ctrl-V multiple times) goes to me :-)
Function SearchAndReplace(s, Str1, Str2)
Dim pos
s = s & "" 'Fix Null
pos = InStr(s, Str1)
While pos > 0
s = Mid(s, 1, pos - 1) & Str2 & Mid(s, pos + Len(Str1))
pos = InStr(pos, s, Str1)
Wend
SearchAndReplace = s
End Function
Sub SRArtist
' Define variables
Dim list, itm, i, tmp, search, replace, s
search = inputbox("Search:", "Search")
If search = "" Then
Exit Sub
End If
replace = inputbox("Replace With:", "Replace")
If replace = "" 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)
itm.ArtistName = SearchAndReplace(itm.ArtistName,search,replace)
' Update the changes in DB
itm.UpdateDB
Next
End Sub
Sub SRTitle
' Define variables
Dim list, itm, i, tmp, search, replace, s
search = inputbox("Search:", "Search")
If search = "" Then
Exit Sub
End If
replace = inputbox("Replace With:", "Replace")
If replace = "" 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)
itm.Title = SearchAndReplace(itm.Title,search,replace)
' Update the changes in DB
itm.UpdateDB
Next
End Sub
Sub SRGenre
' Define variables
Dim list, itm, i, tmp, search, replace, s
search = inputbox("Search:", "Search")
If search = "" Then
Exit Sub
End If
replace = inputbox("Replace With:", "Replace")
If replace = "" 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)
itm.Genre = SearchAndReplace(itm.Genre,search,replace)
' Update the changes in DB
itm.UpdateDB
Next
End Sub
Sub SRAlbum
' Define variables
Dim list, itm, i, tmp, search, replace, s
search = inputbox("Search:", "Search")
If search = "" Then
Exit Sub
End If
replace = inputbox("Replace With:", "Replace")
If replace = "" 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)
itm.itm.AlbumName = SearchAndReplace(itm.itm.AlbumName,search,replace)
' Update the changes in DB
itm.UpdateDB
Next
End Sub
Sub SRAll
' Define variables
Dim list, itm, i, tmp, search, replace, s
search = inputbox("Search:", "Search")
If search = "" Then
Exit Sub
End If
replace = inputbox("Replace By:", "Replace")
If replace = "" 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)
itm.ArtistName = SearchAndReplace(itm.ArtistName,search,replace)
itm.Title = SearchAndReplace(itm.Title,search,replace)
itm.Genre = SearchAndReplace(itm.Genre,search,replace)
itm.AlbumName = SearchAndReplace(itm.AlbumName,search,replace)
' Update the changes in DB
itm.UpdateDB
Next
End Sub
[/code]
And the scripts.ini addition:
[code]
[SRAlbum]
FileName=SearchReplace.vbs
ProcName=SRAlbum
order=5
DisplayName=Album Search and Replace
Description=Album Search and Replace
Language=VBScript
ScriptType=0
[SRArtist]
FileName=SearchReplace.vbs
ProcName=SRArtist
order=6
DisplayName=Artist Search and Replace
Description=Artist Search and Replace
Language=VBScript
ScriptType=0
[SRGenre]
FileName=SearchReplace.vbs
ProcName=SRGenre
order=7
DisplayName=Genre Search and Replace
Description=Genre Search and Replace
Language=VBScript
ScriptType=0
[SRTitle]
FileName=SearchReplace.vbs
ProcName=SRTitle
order=8
DisplayName=Title Search and Replace
Description=Title Search and Replace
Language=VBScript
ScriptType=0
[SRAll]
FileName=SearchReplace.vbs
ProcName=SRAll
order=9
DisplayName=Search and Replace All
Description=Search and Replace All
Language=VBScript
ScriptType=0
[/code]