Randomise Playlist 1.3 - Updated 20/10/2010

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Randomise Playlist 1.3 - Updated 20/10/2010

Postby trixmoto » Mon Nov 26, 2007 7:28 am

This script creates a menu item which appears when right clicking on a playlist. It gives you the option to randomise this playlist.

Code: Select all
'
' MediaMonkey Script
'
' NAME: RandomisePlaylist 1.3
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 20/10/2010
'
' INSTALL: Copy to Scripts\Auto directory and add the following to Scripts.ini
'          Don't forget to remove comments (') and set the order appropriately
'
' [RandomisePlaylist]
' FileName=Auto\RandomisePlaylist.vbs
' ProcName=RandomisePlaylist
' Order=50
' DisplayName=Randomise Playlist
' Description=Randomises selected playlist
' Language=VBScript
' ScriptType=0
'
' FIXES: Fixed playlist node being fully expanded on startup
'

Option Explicit
Dim AutoMode : AutoMode = False 'Randomise playlists automatically

Sub OnStartup
  Call RegisterAutoEvents()
  If AutoMode Then
    Exit Sub
  End If
 
  Dim itm : Set itm = SDB.Objects("RandomisePlaylistMenu")
  If itm Is Nothing Then
    Set itm = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_Tree,1,0)
    itm.Caption = "Randomise Playlist"
    itm.OnClickFunc = "ItmClick"
    itm.UseScript = Script.ScriptPath
    itm.IconIndex = 25 
    itm.Visible = False
    Set SDB.Objects("RandomisePlaylistMenu") = itm
    Call Script.RegisterEvent(SDB,"OnChangedSelection","ShowMenu")
  End If
End Sub

Sub RegisterAutoEvents
  Dim dic : Set dic = SDB.Objects("RandomisePlaylistDic")
  If dic Is Nothing Then
    Set dic = CreateObject("Scripting.Dictionary")
  End If
  Dim tree : Set tree = SDB.MainTree
  Dim node : Set node = tree.Node_Playlists
  If node.Visible Then
    Dim exp : exp = node.Expanded
    node.Expanded = True
    Set node = tree.FirstChildNode(node)
    Call DoChildren(dic,node,":|:")
    If exp = False Then
      tree.Node_Playlists.Expanded = False
    End If
  End If
  Set SDB.Objects("RandomisePlaylistDic") = dic
End Sub

Sub DoChildren(dic,node,levs)
  Do While Not (node Is Nothing)
    If node.NodeType = 61 Then
      node.CustomData = levs
      Dim list : Set list = GetPlaylistFromNode(node)
      If Not (dic.Exists("#"&list.ID)) Then
        Call dic.Add("#"&list.ID,node.Caption)
        If AutoMode Then
          Call Script.RegisterEvent(node,"OnNodeFocused","ShowAuto")
        End If
      End If
    End If
    Dim tree : Set tree = SDB.MainTree
    If node.HasChildren Then
      Dim exp : exp = node.Expanded
      node.Expanded = True   
      Dim tmp : Set tmp = tree.FirstChildNode(node)
      Call DoChildren(dic,tmp,levs&node.Caption&":|:")
      If exp = False Then
        node.Expanded = False
      End If     
    End If
    Set node = tree.NextSiblingNode(node)
  Loop
End Sub

Sub ShowAuto(node)
  Dim list : Set list = GetPlaylistFromNode(node)
  If Not (list Is Nothing) Then
    Dim w : Set w = SDB.MainTracksWindow
    Dim t : Set t = list.Tracks
    While t.Count > 0
      Dim n : n = Int(t.Count*Rnd)
      Call w.AddTrack(t.Item(n))
      Call t.Delete(n)
    WEnd
    Call w.FinishAdding()
  End If
End Sub

Sub ShowMenu()
  Dim itm : Set itm = SDB.Objects("RandomisePlaylistMenu")
  If Not (itm Is Nothing) Then 
    Dim vis : vis = False
    Dim node : Set node = SDB.MainTree.CurrentNode
    If Not (node Is Nothing) Then
      If node.NodeType = 61 Then
        vis = True
      End If
    End if
    itm.Visible = vis   
  End If
End Sub

Sub ItmClick(i)
  Call RandomisePlaylist()
End Sub

