Search scripts

From MediaMonkey Wiki
Jump to navigation Jump to search

Search scripts let developers to plug-in new search types into Auto-tag from Web dialog (formerly Auto-tag from Amazon). You can learn most about them from a well commented Sample AMG Search script. This script type was introduced in MediaMonkey 3.0.

Search script basics

Each search script must be in a separate file (usually .vbs) and must contain several procedures that MediaMonkey calls. The script remains loaded in memory during the whole life of searching (i.e. starting from initialization of a search until user choosed different search method or searches for something else). Therefore you can use global script variables and keep values in them among calls to the procedures of script.

Each search script must be included in Scripts.ini file and designated as ScriptType=3.

Search script structure

Each search script must contain several procedures so that it can properly respond to what user and MediaMonkey want from it. The required procedures are:

Sub StartSearch( Panel, SearchTerm, SearchArtist, SearchAlbum)

This procedure initializes the whole search. It's called only once when search is started. Its parameters are:

Object of SDBUITranspPanel where you can place the controls showing results. Usually, e.g. in Sample AMG Search script, it is SDBUIActiveX control containing a web browser.
The term user searches for. In case the search string wasn't entered by the user, it's a compilation of Artist and Album values (with some useless characters removed).
Artist extracted from tracks that are being search for. In case the search is initiated by user entering a search string, this value is empty.
Album extracted from tracks that are being search for. In case the search is initiated by user entering a search string, this value is empty.

In case you need details about the tracks that are being searched, use ISDBWebSearch::NewTracks property to access individual tracks.

When search results are returned, you should use ISDBWebSearch::SetSearchResults to let MediaMonkey know about it.

Sub ShowResult( ResultID)

This procedure is called whenever user changes the result to be shown in the top panel drop-down control, i.e. when another album should be shown. This is also called automatically right after ISDBWebSearch::SetSearchResults is called, in such case ResultID is 0, indicating that the very first search result should be shown, otherwise it contains the index of search result to be shown (up to number of results set by ISDBWebSearch::SetSearchResults).

This procedure also has to indicate to MediaMonkey how fields would be changed in case user presses Auto-tag button. Use ISDBWebSearch::SmartUpdateTracks, ISDBWebSearch::NewTracks, ISDBWebSearch::AlbumArtURL and ISDBWebSearch::RefreshViews methods for this purpose.

Sub FinishSearch( Panel)

This procedure is called when this search script should terminate all its actions and destroy all created user interface elements. Panel parameter is the same as in case of StartSearch procedure.

Some existing scripts