Weighted Shuffle [Script]

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

Moderators: Peke, Gurus

acey
Posts: 4
Joined: Fri Jun 24, 2011 3:03 pm

Weighted Shuffle [Script]

Post by acey »

Well, I am a total newb to Media Monkey scripting, but I have a weighted shuffle script I wrote a while back that seems to work pretty well for my needs, so I thought I should go ahead and post it in case anyone else finds it useful.

Basically all it does is create a node under your "Now Playing" node which duplicates tracks once per every half-star in the tracks rating. So if you play the songs from this node with shuffle turned on, Media Monkey will be more likely to pick the songs with a higher rating since they are duplicated more. For example a song with a 5 star rating is 10 times more likely to be played than one with a 1/2 star rating. 0 star songs (bomb rating) are dropped completely, and un-rated songs are weighted the same as 2.5 stars.

So to use this, just populate the "Now Playing" node with whatever you want to listen to, then start playing the "Weighted Shuffle" node (and make sure you have shuffle turned on).

Some of this script is based off the tutorial scripts and other scripts I found on the forums, but I don't remember which ones, so sorry if I ripped off any code snippets, etc, from anyone.

Here is the script:

Code: Select all

Sub OnStartup
  Dim Tree
  Set Tree = SDB.MainTree
 
  Dim Node
  Set Node = Tree.CreateNode
  Node.Caption = "Weighted Shuffle"
  Node.IconIndex = 40
  Node.UseScript = Script.ScriptPath
  Node.OnFillTracksFunct = "FillNPTracks"
 
  Tree.AddNode Tree.Node_NowPlaying, Node, 3   ' Add as the last child
End Sub
 
Sub FillNPTracks( Node)  
  Dim min_rating
  min_rating=6
  While min_rating<100 And Not Script.Terminate
    Dim i
    i=0
    Dim List, Trcks
    Set List = SDB.Player.CurrentPlaylist
    Set Trcks = SDB.MainTracksWindow
   
    While i<List.Count And Not Script.Terminate
      If (List.Item(i).Rating > min_rating) Then
        Trcks.AddTrack List.Item(i)
      Else If (min_rating <= 46 And List.Item(i).Rating = -1) Then 'include unknowns 5 times
        Trcks.AddTrack List.Item(i)
      End If
      End If
      i=i+1
    WEnd
    min_rating=min_rating+10
  WEnd

  Trcks.FinishAdding
End Sub
Just put this script in a file named "weighted_shuffle.vbs" or something in your "Program Files\MediaMonkey\Scripts\Auto" folder and it will run to create the node every time you open Media Monkey.

Feel free to let me know if I did anything stupid or if you have any improvements or anything :)

Thanks!
-acey
wormywyrm
Posts: 73
Joined: Tue Jan 12, 2010 4:40 pm

Re: Weighted Shuffle [Script]

Post by wormywyrm »

This is a great idea, I constantly am wishing for something like this without even realizing it :-)
MM to Grooveshark Playlist Sync w/ MonkeyShark.
http://lysle.net/projects/monkeyshark.php
wormywyrm
Posts: 73
Joined: Tue Jan 12, 2010 4:40 pm

Re: Weighted Shuffle [Script]

Post by wormywyrm »

I won't be using it however because it causes the songs to repeat sometimes. I understand why you went with this method of doing it since it would be easier to code, especially for someone new. I am in the same boat as a new scripter here :-)

Maybe what we could do is have the script take an array of all the songs in the now playing list and duplicate songs in the array, then shuffle the array and go through the array removing duplicates. That would make all the good songs tend to be at the top of the array and the bad songs be at the bottom. Then push that array into the now playing list. I would be interested in making these modifications if you don't, let me know.
MM to Grooveshark Playlist Sync w/ MonkeyShark.
http://lysle.net/projects/monkeyshark.php
acey
Posts: 4
Joined: Fri Jun 24, 2011 3:03 pm

Re: Weighted Shuffle [Script]

Post by acey »

Yeah, I see what you are saying I think. The only issue I see with that approach would be that as you work your way down the list, the probability of playing a higher rated song would continuously go down, and as you neared the end, it would actually reverse and would be mostly playing your lowest rated songs. After going all the way through the list you would have listened to all your songs once regardless of the rating. This could of course be avoided by periodically re-shuffling your songs though, and it would prevent songs from repeating as you said.

I may try to make a version of the script that works like this at some point, but it would probably not be right away as I am pretty busy with work and school at the moment. You are more than welcome to use any or all of my code if you want to take a stab at it :)
wormywyrm
Posts: 73
Joined: Tue Jan 12, 2010 4:40 pm

Re: Weighted Shuffle [Script]

Post by wormywyrm »

Yeah, there is definitely a trade off between the two options.

I suppose another way of doing it could be to shuffle it with duplicates, as you have it now, but then loop through the playlist and make sure the same song does not play twice in a row, or even 'too close' to itself (maybe like 4-5 songs apart), that way the listener doesn't have to experience back to back repeats.

Okay, I am busy with school too but it will go on my to do list and we will see who gets around to it first.
MM to Grooveshark Playlist Sync w/ MonkeyShark.
http://lysle.net/projects/monkeyshark.php
acey
Posts: 4
Joined: Fri Jun 24, 2011 3:03 pm

Re: Weighted Shuffle [Script]

Post by acey »

Good idea, seems like that would work well. Plus it wouldn't interfere with the current functionality at all (other than perhaps slowing the initial list population down a bit). You could still turn shuffle on and it would work the same as the current script, or you could play the songs in order to get the same weighting but without the chance of playing a song twice in a row.
Post Reply