Sub RandomisePlaylist()
  Dim tree : Set tree = SDB.MainTree
  Dim node : Set node = tree.CurrentNode
  If Not (node Is Nothing) Then
    If node.NodeType = 61 Then
      Dim list : Set list = GetPlaylistFromNode(node)
      If Not (list Is Nothing) Then
        Call DoRandomise(list)
        tree.CurrentNode = tree.ParentNode(node)
        tree.CurrentNode = node
        Exit Sub
      End If
    End If
  End If
  Call SDB.Messagebox("RandomisePlaylist: You must select a playlist node.",mtError,Array(mbOk))
End Sub

Sub DoRandomise(p)
  Dim t : Set t = p.Tracks
  p.Clear
  While t.Count > 0
    Dim n : n = Int(t.Count*Rnd)
    Call p.AddTrack(t.Item(n))
    Call t.Delete(n)
    SDB.ProcessMessages
  WEnd
End Sub

Sub Install()
  Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
  Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  If Not (inif Is Nothing) Then
    inif.StringValue("RandomisePlaylist","Filename") = "Auto\RandomisePlaylist.vbs"
    inif.StringValue("RandomisePlaylist","Procname") = "RandomisePlaylist"
    inif.StringValue("RandomisePlaylist","Order") = "50"
    inif.StringValue("RandomisePlaylist","DisplayName") = "Randomise Playlist"
    inif.StringValue("RandomisePlaylist","Description") = "Randomises selected playlist"
    inif.StringValue("RandomisePlaylist","Language") = "VBScript"
    inif.StringValue("RandomisePlaylist","ScriptType") = "0"
    SDB.RefreshScriptItems
  End If
  Call OnStartup()
End Sub

Function GetPlaylistFromNode(node)
  Dim str : str = node.CustomData
  If InStr(str,":|:") = 0 Then
    Set GetPlaylistFromNode = SDB.PlaylistByTitle(node.Caption)
  Else
    Set GetPlaylistFromNode = SDB.PlaylistByTitle("")
    Dim i,j,kids,kid
    Dim arr : arr = Split(str,":|:")
    For i = 1 To UBound(arr)-1
      Dim nam : nam = arr(i)
      Set kids = GetPlaylistFromNode.ChildPlaylists
      For j = 0 To kids.Count-1
        Set kid = kids.Item(j)
        If kid.Title = nam Then
          Set GetPlaylistFromNode = kid
          Exit For
        End If         
      Next
    Next   
    Set kids = GetPlaylistFromNode.ChildPlaylists
    For j = 0 To kids.Count-1
      Set kid = kids.Item(j)
      If kid.Title = node.Caption Then
        Set GetPlaylistFromNode = kid
        Exit For
      End If         
    Next
  End If
  If Not (GetPlaylistFromNode.Title = node.Caption) Then
    Set GetPlaylistFromNode = Nothing
  End If
End Function
Last edited by trixmoto on Wed Dec 05, 2007 10:03 am, edited 1 time in total.
Download my scripts at trixmoto.net.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE
trixmoto
 
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK

Postby nohitter151 » Mon Nov 26, 2007 7:58 am

Been waiting a long time for one like this, and it works great! Thanks for another great one!
MediaMonkey user since 2006
Need help? Got a suggestion? Can't find something?

Please no PMs in reply to a post. Just reply in the thread.
nohitter151
 
Posts: 23640
Joined: Wed Aug 09, 2006 10:20 am
Location: NJ, USA

Postby bluesbeat » Mon Nov 26, 2007 8:41 am

Just tried this in MM2.
Is it supposed to work on Auto Playlists?, can only see the option on normal playlists.

thanks,
Geoff
bluesbeat
 
Posts: 37
Joined: Mon Oct 08, 2007 9:29 am
Location: Australia

Postby trixmoto » Mon Nov 26, 2007 11:12 am

You cannot randomise and autoplaylist because they are automatic and are therefore rebuilt.
Download my scripts at trixmoto.net.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE
trixmoto
 
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK

Postby Bex » Mon Nov 26, 2007 11:20 am

Well, you randomize an autoplaylist in its settings. So there's need to have a script for it (it's not even possible).
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

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

Postby bluesbeat » Mon Nov 26, 2007 5:43 pm

ok, thanks.
bluesbeat
 
Posts: 37
Joined: Mon Oct 08, 2007 9:29 am
Location: Australia

Postby The Crow » Thu Nov 29, 2007 7:22 am

Hello trixmoto! Thanks for your answer to my shuffle question in the other thread.

Is it perhaps possible, to modify the randomise 1.0 script so that the playlist gets randomised automatically when it is selected with the left mouse button so that you don't need the right click and select "Randomise Playlist"?
The Crow
 
