Auto-Shuffle albums on playback - with exceptions

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

Posts: 2
Joined: Sun Jul 26, 2009 2:54 pm

Auto-Shuffle albums on playback - with exceptions

Post by Breaker12345 » Mon Jul 27, 2009 5:19 pm

Here's my little script for MM that may be of help to you:

I have usually set track numbers in tags. When starting playback on an album, I usually want to randomize the playlist first and then play the list back from top to the bottom. I dislike the embedded shuffle function with the track jumping around in the list.

There are albums, where it makes sense to play them back only in the original track order, e.g. "concept" albums or live albums. So I want to define exceptions when not to shuffle. I defined that by simply adding an empty file "!noshuffle.flag" in that album's directory.

I wrote a script which automatically randomizes the playlist on playing back the first song. - Except that !noshuffle.flag file is found.

If you want a similar behaviour, this script may help you. If you don't want the "noshuffle" detection by that file and instead of something else, you could change the script of course. One little disadvantage is that the script randomizes the list after starting playback, so you will hear the first second of the first song of the non-shuffled list.

You can install the script by simply copying it into the Scripts\Auto directoy.

Code: Select all

' Autoshuffle.vbs for MediaMonkey 3.1+
' Randomize the playlist whenever the first file of a batch of files is played back.
' Only shuffle the files once, when the first file is played back.
' Don't shuffle, if a file "!noshuffle.flag" is found in the directory of the first file of the playlist.
' (c) 07/2009 Uwe Freese,

Dim lastDirectory

Sub OnStartup 
  Script.RegisterEvent SDB, "OnPlay", "SDBPlay"
  lastDirectory = ""
End Sub 
Sub SDBPlay
	If SDB.Player.CurrentSongIndex = 0 Then
		Dim path, i

		path = SDB.Player.CurrentSong.Path
		i = InStrRev(path, "\")
		path = Mid(path, 1, i)
		if lastDirectory = path Then
			Exit Sub
		end if
    lastDirectory = path

		Dim fso
		Set fso = CreateObject("Scripting.FileSystemObject")
		if Not fso.FileExists(path & "!noshuffle.flag") then
		    Call DoRandomise
		end if
		Set fso = nothing
	End If
End Sub

Sub DoRandomise
  Dim i, count
  count = SDB.Player.CurrentSonglist.Count

  if Count = 1 Then
  	Exit Sub
  End If

  for i = 1 To count
    Dim n : n = Int(count * Rnd)
    SDB.Player.PlaylistMoveTrack n, 0
  SDB.Player.CurrentSongIndex = 0
End Sub
If anyone knows a better approach to randomizing albums with the option for exceptions, please let me know!