Here is a script to create an Album Artists Node

Download and get help for different MediaMonkey 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 » Fri Jan 21, 2005 10:42 am

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: Barton, UK
Contact:

Thanks

Post by trixmoto » Wed Sep 07, 2005 5:25 am

This is excellent, thank you!

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

Re: Thanks

Post by onkel_enno » Wed Sep 07, 2005 5:35 am

trixmoto wrote:This is excellent, thank you!
You can also use Magic Nodes for things like that.
SansaMonkey - for SanDisk Sansa and Rockbox Users

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

rk
Posts: 104
Joined: Mon Jul 25, 2005 2:18 am
Location: Germany

Post by rk » Wed Sep 07, 2005 5:39 am

Yes, try Magic Nodes! It is highly flexible!

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

Post by trixmoto » Thu Sep 08, 2005 3:48 am

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: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Thu Sep 08, 2005 3:53 am

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.
SansaMonkey - for SanDisk Sansa and Rockbox Users

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

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

Post by trixmoto » Thu Sep 08, 2005 4:21 am

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

Post Reply