In progress: Search & Replace

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: In progress: Search & Replace

by jaxjon » Thu Mar 25, 2004 10:52 am

I would like to be able to do search and replace without having to have all songs visible or selected. Is there a way to search songs and display those that meet the search criteria, then do replace? I like the idea though. Thanks for posting it.

Jon

by farallon » Thu Mar 25, 2004 7:12 am

Sounds promissing! (I'm starting to like VBScript, and I've already got some ideas.....)
I've fixed some errors you got when pressing cancel or leaving the box empty. It now simply exits when this occurs, instead of producing error messages :oops:.

by jiri » Thu Mar 25, 2004 6:36 am

Thanks for sharing the script. As for custom dialogs - no, there currently isn't a way how to show them, only simple input boxes are possible. However, it's planned add some new objects that would allow scripts and plug-ins to create their own dialogs and interact with them. However, thanks to its complexity, it will take some time until it's implemented.

Jiri

In progress: Search & Replace

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

Top