Code: Select all
'MoveFirstWord (version 2)
'moves first word in artist to last.
'examples: The Beatles --> Beatles, The
' Jon Anderson --> Anderson, Jon
'written by Roy DeRousse, 3/16/2004
'feel free to use "as is" or borrow and modify code. user assumes all risks.
'QuoteString: Formats a string for use with Access SQL
'Surrounds a string with tics and replaces embedded tics with double tics
Const QuoteChar = "'"
QS = QuoteChar & Replace(UnquotedString, QuoteChar, QuoteChar & QuoteChar) & QuoteChar
Dim list, itm, i, ParsedArray, sql, NewName
'Get list of selected tracks from MediaMonkey
Set list = SDB.SelectedSongList
If list.count=0 Then
Set list = SDB.AllVisibleSongList
'Process all selected tracks
For i=0 To list.count-1
Set itm = list.Item(i)
'get the first two pieces of artistname that are separated by one or more spaces
ParsedArray = split(trim(itm.ArtistName), " ", 2)
if ubound(ParsedArray, 1) = 1 then
'two pieces returned. reformat ArtistName
NewName = ParsedArray(1) & ", " & ParsedArray(0)
'must use sql because itm.UpdateDB does not update the album artist field
sql = "UPDATE Artists SET Artists.Artist = " & qs(NewName) & " WHERE Artists.Artist= " & qs(itm.ArtistName)
SDB.database.execSQL(sql) '//find some way to not do this each time
'the following code would refresh the screen entry for artist, but
'- album artist would still not refreshed (although really updated in DB if album artist = artist)
'- it doesn't change the (mp3) file's tag like i was expecting
'therefore, i have commented out the code since it may cause more confusion than it's worth
'itm.ArtistName = NewName 'needed so that itm.updatedb knows that it needs to do something
msgbox "Be sure to refresh (F5) & synchronize tags" 'you may wish to remove this line
Pablo, I decided to use SQL after all! Updating the Artists table directly changes the artist name for both the song and the album if both were the same to begin with. Although the script is fully functional now, there are some things that I don't like about it:
- MP3 tags aren't updated. I thought that itm.UpdateDB would also update the tags if the "Update tags immediately after editting properties" option was turned on, but that is not true. Does anyone know how to really update tags via scripting?
- The script tries to update artist name for each song selected. This doesn't hurt anything, because there is nothing to change after the first time, but I hate to do the extra processing. I could put the artists changed in a table and check the table before trying another update, but that would take more code and probably be just as inefficient as what I'm doing now.
- The song list doesn't get refreshed automatically. I could use UpdateDB to do it, but it only shows the changed Artist name, and the Album Artist stays the same. I decided that it would be less confusing not to refresh it at all.
Even with those gripes, the script is at least useable now. All comments and suggestions are welcome.