Various Artists

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Risser
Posts: 184
Joined: Thu Mar 03, 2005 11:28 am

Various Artists

Post by Risser » Thu Nov 10, 2005 9:27 am

Script: Various Artists
Description: A script to create a Various Artists node that includes Compilations and Mixes, using codes in the comments of the songs to build and maintain this lists. This allows songs to be added and removed without affecting the structure of the compilation/mix. It also allows songs that may exist on both an album and in a compilation, or on multiple compilations, to be included in both places without needing to keep multiple copies of the song.

Peter

===========================
' Various Artists Node
' Version 1.0
' A script to create a Various Artists node that includes Compilations and Mixes, using codes
' in the comments of the songs to build and maintain this lists. This allows songs to be added
' and removed without affecting the structure of the compilation/mix. It also allows songs that
' may exist on both an album and in a compilation, or on multiple compilations, to be included in
' both places without needing to keep multiple copies of the song.
'
' This script creates a node in the tree, below the artist node, called "Various Artists".
' The node displays subnodes with large-scale categories of song compilations. In this case, they are
' "Compilation" and "Mix". Beneath each of these, nodes are created for lists of songs based on notes
' added to the comments field of individual song files. The format is as follows:
' COMP:Compilation Name:04
' MIX:Mix Name:12
' where the track number is a 2 digit number and the note occurs on a single line by itself.
' COMP indicates the track should be included on a compilation. MIX indicates it should show up
' on a mix.
'
' You can include multiple notes like this and the track will show up on each compilation/mix listed.
' Note that the track still appears under the album that is referenced in the album tag.
'
' The caption for the node includes the name of the compilation as well as the minimum and maximum
' year, which is kind of cool, to see the span.
'
' The root caption can be changed by editing the RootNodeCaption constant.
' You can add new types by adding lines to the FillRootCustomNode. Also, you can remove types
' by removing the corresponding line. For example, I have a special subset for mixes that other
' people have made for me. For these to show up, I have added the line:
' AddMainNode Node, "RING", "Ring Mixes"
' I then add 'RING:Bob's Extra Cool Mix:01" to the corresponding files and the next time I open the
' node, Bob's Extra Cool Mix is displayed.
'
' The one thing I don't like is that there is a bit of work actually pasting these "notes" into the
' files. But, once they are there, they are there for good.
'
' This script does not update the DB or files. Use at your own risk. Do not taunt this script.

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Global Variables and Declarations
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Option Explicit

' %%% The caption for the root node.
Const RootNodeCaption = "Various Artists"

Sub FillRootCustomNode(Node)
Node.hasChildren = False
AddMainNode Node, "COMP", "Compilations"
AddMainNode Node, "EXRING", "Exotica Ring"
AddMainNode Node, "MIX", "Mixes"
End Sub


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' The Meat. Don't change anything under here.
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Sub FillStandardProperties(parentNode, childNode)
With childNode
.CustomNodeId = parentNode.CustomNodeId
.CustomDataId = parentNode.CustomDataId + 1
.UseScript = Script.ScriptPath
End With
End Sub

Sub SortArray(aTempArray)
Dim iTemp, jTemp, strTemp

For iTemp = 0 To UBound(aTempArray)
For jTemp = 0 To iTemp

If strComp(aTempArray(jTemp), aTempArray(iTemp)) > 0 Then
'Swap the array positions
strTemp = aTempArray(jTemp)
aTempArray(jTemp) = aTempArray(iTemp)
aTempArray(iTemp) = strTemp
End If

Next
Next
End Sub


Sub BuildArray(CompList, aTempArray)
Dim nCount, strKey
nCount = 0

'-- Redim the array to the number of keys we need
Redim aTempArray(CompList.Count - 1)

'-- Load the array
For Each strKey In CompList.Keys

'-- Set the array element to the key
aTempArray(nCount) = strKey

'-- Increment the count
nCount = nCount + 1

Next
End Sub

Sub FillCustomLeaf(Node)

Dim sql, compName, trackNumSql, lengthSql, posSql, sql2
compName = Node.CustomData
compName = Replace(compName, "'", "''")
lengthSql = "Len('"&compName&"')"
posSql = "InStr(Memos.MemoText,'"&compName&"')"
trackNumSql = "Mid(Memos.MemoText, "&posSql&"+"&lengthSql&"+1,2)"
sql = "select Songs.Id from Songs, Memos " &_
"where Songs.Id = Memos.IdSong and MemoText like '%"&compName&":%' " &_
"order by " & trackNumSql
' sql2 = "select Songs.Id, Songs.SongTitle from Songs, Memos " &_
' "where Songs.Id = Memos.IdSong and MemoText like '%"&compName&"%' " &_
' "order by " & trackNumSql
'SDB.MessageBox "compName:"&compName, mtWarning, Array(mbOk)


Dim Tracks
Set Tracks = SDB.MainTracksWindow

Dim Iter, id, song
Set Iter = SDB.Database.OpenSQL(sql)
Do Until Iter.EOF
'SDB.MessageBox Iter.StringByIndex(1), mtWarning, Array(mbOk)

' song = SDB.createNewSongData
' song.id = Iter.StringByIndex(0)
Tracks.AddTracksFromQuery("AND Songs.ID = "&Iter.StringByIndex(0))
Iter.Next
Loop

' Tracks.AddTracksFromQuery("AND Songs.ID IN (" & sql &")")
Tracks.FinishAdding

End Sub

Sub FillMainNode(subRoot)
subRoot.hasChildren = False

