Page 1 of 29

Last.FM Node: dynamic node based on 2020.04.19 [MM3][MM4]

Posted: Mon Jan 14, 2008 1:43 pm
by Teknojnky
I'm pleased to release the latest updates to Last.FM Node.


If you have problems installing on vista or windows 7, try shutting down MM and then right click the MM shortcut and RUN AS ADMIN, then double click the MMIP installation file

You can change some of the options @ tools > options > library > nodes (mouse over the controls to see what they do) to suite your preference.

To add your favorite artists, tags, etc... use the menu icon on the main toolbar.

To remove them, you will have to shutdown MM and edit the lastfmnode.vbs.ini file in the mm\scripts\auto folder.

Download @ ... discovery/

Recent Updates:
' 2020.04.19
' * fixed error 424 during similar track search
' * not sure what I screwed up with fixurl, but I added some hardcoded codes to help bjork etc
' * added option for key, see Tools > options > library > node
' * you must enter a key, either your own or a publicly available one (see forum)'
' or'
' * updated api urls and changed to HTTPS'
' * added some more logging, also added logging for tracks not found in library
' potentially useful to see what artists/tracks you might be interested in'
' that you don't already have'
' * removed group and location nodes'
' * added global top tracks under 'users' node'
' * added user recently played tracks under a favorite user node

