Sample Read and Write Method(s)
From MMWiki
Revision as of 18:23, 20 April 2008; view current revision
←Older revision | Newer revision→
←Older revision | Newer revision→
|
[edit]
Instructions
- Copy the sample code into a text editor
- Replace highlighted terms with information from the items page in the Property Summary Table Title e.g.
- Value Name = Title
- Value Type = String
- Field Name = SongTitle
- Database Table = Songs
- Change the SelectMethod = 1 to a number corresponding to the select method required e.g.
- SelectMethod = 2 would use SQLQuery Method
- Comment all lines that DO NOT match the SelectMethod chosen by adding a single quote to the front of the line e.g. If SelectMethod was set as 3 all lines with 'SelectMethod not containing 2 would need to be commented out (or removed)
- ' For iCounter = 0 to objSongList.count - 1 'SelectMethod 4 SongLists
- Save the file as WikiSample.vbs in ...MediaMonkey\Scripts folder
- Edit the ...MediaMonkey\Scripts\Scripts.ini and add (copy/paste the section between '<-- Start ini code and '<--- End ini code) and save
- Start MM and select menu Tools --> Scripts --> WikiSample
Note: If Value Type = Object you will need to add the Member Name to the code e.g. ObjectAlbum = objSongData.Album.Member
[edit]
Sample Code
' ' MediaMonkey Script ' ' NAME: WikiSample.vbs ' ' Template Author: MoDementia ' Time, DATE : 22:31, 09 April 2008 ' 'Sample of Scripting Code Read and Write Method(s) 'A working script to show database results using various selection methods ' 'MediaMonkey\Scripts\Scripts.ini entry ' '<-- Start ini code '[WikiSample] 'Format of the Scripts.ini file 'Filename=WikiSample.vbs 'Procname=WikiSample 'Order=99 'DisplayName=WikiSample 'Description=Displays the raw database value of the MMWikipage item 'Language=VBScript 'ScriptType=0 '<-- End ini code Sub WikiSample Dim SelectMethod, SampleID, Value TypeNewValue Name Dim SQLString 'SelectMethod 3 Dim objSongList 'SelectMethod 2 SelectMethod = 1 ' SelectMethod NowPlaying = 1 ' SelectMethod UseSQLQuery = 2 ' SelectMethod UseSQL = 3 ' SelectMethod SelectedSongs = 4 ' SampleID = 13123 'Usualy Set in another part of the script 'Random SampleID Code (Remove if SampleID known) Set iter = SDB.Database.OpenSQL("SELECT DISTINCT Songs.ID FROM Songs ORDER BY RANDOM() Limit 1") While Not iter.EOF SampleID = iter.StringByIndex(0) iter.Next Wend 'End of random SampleID code Value TypeNewValue Name = "Mamma Mia" Set objSongList = SDB.NewSongList 'SelectMethod 2 and 3 SDB.NewSongList Select Case SelectMethod Case 1 Set objSongData = SDB.Player.CurrentSong 'SDB.Player.CurrentSong Case 2 Set objSongListiterator = SDB.Database.QuerySongs("AND Songs.ID=" & SampleID) 'SDB.Database.QuerySongs Case 3 SQLString = "SELECT Field Name FROM Database Table WHERE Database Table.ID = " & SampleID Set objSongStringiterator = SDB.Database.OpenSQL(SQLString) 'SDB.Database.OpenSQL Case 4 Set objSongList = SDB.SelectedSongList 'SDB.SelectedSongList ' Set objSongList = SDB.CurrentSongList 'SDB.CurrentSongList ' Set objSongList = SDB.AllVisibleSongList 'SDB.AllVisibleSongList Case Else SDB.MessageBox "Incorrect Select Method ", mtError, Array(mbOK) 'SDB.MessageBox Exit Sub End Select For iCounter = 0 to objSongList.count - 1 'SelectMethod 4 SongLists While Not objSongListiterator.EOF 'SelectMethod 2 Iterator While Not objSongStringiterator.EOF 'SelectMethod 3 Set objSongData = objSongListiterator.Item 'SelectMethod 2 objSongList.Add(objSongData) 'SelectMethod 2 Set objSongData = objSongList.Item(iCounter) 'SelectMethod 4 Value TypeValue Name = objSongData.Value Name 'SelectMethod 1, 2 and 4 SDB.MessageBox "Value = '" & Value TypeValue Name & "'", mtError, Array(mbOK) 'SelectMethod 4 (2 and 3) Value TypeValue Name = objSongStringiterator.StringByIndex(0) 'SelectMethod 3 objSongListiterator.Next 'SelectMethod 2 objSongStringiterator.Next 'SelectMethod 3 Wend 'SelectMethod 2 and 3 Next 'SelectMethod 4 Set objSongListiterator=Nothing 'SelectMethod 2 Set objSongStringiterator=Nothing 'SelectMethod 3 SDB.MessageBox "Value = '" & Value TypeValue Name & "'", mtError, Array(mbOK) ' objSongData.Value Name = Value TypeNewValue Name 'Commented Out For Safety 'SelectMethod 1, 2 and 4 ' objSonglist.UpdateAll 'Commented Out For Safety 'UpdateAll 'SelectMethod 1, 2 and 4 Updates db and writes tags (if checked in options) End Sub
[edit]
Converted Sample Method 2
' ' MediaMonkey Script ' ' NAME: WikiSample.vbs ' ' Template Author: MoDementia ' Time, DATE : 22:31, 09 April 2008 ' 'Sample of Scripting Code Read and Write Method(s) 'A working script to show database results using various selection methods ' 'MediaMonkey\Scripts\Scripts.ini entry ' '<-- Start ini code '[WikiSample] 'Format of the Scripts.ini file 'Filename=WikiSample.vbs 'Procname=WikiSample 'Order=99 'DisplayName=WikiSample 'Description=Displays the raw database value of the MMWikipage item 'Language=VBScript 'ScriptType=0 '<-- End ini code Sub WikiSample Dim SelectMethod, SampleID, StringNewTitle ' Dim SQLString 'SelectMethod 3 Dim objSongList 'SelectMethod 2 SelectMethod = 2 ' SelectMethod NowPlaying = 1 ' SelectMethod UseSQLQuery = 2 ' SelectMethod UseSQL = 3 ' SelectMethod SelectedSongs = 4 ' SampleID = 13123 'Usualy Set in another part of the script 'Random SampleID Code (Remove if SampleID known) Set iter = SDB.Database.OpenSQL("SELECT DISTINCT Songs.ID FROM Songs ORDER BY RANDOM() Limit 1") While Not iter.EOF SampleID = iter.StringByIndex(0) iter.Next Wend Set iter=Nothing 'End of random SampleID code StringNewTitle = "Mamma Mia" Set objSongList = SDB.NewSongList 'SelectMethod 2 and 3 SDB.NewSongList Select Case SelectMethod Case 1 Set objSongData = SDB.Player.CurrentSong 'SDB.Player.CurrentSong Case 2 Set objSongListiterator = SDB.Database.QuerySongs("AND Songs.ID=" & SampleID) 'SDB.Database.QuerySongs Case 3 SQLString = "SELECT SongTitle FROM Songs WHERE Songs.ID = " & SampleID Set objSongStringiterator = SDB.Database.OpenSQL(SQLString) 'SDB.Database.OpenSQL Case 4 Set objSongList = SDB.SelectedSongList 'SDB.SelectedSongList ' Set objSongList = SDB.CurrentSongList 'SDB.CurrentSongList ' Set objSongList = SDB.AllVisibleSongList 'SDB.AllVisibleSongList Case Else SDB.MessageBox "Incorrect Select Method ", mtError, Array(mbOK) 'SDB.MessageBox Exit Sub End Select ' For iCounter = 0 to objSongList.count - 1 'SelectMethod 4 SongLists While Not objSongListiterator.EOF 'SelectMethod 2 ' While Not objSongStringiterator.EOF 'SelectMethod 3 Set objSongData = objSongListiterator.Item 'SelectMethod 2 objSongList.Add(objSongData) 'SelectMethod 2 ' Set objSongData = objSongList.Item(iCounter) 'SelectMethod 4 StringTitle = objSongData.Title 'SelectMethod 1, 2 and 4 SDB.MessageBox "Value = '" & StringTitle & "'", mtError, Array(mbOK) 'SelectMethod 4 (2 and 3) ' StringTitle = objSongStringiterator.StringByIndex(0) 'SelectMethod 3 objSongListiterator.Next 'SelectMethod 2 ' objSongStringiterator.Next 'SelectMethod 3 Wend 'SelectMethod 2 and 3 ' Next 'SelectMethod 4 Set objSongListiterator=Nothing 'SelectMethod 2 ' Set objSongStringiterator=Nothing 'SelectMethod 3 SDB.MessageBox "Value = '" & StringTitle & "'", mtError, Array(mbOK) ' objSongData.Title = StringNewTitle 'Commented Out For Safety 'SelectMethod 1, 2 and 4 ' objSonglist.UpdateAll 'Commented Out For Safety 'UpdateAll 'SelectMethod 1, 2 and 4 Updates db and writes tags (if checked in options) End Sub
