JavaScript: Get Artist IDs

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

DazB
Posts: 409
Joined: Mon Jun 11, 2007 4:09 am
Location: Yorkshire, UK

JavaScript: Get Artist IDs

Post by DazB » Fri Jul 03, 2009 6:10 pm

Hi,

Unless I am missing something, due to the implementation of multiple artists fields;

Code: Select all

SDB.CurrentSongList.Item(0).Artist.ID
returns 0, so is the following the right way of getting the ID(s)?

Code: Select all

function getArtistIDs(artistName)
{
    var tempArray = [];
    /** Normalise the separator **/
    SDB.Tools.UFText2MultiString(artistName);
    artistName = artistName.split('; ');
    for ( var i in artistName )
    {
        artistName[i] = "'"+artistName[i].replace(/'/, "''")+"'";
    }
    var iter = SDB.Database.OpenSQL("SELECT ID FROM Artists WHERE Artist IN ("+artistName.join(',')+")");
    while ( !iter.EOF )
    {
      tempArray.push(iter.StringByIndex(0));
      iter.Next();
    }
    document.getElementById('artist_id').innerHTML = tempArray.join(' | ');
}
Daz

BTW: The colour for the "syntaxcomment" in the CSS is not agreeable to my eyes.

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: JavaScript: Get Artist IDs

Post by trixmoto » Sat Jul 04, 2009 9:28 am

Yeah I asked Jiri about this and he said that he thought it would have too much of a negative performance to make "Artist.ID" into a list or whatever to make it work with multiple artists. Querying to the ID based on the name is a good way to do it. Or if you want the Artist object you can use ArtistByName.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

DazB
Posts: 409
Joined: Mon Jun 11, 2007 4:09 am
Location: Yorkshire, UK

Re: JavaScript: Get Artist IDs

Post by DazB » Sat Jul 04, 2009 1:12 pm

Hi,

Thanks for the reply. I actually don't currently use multiple artists, but...

Daz

Post Reply