New script: Moves first word in artist to last

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

roylayer
Posts: 85
Joined: Tue Feb 25, 2003 12:44 am

New script: Moves first word in artist to last

Post by roylayer » Sun Mar 14, 2004 1:20 am

Note: Please see later version(s) of this script in later notes.

Code: Select all

'moves first word in artist to last.  
'example: The Beatles --> Beatles, The
'         Bob Dylan --> Dylan, Bob

Sub MoveFirstWord  
  ' Define variables
  Dim list, itm, i, ParsedArray

  ' 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)
    '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
      itm.ArtistName = ParsedArray(1) & ", " & ParsedArray(0)
      itm.UpdateDB
    end if
  Next
End Sub
This works fine, but it doesn't do anything to the Album Artist. If the Album Artist = the Song Artist, or if the Album Artist is blank, I want to set the Album Artist equal to the same thing that the Song Artist was set to. (Actually, I was hoping that MM would do this for me since it does something similiar when you edit Song properties interactively. Oh well...) Does anyone know how to access the Album Artist field? I tried itm.album.artist.name, but that gives me the same thing as itm.artistname.

I also plan to build the inverse of this script, MoveLastWord, to convert from a "Dylan, Bob" format to a "Bob Dylan" format once I figure out how to deal with Album Artist. All comments appreciated.
Last edited by roylayer on Tue Mar 16, 2004 3:50 pm, edited 1 time in total.
Happy user of MediaMonkey Gold version 2.5.5.998
Computer: p4, 2.5 ghz, 3 gb ram, win xp

Lowlander
Posts: 46283
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Post by Lowlander » Sun Mar 14, 2004 3:22 pm

I asked the same thing about album artist but no response yet. Hope to find out soon.

Good luck
Lowlander (MediaMonkey user since 2003)

Pablo
Posts: 554
Joined: Sun Feb 22, 2004 2:59 am

Post by Pablo » Sun Mar 14, 2004 3:32 pm

Hi. Nice script. I can't help with the album artist but I'll do some research. As a last resource, you can always do it by SQL...

Pablo

roylayer
Posts: 85
Joined: Tue Feb 25, 2003 12:44 am

Post by roylayer » Sun Mar 14, 2004 3:50 pm

I would be very wary of changing the Artist by SQL. Changing stuff like PlayCounter is one thing, but changing key fields like Artist Name is another. I believe MM does some additional stuff when you change an Artist Name through its interface. For example, let's say we have these two artists:

The Beatles (ID = 1)
Beatles, The (ID = 2)

If we just use SQL to change "The Beatles" to "Beatles, The" for ID = 1, then we simply end up with two entries in the database that have the same artist name. Songs for The Beatles will still be split into two nodes. MM must check to see if "Beatles, The" already exists and, if so, change the Artist ID associated with its songs.
Happy user of MediaMonkey Gold version 2.5.5.998
Computer: p4, 2.5 ghz, 3 gb ram, win xp

Pablo
Posts: 554
Joined: Sun Feb 22, 2004 2:59 am

Post by Pablo » Mon Mar 15, 2004 5:25 am

I would be very wary of changing the Artist by SQL.
Me too, that's why I said, only as a last resource. But it could be done :-?

Pablo

jiri
Posts: 5395
Joined: Tue Aug 14, 2001 7:00 pm
Location: Czech Republic
Contact:

Post by jiri » Mon Mar 15, 2004 5:32 am

I haven't tried that recently, but I believe that itm.album.artist.name should really return Album Artist name. That said, there's definitely problem with updating that name, there isn't any 'scripting' way how to write it back to DB.

Actually, I'd be interested in a list of such things that you miss in scripting, it seems there's already a couple of users trying to use this feature and I'd like to improve it for some latter version (probably 2.3).

Jiri

Lowlander
Posts: 46283
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Post by Lowlander » Mon Mar 15, 2004 10:34 am

My true problem with the album artist is that the field is empty when no album exists. This does keep the MM interface clean, but limits some of its use. Of course scripting could take care of that by using artistName when albumArtist is empty.

My problem relates to the file rename function, where album artist wouldn't work.
Lowlander (MediaMonkey user since 2003)

roylayer
Posts: 85
Joined: Tue Feb 25, 2003 12:44 am

Post by roylayer » Mon Mar 15, 2004 11:53 pm

