Here is a script to create an Album Artists Node

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

jmaver
Posts: 92
Joined: Thu Feb 19, 2004 10:26 am

Here is a script to create an Album Artists Node

Post by jmaver »

Code: Select all

' Adds an album artist field
'

Sub OnStartup
  Dim Tree
  Set Tree = SDB.MainTree

  Dim AlbArtNode
  Set AlbArtNode= Tree.CreateNode
  AlbArtNode.Caption = "Album Artists"
  AlbArtNode.IconIndex = 0
  AlbArtNode.UseScript = Script.ScriptPath
  AlbArtNode.OnFillChildren = "FillAlbumArtists"

  Tree.AddNode Tree.Node_Library, AlbArtNode, 2
  AlbArtNode.HasChildren = true
End Sub

Sub FillAlbumArtists(Node)
  Node.HasChildren = false
 Dim Tree, Iter
  Set Tree = SDB.MainTree
  Set Iter = SDB.Database.OpenSQL( "SELECT DISTINCT Artists.Artist, Artists.ID FROM (Albums INNER JOIN Artists ON Albums.IDArtist = Artists.ID) WHERE Albums.IDArtist <> 0 ORDER BY Artists.Artist" ) 

  While Not Iter.EOF
    Set NewNode = Tree.CreateNode
    NewNode.Caption = Iter.StringByIndex(0)
    NewNode.CustomData = Iter.ValueByIndex(1)
    NewNode.IconIndex = 0
    NewNode.UseScript = Script.ScriptPath
    NewNode.OnFillChildren = "FillAlbums"
    NewNode.OnFillTracksFunct = "FillArtistTracks"
    Tree.AddNode Node, NewNode, 3     '  Add as the last child
    NewNode.HasChildren = true
    Iter.Next
  WEnd
End Sub

Sub FillAlbums(Node)
  'Node.CustomData contains Artists.ID
  Node.HasChildren = false
 
  Set Tree = SDB.MainTree
  Set Iter = SDB.Database.OpenSQL( "SELECT Albums.Album, Albums.ID FROM Albums WHERE Albums.IDArtist= " & Node.CustomData & " Order BY Album")

  While Not Iter.EOF
    Set NewNode = Tree.CreateNode
    NewNode.Caption = Iter.StringByIndex(0)
    NewNode.CustomData = Iter.ValueByIndex(1)
    NewNode.IconIndex = 16
    NewNode.UseScript = Script.ScriptPath
    NewNode.OnFillTracksFunct = "FillTracks"
    Tree.AddNode Node, NewNode, 3     '  Add as the last child
    Iter.Next
  WEnd
End Sub

Sub FillArtistTracks( Node)
  'Node.CustomData contains Artists.ID
  Set Trcks = SDB.MainTracksWindow

  Trcks.AddTracksFromQuery( "and Songs.ID in (SELECT Songs.ID FROM Songs,Albums WHERE Songs.IDAlbum=Albums.ID AND Albums.IDArtist="& Node.CustomData & ")")
  Trcks.FinishAdding
End Sub

Sub FillTracks( Node)
  'Node.CustomData contains Albums.ID
  Set Trcks = SDB.MainTracksWindow

  Trcks.AddTracksFromQuery( "and Songs.ID in (SELECT ID FROM Songs WHERE IDAlbum="& Node.CustomData & ")")
  Trcks.FinishAdding
End Sub
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Thanks

Post by trixmoto »

This is excellent, thank you!
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Re: Thanks

Post by onkel_enno »

trixmoto wrote:This is excellent, thank you!
You can also use Magic Nodes for things like that.
rk
Posts: 104
Joined: Mon Jul 25, 2005 2:18 am
Location: Germany

Post by rk »

Yes, try Magic Nodes! It is highly flexible!
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

I now use Magic Nodes and agree it is great. I still use this script though because it uses the Artist icon and puts the node in the right place.
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

trixmoto wrote:I now use Magic Nodes and agree it is great. I still use this script though because it uses the Artist icon and puts the node in the right place.
Same things can be done with MagicNodes.
KeyWords: "icon:" and "child of:"
Last edited by onkel_enno on Thu Sep 08, 2005 5:02 am, edited 1 time in total.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

I'm sure I'll learn to use Magic Nodes properly soon, but for now this script does the job. Cheers!
Post Reply