Page 1 of 1

New Script: Merge Playlist with its children

Posted: Mon Jan 23, 2006 12:27 pm
by psyXonova
Merge Playlists script

This Script will merge the songs of the selected playlist with all the songs of the children playlists and present them inside the MainTrackWindow

Known issues: Since this script uses the PlaylistByTitle function it wont work when 2 or more playlists exist using the same name. This will be fixed in a newer release

To Do: Option to select which playlists to merge even if those playlists dont bellong to the same branch of the MainTree.
Make code faster

Suggestions and/or corrections are welcome

Usage
Right click on a playlist and select "Merge Playlist with its children"

Code:
Save the following code as MergePlaylist.vbs inside the Script\Auto folder. Restart MM

EDIT

New Code Bellow

Posted: Mon Jan 23, 2006 2:56 pm
by Paven
Wow this script worked realy well. It will help me to keep track of my sync list.

1 feature i wonder about... Should the playlist be saved with the new contense? or is just for show?

2 i noticed that it continues to sync if u change play list or folder.. it just keeps adding and adding tracks....

P

Posted: Mon Jan 23, 2006 3:20 pm
by Josti
Sorry for being impolite, but shouldn't it be children instead of childs...

Have no use for this script, but looks good, keep coding ;)

Posted: Mon Jan 23, 2006 3:58 pm
by psyXonova
Josti you are not impolite, you are just right.
Thnks for the correction

Paven i will check the problem you report tomorrow. Perhaps i can find a workaround

Posted: Tue Jan 24, 2006 6:25 am
by psyXonova
Ok, this fixes the situation where clicking on a different node, made the script keep adding tracks....

Code: Select all

'==========================================================================
' NAME: MergePlaylists.vbs
'
' AUTHOR: psyXonova
' DATE  : 23/1/2006
'
' COMMENT: This script will merge selected playlist with its childen.
'
'==========================================================================
Set DicList = CreateObject("Scripting.Dictionary")

Sub OnStartup
  SDB.UI.AddMenuItemSep SDB.UI.Menu_Pop_Tree,3,1

  Dim miAddToFavouriteNodes
  Set miAddToFavouriteNodes = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_Tree,0,0)
  With miAddToFavouriteNodes
    .Caption = "Merge Playlist with Children"
    .OnClickFunc = "mergePlaylist"
    .UseScript = Script.ScriptPath
    .IconIndex = 18
  End With
  
  End Sub
  
  Sub MergePlaylist(arg)
  Set myNode = SDB.MainTree.CurrentNode
  
  If myNode.NodeType <> 61 And myNode.NodeType <> 71 And mynode.NodeType <> 6 Then
  MsgBox "Please select a playlist"
  Else
  If myNode.nodeType = 6 Then 
  MsgBox "You must select a playlist, and not the parent node"
  Else
  
  	QSQL = "SELECT Playlists.IDPlaylist FROM Playlists WHERE Playlists.PlaylistName = '" & MyNode.Caption & "'" 'Like "& Node.Caption & " ORDER BY Playlist.ParentPlaylist"
	Set Iter = SDB.Database.OpenSQL(QSQL)
	i=0
	While Not Iter.Eof
		PlParent = Iter.ValueByIndex(0)
		i=i+1
		Iter.Next
	Wend
	
	If i>1 Then '2 or more playlists with the same name exist
		MsgBox "Multiple playlists with the same name"
	Else
	Dim myPlaylist, list, MainWindow
	Set myPlaylist = SDB.PlaylistByTitle(MyNode.Caption)
	Set list = myPlaylist.ChildPlaylists
	For i = 0 To list.Count -1
	DicList.Add list.item(i).id, list.Item(i)
	Next
	
	Do While True
	dicount = DicList.Count
	arrayitems = DicList.Items
	For j = 0 To DicList.Count - 1
 		Set myPlaylist = Arrayitems(j)
 		Set list = myPlaylist.ChildPlaylists
 		For i = 0 To list.Count -1
 			If Not DicList.Exists(list.Item(i).id) Then DicList.Add list.Item(i).id, list.Item(i)
 		Next
	Next
		If dicount => DicList.Count Then Exit Do
	Loop
	End If
	
	arrayitems = DicList.Items
	Set MainWindow = SDB.MainTracksWindow
	For i = 0 To DicList.Count -1
	Set myPlaylist = arrayitems(i)
		AddID = MainWindow.CurrentAddingId
		For j=0 To myPlaylist.Tracks.count -1
		MainWindow.AddTrackEx myPlaylist.Tracks.Item(j), AddID
		If SDB.MainTree.CurrentNode.caption <> myNode.caption Then Exit Sub
		Next
		
	Next
	MainWindow.FinishAdding
	
  End If
  End If
 End Sub
 

Posted: Sat Aug 19, 2006 8:20 pm
by baker
Hey, great script. Thanks a lot. One request though..

Would it be possible to have an option that would make it automatically merge all child playlists with their parents at startup?

Thanks again,
Baker

Posted: Sat Aug 19, 2006 9:40 pm
by baker
Actually, I just noticed that it seems to be mistakenly adding duplicate songs from the child in the place of other songs. For example, a child that contains 3 songs...

1. Beatles - Hard Day's Night
2. Doors - Light My Fire
3. Queen - Bicycle Race

...will transfer to the parent

1. Beatles - Hard Day's Night
2. Beatles - Hard Day's Night
3. Queen - Bicycle Race

Is it just me? I am using 2.52.951

Posted: Tue Aug 22, 2006 10:28 am
by scherer43
Fantastic Script!

I have used it to create Playlists using several Auto-Playlists. For Example....

I used it to make a radio station like list of 20 songs....
Parent- My 20 Songs (no songs here)

Children (Auto-Playlists)
1. List of 10 Random 5 Star songs
2. List of 7 Random 4 Star songs, not heard in at least a day
3. List of 3 Random 3 Star songs, ordered by not heard recently

I also ran into the repeating problem mentioned above.
It seems that each Child included will bring pair of duplicates to the Parent.
I think it can be fixed. With some slight modifications this script can do a ton to create some fanastic multi-blended playlists. Thank you and good luck, I'll be keeping an eye out!

EDIT: Also once the newly formed playlist plays past 12 it seems to begin deleting songs out of the playlist.

Posted: Thu Feb 22, 2007 6:08 pm
by Teknojnky
Anyone know how to make this script *COPY* playlist entries from child playlists to the parent?

It seems that the current implementation *MOVES* static playlist tracks to the parent, which is bad when you merge a bunch of staticly made playlists into the parent (and thus losing the organization of the tracks in the childs).

Posted: Sun Sep 16, 2007 3:53 am
by surfer
Does this script work on the new MM 3.0 beta2?
If not, could you please update?