Jiri, I displayed itm.album.artist.name along with item.artistname in a message box, and both displayed the Song artist name. (I chose a song with different Song and Album artist names.) I was surprised as well. It's possible that I did something wrong, but, like you say, it really doesn't matter since I can't set the field anyway.

Thanks for the invite to submit things that we miss in scripting. I'll try to keep track of such things. Frankly, I am still blown away that this feature is even provided! You have no idea how much time this has saved me, not to mention providing capabilities that I could only do previously by editting the database directly (which I try to avoid). In general, the object model seems very robust. Thanks again!
Happy user of MediaMonkey Gold version 2.5.5.998
Computer: p4, 2.5 ghz, 3 gb ram, win xp

roylayer
Posts: 85
Joined: Tue Feb 25, 2003 12:44 am

Post by roylayer » Tue Mar 16, 2004 11:28 am

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.

Function QS(UnquotedString)
  '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
End function

Sub MoveFirstWord
  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 
  End If  

  '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
      'itm.UpdateDB  
    end if
  Next

  msgbox "Be sure to refresh (F5) & synchronize tags"  'you may wish to remove this line
End Sub
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.
Happy user of MediaMonkey Gold version 2.5.5.998
Computer: p4, 2.5 ghz, 3 gb ram, win xp

roylayer
Posts: 85
Joined: Tue Feb 25, 2003 12:44 am

Post by roylayer » Tue Mar 16, 2004 5:42 pm

This minor update tries to be more efficient about updating Artists.Artist and adds a progress bar.

Code: Select all

'MoveFirstWord (version 2.1)

'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.

Option Explicit

Function QS(UnquotedString)
  '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
End function

Sub MoveFirstWord
  Dim list, itm, i, ParsedArray, sql, NewName, LastName, Progress

  'Get list of selected tracks from MediaMonkey
  Set list = SDB.SelectedSongList 
  If list.count=0 Then 
    Set list = SDB.AllVisibleSongList 
  End If  

  'Set up progress 
  Set Progress = SDB.Progress 
  Progress.Text = "Moving first word to last..." 
  Progress.MaxValue = list.count 

  'Process all selected tracks
  For i=0 To list.count-1
    Set itm = list.Item(i)

    if itm.ArtistName <> LastName then
      LastName = itm.ArtistName
      'only do when artist name changes.  
      'this is done for efficiency only, assuming that the list will be sorted by artist name.
      'script will still work if that is not true
      '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)

        '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
        'itm.UpdateDB  
      end if
    end if

    Progress.value = i+1 
    If Progress.terminate Then 
       Exit For  'allows user to right click progress bar to stop script
    End if    
  Next

  msgbox "Be sure to refresh (F5) & synchronize tags"  'you may wish to remove this line
End Sub
Happy user of MediaMonkey Gold version 2.5.5.998
Computer: p4, 2.5 ghz, 3 gb ram, win xp

Pablo
Posts: 554
Joined: Sun Feb 22, 2004 2:59 am

Post by Pablo » Thu Mar 18, 2004 7:03 pm

Nice. I think I'll adapt it to work only if the first word is "the" or similar.

Pablo

roylayer
Posts: 85
Joined: Tue Feb 25, 2003 12:44 am

Post by roylayer » Thu Mar 18, 2004 7:39 pm

You may want to hold up on that. I've been working on that for the past several days. ;-) Actually, I already have that part done, but I want to combine it with a routine to Init Caps. (Yes, I know that one has already been posted here, but I have slightly different requirements from those that one addresses.)

The new script will scan all Arist, Album, and Title fields, and move any preposition like "the," "a," etc. to the back (or sometimes middle) of the field. It will also force init caps and trailing lower case for all words found. Basically, I want one script to "normalize" all tag data for any new songs that I create or download.

I should have it ready within the next day or two.
Happy user of MediaMonkey Gold version 2.5.5.998
Computer: p4, 2.5 ghz, 3 gb ram, win xp

nachtgieger
Posts: 32
Joined: Thu Dec 19, 2002 3:41 am
Location: Germany

Re: buy viagra online

Post by nachtgieger » Tue Jul 12, 2005 1:59 am

Stop that!

onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Re: buy viagra online

Post by onkel_enno » Tue Jul 12, 2005 2:02 am

nachtgieger wrote:Stop that!
IT won't hear you :wink:
Jiri already has an eye on this.
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

Post Reply