Dim CompList, sql, Iter, theCode
Dim minYears, maxYears
Set CompList = CreateObject("Scripting.Dictionary")
Set minYears = CreateObject("Scripting.Dictionary")
Set maxYears = CreateObject("Scripting.Dictionary")
theCode = subRoot.customData
sql = "select Memos.MemoText, Songs.Year from Songs, Memos where MemoText like '%"&theCode&":%' AND Songs.Id = Memos.IdSong"
Set Iter = SDB.Database.OpenSQL(sql)

Dim s, bpos, epos, name, year, min, max
Dim node

Do Until Iter.EOF
s = Iter.StringByIndex(0)
year = Iter.StringByIndex(1)
If Len(year) = 3 Then
year = year + "-"
End If

Do Until Len(s) = 0 Or InStr(s, theCode&":") = 0
bpos = InStr(s, theCode&":")
If bpos <> 1 Then
s = Mid(s, bpos)
End If
s = Mid(s, Len(theCode)+2)
epos = InStr(s, vbcrlf)
If epos = 0 Then
epos = Len(s) + 1
End If
name = Left(s, epos-1)
If Left(Right(name,3),1) = ":" Or Left(Right(name,3),1) = "." Then
name = Mid(name,1,Len(name)-3)
End If

If Not CompList.Exists(name) Then
CompList.add name, name
End If

If Year <> "-1" Then
If Not minYears.Exists(name) Then
minYears.add name, year
Else
min = minYears.item(name)
If Left(min,3) = Left(year, 3) Then
If Right(min,1) = "-" Then
minYears.remove(name)
minYears.add name, year
ElseIf Right(year,1) <> "-" And year < min Then
minYears.remove(name)
minYears.add name, year
End If
ElseIf year < min Then
minYears.remove(name)
minYears.add name, year
End If
End If
If Not maxYears.Exists(name) Then
maxYears.add name, year
Else
max = maxYears.item(name)
If Left(max,3) = Left(year, 3) Then
If Right(max,1) = "-" Then
maxYears.remove(name)
maxYears.add name, year
ElseIf Right(year,1) <> "-" And year > max Then
maxYears.remove(name)
maxYears.add name, year
End If
ElseIf year > max Then
maxYears.remove(name)
maxYears.add name, year
End If
End If
End If

'SDB.MessageBox "BLAH:"&s&":"&bpos&":"&epos&"::"&name, mtWarning, Array(mbOk)

s = Mid(s,epos)
Loop
Iter.Next
Loop

Dim aTemp, iTemp
Call BuildArray(CompList, aTemp)
Call SortArray(aTemp)
For iTemp = 0 To UBound(aTemp)
Set node = SDB.MainTree.createNode
name = CompList.Item(aTemp(iTemp))
min = minYears.Item(name)
max = maxYears.Item(name)
node.Caption = name & " [" & min & " - " & max & "]"
node.IconIndex = 16
node.UseScript = Script.ScriptPath
node.OnFillTracksFunct = "FillCustomLeaf"
node.customData = theCode&":"&name
node.sortGroup = 0
node.sortCriteria = 0
SDB.MainTree.AddNode subRoot, node, 3

node.hasChildren = False
Next
End Sub

Sub AddMainNode(rootNode, theCode, theCaption)
Dim subRoot
Set subRoot = SDB.MainTree.createNode
subRoot.Caption = theCaption
subRoot.IconIndex = 48
subRoot.UseScript = Script.ScriptPath
subRoot.onFillChildren = "FillMainNode"
subRoot.customData = theCode
SDB.MainTree.AddNode rootNode, subRoot, 3

subRoot.hasChildren = True
End Sub

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Startup Function
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Sub onStartUp
Dim Tree, Iter
Dim sql

Dim CompRoot
Set CompRoot = SDB.MainTree.createNode
CompRoot.Caption = RootNodeCaption
CompRoot.IconIndex = 48
CompRoot.UseScript = Script.ScriptPath
CompRoot.onFillChildren = "FillRootCustomNode"
SDB.MainTree.AddNode SDB.MainTree.Node_Artist, CompRoot, 1
CompRoot.hasChildren = True
End Sub

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex » Thu Nov 10, 2005 11:58 am

This script is even more cooler!
Again awesome, you're the man.
I'll sure test it when i get home.

Thanks again!

Globi
Posts: 34
Joined: Fri Oct 07, 2005 12:40 pm

Post by Globi » Thu Nov 10, 2005 12:45 pm

Sorry for a newbie question.

How do I start this script, what do I have to put in the "script.ini"?

Thanks

regards,

Globi

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

Post by trixmoto » Thu Nov 10, 2005 1:24 pm

No need to put anything in the .ini file, it is an auto-script. Save the code as a .vbs file in the Scripts\Auto\ folder and (re)start MM. The node should appear in the tree.
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.

Risser
Posts: 184
Joined: Thu Mar 03, 2005 11:28 am

Post by Risser » Thu Nov 10, 2005 2:23 pm

Remember the node will be empty until you start tagging your files.

There's another little quirk I forgot to mention. I set the node's sort-type to non-sorted, which should display the tracks in the order that I put them.

But, if you sort them, all the rest of the windows you visit will be sorted as such. The only way to get back to "unsorted" is to click on a playlist. Usually Now Playing works for me. That "erases" the sort and allows the node to sort itself as it sees fit.

Peter

sommo

Post by sommo » Tue Apr 29, 2008 1:07 am

Thanks for this! :)

sommo

Re: Various Artists

Post by sommo » Tue Aug 26, 2008 5:06 pm

Doesnt work with MediaMonkey 3

robojock
Posts: 334
Joined: Sun Sep 26, 2004 12:01 pm
Location: Windhoek,Namibia

Re: Various Artists

Post by robojock » Sat Oct 18, 2008 2:28 pm

can someone pls update this script so that it works with mm3. i really really need it :)

Post Reply