Posts: 44
Joined: Wed Nov 28, 2007 4:05 pm

Postby trixmoto » Thu Nov 29, 2007 7:46 am

Yes this would be possible. I'll add it to my to do list! :)
Download my scripts at trixmoto.net.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE
trixmoto
 
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK

Postby The Crow » Thu Nov 29, 2007 9:48 am

Great!
The Crow
 
Posts: 44
Joined: Wed Nov 28, 2007 4:05 pm

Postby Guest » Thu Nov 29, 2007 3:50 pm

Is it possible to make it work with the genre lists as well or is it limited to playlists?
Guest
 

Postby Teknojnky » Thu Nov 29, 2007 4:01 pm

why not create an auto-playlist of:

genre = whatever genre(s) you want
sort = random a-z
Teknojnky
 
Posts: 5521
Joined: Tue Sep 06, 2005 11:01 pm

Postby The Crow » Fri Nov 30, 2007 4:46 am

Teknojnky wrote:why not create an auto-playlist of:


Using Auto DJ you have to choose a determined playlist where the next random tracks are selected from, but I would like to get randomised tracks from the list playing currently and I think there is no possibility to make such a setting with Auto DJ.

As far as I see an automatic comfortable randomised play back with tracks from the active playlist seems to be able to realize with

1. a script that shuffles the playlist already when it is clicked on
(this is on trixmoto's list :), but this probably wouldn't work with genre lists (?))

or 2. an improved MM random mode where at least the Now Playing action works properly (this is going to be fixed with MM 3.0 RC 4, http://www.mediamonkey.com/forum/viewtopic.php?t=21616; however, a navigation with "Next track", "Previous track" and the "Play selected tracks next" button wouldn't probably work)

or 3. with an improved Auto DJ that selects tracks from the actual playlist (perhaps you can realize it with Auto DJ Scripts).
The Crow
 
Posts: 44
Joined: Wed Nov 28, 2007 4:05 pm

Postby nohitter151 » Fri Nov 30, 2007 8:04 am

The Crow wrote:
Teknojnky wrote:why not create an auto-playlist of:


Using Auto DJ you have to choose a determined playlist where the next random tracks are selected from, but I would like to get randomised tracks from the list playing currently and I think there is no possibility to make such a setting with Auto DJ.

As far as I see an automatic comfortable randomised play back with tracks from the active playlist seems to be able to realize with

1. a script that shuffles the playlist already when it is clicked on
(this is on trixmoto's list :), but this probably wouldn't work with genre lists (?))

or 2. an improved MM random mode where at least the Now Playing action works properly (this is going to be fixed with MM 3.0 RC 4, http://www.mediamonkey.com/forum/viewtopic.php?t=21616; however, a navigation with "Next track", "Previous track" and the "Play selected tracks next" button wouldn't probably work)

or 3. with an improved Auto DJ that selects tracks from the actual playlist (perhaps you can realize it with Auto DJ Scripts).


I'm pretty sure TechnoJnky was talking about Auto-Playlists, not Auto-DJ
MediaMonkey user since 2006
Need help? Got a suggestion? Can't find something?

Please no PMs in reply to a post. Just reply in the thread.
nohitter151
 
Posts: 23640
Joined: Wed Aug 09, 2006 10:20 am
Location: NJ, USA

Postby The Crow » Fri Nov 30, 2007 8:46 am

Okay, you're right, I missed that. Auto Playlist works, of course, but I'd like to get randomised manual playlists (and/or the genre list) that can't be really created with criterias of Auto Playlist.
I know, it's a little bit special, but I'm using MM in a flatshare with different users and want to get it as easy without running manual commands.

There are, as I wrote, several ways to solve this. The aim would also be achieved if it was possible to add tracks manually to the Auto Playlist. :o That sounds strange but would solve my problem, too. :wink:

The best way seems to be waiting for trixmotos new script.
The Crow
 
Posts: 44
Joined: Wed Nov 28, 2007 4:05 pm

Postby Bex » Fri Nov 30, 2007 9:57 am

The Crow wrote:The aim would also be achieved if it was possible to add tracks manually to the Auto Playlist. :o That sounds strange but would solve my problem, too. :wink:


In MM3 you can achieve that since autoplaylist can "link" from other playlists. e.g. A static playlist to which you can add tracks which then ends up in your autoplaylist.
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

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

Next

Return to Need Help with Addons?

Who is online

Users browsing this forum: Bing [Bot] and 20 guests