* added QuickQueue from menu, selected tracks will be queried and
each of their similar tracks will be queued (using the queue # in options)

* added dj queue option (queue multiple similar tracks at one time)
* added avoid twofers option (avoid playing 2 songs by the same artist in a row)

* Optimized auto-dj mode retries (hopefully)'
* Last.FM node now indicates what track will be used if you click the root node'
* Misc stuff I've forgotten'

* fixed a couple event errors'
* disabled some unnecessary database transactions'

* implemented favorites saving and usage (edit/remove not yet functional)'
* favorite nodes are stored in Auto\LastFmNode.vbs.ini'
* added menu and dialog to save favorites to the Last.FM toolbar button/menu'

* Fixed control names in options sheet
* Fixed dropdown lists in options sheet and added a couple more sorts'
* Partially fixed enable dj mode from option sheet (still works from the toolbar menu)'

* Updated SQL's to use current filter settings. Useful if you want to prevent
in-accessible or other tracks from being queried'
* Finally implemented preference saving to ini, you no longer need to manually
modify the variables at the top of the script. Options > Library > Last.FM Node (note this does not yet include default/favorite nodes)

* Updated QueryLibrary() to avoid some case sensitivity and increase speed.
thx to Bex, ZvezanD and chx for the interesting discussion about it
* added check for similar artist exists in library before trying to find their
tracks when similar tracks fails (prevents searching for tracks not in lib)

* added Order variable to set the preferred sort order when searching for tracks
must be a valid ORDER BY <songfield> sql qualifier, default is sort by bitrate
DESC so the highest bitrate track is used first. Other alternatives might be
Rating DESC, DateAdded ASC/DESC, PlayCounter ASC/DESC, Year ASC/DESC,
or Random(). Sort order only matters when you might have multiple copies
of a track. The previous unspecified behavior appeared to be by songid.
NOTE: if you choose Random(), you might get a repeat play of a track early
because a different version may have been played previously.


* add db commits before sql iterators to avoid some database errors when multiple scripts are running or tags are being updated in the background

* updated the sql query with many thanks to Bex for a much much faster and less resource intensive query

* fixed artist check so that differing case doesn't matter (I noticed NoFX vs NOFX)'
* implemented group tracks/artists, enjoy and don't forget to join "Media Monkey"
* updated most of the nodes to be more consistent with stuff I learned later
* should use new events instead of old onclick stuff'
* added default variables to customize the prompts to your preferences,
saving options to ini should be coming soon I hope.
* I think I have all functionality I originally envisioned and even some I didn't.
Work soon to start on save/load nodes, optionsheet and whatever optimzations'
* Oh, also added get current play track for fav artist and tags

* added a real PAINT IT BLACK icon based on image from Spacefish, Thanks!'
* functionalized the dj restrictions (shouldn't really have any discernable effect)
* add qry check for artist before searching artist+title
I am interested in knowing if this is any noticible improvement
especially for smaller libraries (shouldn't search for artists you don't have)
* added check for min rating and size in qry (rating uses 'djminrating' variable)
this affects the regular nodes to keep crappy tracks out, feedback requested'
* misc improvements & logging tweaks/details (be sure to delete log occasionally)'

' * implemented related artist + random related artist top tracks failover
' if related tracks comes up empty.
' * implemented last chance add random track from library if all else fails'

It's not the most pretty, but it seems to be working OK.. try it out and let me know how it works for you!

Minor update to script:
' Recent Updates:
' * implemented artist time limit (keeps artist from repeating within # hours)
' * implemented retry counter, script will now try to find more tracks by temporarily
' loosening restrictions (track/artist repeat timer, turn off dupe avoidance)'


While I still have not finished implentation of save/load, I have added a new feature which I am very excited about and I think you will be too.

Last.FM DJ Mode

When enabled, this will auto-enqueue related tracks based on the 'related tracks' feed from This is slightly different from scrobbler dj, where the related artists was chosen then a top track from the related artist was chosen.

Using the related tracks feed is more accurate, but can possibly lead to a potentially smaller pool of tracks to choose from.

To enable DJ mode, select it from the Last.FM icon on the standard toolbar.

In the future, additional modes will be added to fall back on if insufficient usable tracks occurs.

I also tried my hand at a MMIP installation package, download here.

This script is compatible with Mediamonkey 3, older versions are not supported.

Script is still a work in progress, not all features are implemented and errors could occur.

Feedback, bugs, improvement ideas are welcomed.

Thanks go out to Psyxonova, the creator of the ScrobblerDJ script which has been a favorite and inspiration.

Thanks also go out to the Mediamonkey Dev Team and the Community Scripters who make Mediamonkey such a wonderful tool.

OK well here is the first somewhat usable release.. there is still lots to do, but the favorite artists node appears to function perfectly (but still no save/load).


Try it out, I'm looking forward to hearing any comments/suggestions!

All Nodes appear to be fully functional, still no save/load yet, I'll start figuring out how to do that soon.

Code: Select all

code removed, use MMIP installer

So, I was thinkin what else would be super cool to have in mediamonkey...

An auto-playlist/node of an artist's top tracks based on their top tracks at

There are already a few scripts out there that do related stuff, this would be somewhat of a combination of some of them, but would provide an interesting and dynamic view not really available in mm..

So, a new node could be created "" or some such, under this node the user could add various particular/favorite artists, once added and clicked on, the script would dynamically load the artists top tracks that you have in your library.

Now really the most interesting thing that this does differently from other scripts, is that it simply populates a node tracklist and does not enqueue anything at all. From the resulting tracklist you could enqueue or rate or burn or edit or whatever you wish to do.

To build on the above, even cooler would be the ability to right click one of these artist nodes or tracks and have related artists added as subnodes along with their dynamic track lists matched up between and your library.

Here's sort of a visual example as how I was thinking...

MM tree nodes
  • Now Playing
  • Library & subnodes
  • Artist Dyamic Playlists
    [**] Nine Inch Nails (clicking this node would load Nine Inch Nails Top tracks that you have in your library
    [***] Tool (related sub nodes off of NIN with their resulting top tracks)
    [***] A Perfect Circle
    [****] Tool
    [****] Deftones (related artist sub node of A Perfect Node)
    [****] Nine Inch Nails
    [***] Marilyn Manson
(edit I guess its not possible to multilevel bullets, but hopefully the heirarchy is apparent)

I am sure some limit would have to be made to how deep a set of subnodes you could make, and it might be prudent to filter duplicates within a tree of related artists (so NIN wouldn't appear under a subnode of itself), but hopefully the idea is to be able to a tree of related artists and their applicable top tracks.

To add an artist to the root tree, a context menu could be added 'add to node' and/or type the artist name into a small input box initiated via script menu or toolbar icon, or better yet just clicking the root node would ask you what artist to add.

I don't really have the time to research and make this script, tho it could probly done by combining code from several of the existing scripts, so I'm just putting the idea out there in case anyone else see's the usefulness and has the time/ability to take the idea and run with it.

Here is a screenshot of how it looks so far.. right now the artist is hard coded into the script, but eventually you will be able to add/remove artists dynamically...


Posted: Wed Jan 23, 2008 2:15 am
by Teknojnky
script too large to post...

download installer

Posted: Wed Jan 23, 2008 2:55 am
by drjboulder
Good luck with this Teckno, this could be very cool!

Posted: Wed Jan 23, 2008 1:17 pm
by Teknojnky
Continuing on, trying to get this simple query to work...

Code: Select all

      Dim Iter, Qry 
       Qry = "ArtistName=" & Artist & " AND Title=" & TrackTitle
      Set Iter = SDB.Database.QuerySongs (Qry)
      Do While Not Iter.EOF
        logme "Query Match Loop entered"
        Tracks.AddTrack (Iter.Item)
        If AvoidDupes Then 'add only first result'
          Exit Do
        End If
I'm getting error executing SQL "SELECT Songs.* From SONGS WHERE ArtistName=Nine Inch Nails AND Title=Closer"
:near "Inch" : syntax error (1,1)

or if I try to only query the title;

' Qry = "Title=" & TrackTitle

error executing SQL "Select Songs.* FROM Songs WHERE Title = Closer"
: no such column: Closer (1,1)

Which I don't understand, I followed the example in the wiki..

Posted: Wed Jan 23, 2008 2:29 pm
by Bex
When comparing a text-field with 'some text', you must put the 'some text' between apostrophes.
You must also replace any apostrophes in 'some text' with two apostrophes.
Like this:

Code: Select all

Qry = "ArtistName='" & Replace(Artist,"'","''") & "' AND Title='" & Replace(TrackTitle,"'","''") &"'"

Posted: Wed Jan 23, 2008 2:39 pm
by Teknojnky
Ah hah, ok now I see..

I didn't understand what this function was for but now I do..

Code: Select all

Function CorrectSt(inString)
	'logme ">>CorrectSt() has started with parameters " & inString
	CorrectSt = Replace(inString, "'", "''")
	CorrectSt = Replace(inString, """", """""")
	'logme "<<CorrectSt() will return " & CorrectSt & " and exit"
End Function
But I still get sql error no such column: title using

Code: Select all

      Dim Iter, Qry 
'       Qry = "Song.ArtistName=" & Artist & " AND Song.Title=" & TrackTitle
'       Qry = "Title = '" & TrackTitle & "'"
      Qry = "ArtistName='" & Replace(Artist,"'","''") & "' AND Title='" & Replace(TrackTitle,"'","''") &"'"
      Set Iter = SDB.Database.QuerySongs (Qry) 
      Do While Not Iter.EOF
        logme "Query Match Loop entered"
        Tracks.AddTrack (Iter.Item)
        If AvoidDupes Then 'add only first result'
          Exit Do
        End If
Title is a songdata property in mm3 or has that changed?

The other errors I get after the sql error:

field not found in result C:\sources\mediamonkeyrelease\mp3datab\sqlitedb.pas, line 1227
file: lastfmnode.vbs, line 154, column 6 (which refers to the Set Iter line above)

Posted: Wed Jan 23, 2008 2:47 pm
by Bex
The CorrectSt Function is wrong. It should be:

Code: Select all

Function CorrectSt(inString)
   'logme ">>CorrectSt() has started with parameters " & inString
   CorrectSt = Replace(inString, "'", "''")
   CorrectSt = Replace(CorrectSt, """", """""")
   'logme "<<CorrectSt() will return " & CorrectSt & " and exit"
End Function
But I don't understand the use of this part:

Code: Select all

CorrectSt = Replace(CorrectSt, """", """""")
So I would actually remove it.

Posted: Wed Jan 23, 2008 2:58 pm
by Teknojnky
Ok but I wasn't even using CorrectSt yet...

the sample query works

Code: Select all

Set Iter = SDB.Database.QuerySongs("SongLength > 60*1000")
but I can't get anything to work with either Title or ArtistName fields..

Posted: Wed Jan 23, 2008 3:37 pm
by Bex
Ok, I should have thought of checking the fieldnames in the first post. ArtistName and Title don't exist. They should be Artist and SongTitle:

Code: Select all

Qry = "Artist='" & Replace(Artist,"'","''") & "' AND SongTitle='" & Replace(TrackTitle,"'","''") &"'"

Posted: Wed Jan 23, 2008 3:39 pm
by Teknojnky
I am wondering if this is a bug..

Title does not appear to be valid, but the following worked..

Set Iter = SDB.Database.QuerySongs ( "Artist LIKE '%Nine Inch Nails'")
Set Iter = SDB.Database.QuerySongs ( "Album LIKE '%Nine Inch Nails'")

doesn't work
Set Iter = SDB.Database.QuerySongs ( "ArtistName LIKE '%Nine Inch Nails'")
Set Iter = SDB.Database.QuerySongs ( "Title LIKE '%Closer'")
Set Iter = SDB.Database.QuerySongs ( "AlbumName LIKE '%Nine Inch Nails'")

I don't see any property that returns Title other than Title...

Posted: Wed Jan 23, 2008 3:42 pm
by Teknojnky
Bex wrote:Ok, I should have thought of checking the fieldnames in the first post. ArtistName and Title don't exist. They should be Artist and SongTitle:

Code: Select all

Qry = "Artist='" & Replace(Artist,"'","''") & "' AND SongTitle='" & Replace(TrackTitle,"'","''") &"'"

Ok we just both realized this :)

But, SongTitle DOES work, however I don't see it @

nor is 'SongTitle' anywhere else within the scripting wiki.. ... ext=Search

Strange no?

Posted: Wed Jan 23, 2008 3:49 pm
by Teknojnky

(well just basic functionality! but its a start!)

Updating code above..

Now I gotta figure out how to store the artist names and add/remove them dynamically to the tree.

Posted: Wed Jan 23, 2008 3:50 pm
by Bex
Then the wiki is wrong. I just found out how to update the wiki the other day (really easy) so I'll fix it.

Btw, you can use my SQL-Viewer script to see all Tables and Field names. It reads directly from the database so it's always correct.

Edit: What am I talking about?
The link you provided displays the Songdata object and all its members where the name of the title correctly is named Title.
However, that's not the same thing as the field name in Table Songs in SQL-Database. In there the name is SongTitle.

The Wiki lacks info about database Field Names. It's only contians Table Names. I'll try to add Field names when I get the time.

Posted: Wed Jan 23, 2008 3:52 pm
by trixmoto
When you are querying the database you are looking at tables and fields, not objects and properties - the names are often different in MM. The wiki section is here, but the fields are not listed yet... ... _structure

Posted: Wed Jan 23, 2008 3:57 pm
by Bex
I'm a slow typer so you bet me Trixi!