I'm using a home-made script for GenerateNewTrack (i.e. for tracks added by auto-dj). I've been using this script for a while, in MM3, in MM4, without problem (up to MM4 build 1449). But now with MM4 build 1459, I get the error "Error happened during script execution: Invalid variant operation" every time it is run. It seems to work normally though, tracks are added as they should. But this message always pop-up. I put traces in the script to see when this was popping, and apparently it occurs after exiting the function GenerateNewTrack. So it seems to be in MM itself, either I'm doing something it does not like later on, or there is a bug in MM (but something definitely changed in MM for this to happen).
Here is my script:
- Code: Select all
'==========================================================================
'
' MediaMonkey Script
'
' NAME: DJTiedSongsGroups
' DESCRIPTION:
' Lets you use auto-dj while playing together groups of songs that should go together
' (groups of songs must previously be tagged as linked)
'
' AUTHOR: Tanguy Kervahut
' DATE : 11.10.2008
'
' Modified: 29.10.2008
' -Added "By album" option
' -Change the mechanism, it now adds a whole group (or album) at once. So it can add more tracks than the maximum specified for auto-dj when
' a group has more tracks than the maximum.
'
' Modified: 24.02.2009
' -"By album" option now gives the same weight to all albums (before an album with more tracks had more chances to play)
' -For multi-disc albums, ask if whole album should play or only selected disc.
'
' Modified: 17.03.2009
' - Fix a small bug when tracks don't have track order
'
' INSTALL:
' - Copy script to MediaMonkey's "Scripts" folder
' - Add an script entry to file Scripts.ini (example shown below)
'
' USE:
' For songs you want in one group, change the Custom3 field for these songs to
' the same value, beginning with LT (this indicates a "linked track").
' E.g. for an album "Pink Floyd - Dark Side of the Moon" you can change the Custom3 field
' for all tracks to "LT Pink Floyd - Dark Side of the Moon". (without quotation marks).
' Bear in mind that shorter values for the Custom3 field are faster (so better "LT PF-DSOTM")
' Order of tracks in a tied group is indicated using the standard Track Number field.
'
' [DJTiedSongsGroups]
' FileName=DJTiedSongsGroups.vbs
' DisplayName=AutoDJ Tied songs groups
' Language=VBScript
' ScriptType=4
'##############################################################################################
Option Explicit
Public DJTSG_LastSong, DJTSG_LastCall, DJTSG_NbAdded, Fso, LogF
Sub InitConfigSheet(Panel)
Dim Edt, Lists, i
Set Edt = SDB.UI.NewLabel(Panel)
Edt.Common.SetRect 1, 5, 75, 20
Edt.Caption = "Use playlist:"
Edt.Autosize = False
Edt.Alignment = 0
Set Edt = SDB.UI.NewDropDown(Panel)
Set Lists = SDB.PlaylistByTitle("").ChildPlaylists
for i = 0 to Lists.Count-1
Edt.AddItem(Lists.Item(i).Title)
next
Edt.Common.SetRect 86, 1, 200, 20
Edt.Common.ControlName = "TagGroupPlaylist"
Edt.Text = SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist")
Set Edt = SDB.UI.NewCheckBox(Panel)
Edt.Common.SetRect 295, 2, 75, 20
Edt.Common.ControlName = "ByAlbum"
Edt.Caption = "By Album"
Edt.Checked = SDB.IniFile.BoolValue("TagGroup", "ByAlbum")
End Sub
Sub CloseConfigSheet(Panel, SaveConfig)
if Saveconfig then
SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist") = Panel.Common.ChildControl("TagGroupPlaylist").Text
SDB.IniFile.BoolValue("TagGroup", "ByAlbum") = Panel.Common.ChildControl("ByAlbum").Checked
end if
End Sub
Function GenerateNewTrack
Dim ByAlbum, TagGroupPlaylist, CheckPlaylist, i, RandomTrack, NextSong, NextGroup, DiscNo
if isEmpty(DJTSG_LastSong) then
' Randomize on first run
Randomize
DJTSG_NbAdded = 0
DJTSG_LastCall = DateAdd("n",-1,Now)
end if
' The following is to avoid adding multiple groups when more than one track needs
' to be added. Because MM can call this function multiple times at once when more
' than one is required to reach the minimum to maintain. When this happens, the
' playlist isn't updated until all calls are finished. So from an empty playlist,
' it could add 5 albums (if by album and number to maintain is 5).
if DateDiff("s",DJTSG_LastCall,Now) < 5 then
DJTSG_NbAdded = DJTSG_NbAdded - 1
if DJTSG_NbAdded > 0 then
exit Function
end if
else
DJTSG_NbAdded = 0
end if
logme( "Inside GenerateNewTrack")
Dim answer
ByAlbum = SDB.IniFile.BoolValue("TagGroup", "ByAlbum")
TagGroupPlaylist = SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist")
Set CheckPlaylist = SDB.PlaylistByTitle(TagGroupPlaylist).Tracks
if (CheckPlaylist.Count = 0) then
' To avoid multiple pop-up, see previous comment
DJTSG_NbAdded = 99
answer = SDB.MessageBox( "AutoDJ playlist is empty", mtError, Array(mbOk))
exit Function
end if
i = 0
if ByAlbum then
dim CheckAlbumList, NextAlbum, RandomAlbum, AlbumTrackList
Set CheckAlbumList = CheckPlaylist.Albums
' When ByAlbum, select an album at random from the AutoDJ playlist
' and not a track, otherwise albums with more tracks get picked more often
Do
RandomAlbum = Int(Rnd() * CheckAlbumlist.Count)
Set NextAlbum = CheckAlbumlist.Item(RandomAlbum)
Set AlbumTrackList = NextAlbum.Tracks
Do
RandomTrack = Int(Rnd() * AlbumTrackList.Count)
Set NextSong = AlbumTrackList.Item(RandomTrack)
Loop while (NOT IsInSongList(NextSong, CheckPlaylist)) ' Loop to skip discs already played from multi-disc albums
i = i + 1
Loop while (IsInSongList(NextSong, SDB.Player.CurrentPlaylist) Or SameGroup(NextSong, DJTSG_LastSong, ByAlbum)) AND i < CheckPlaylist.Count
else
Do
RandomTrack = Int(Rnd() * CheckPlaylist.Count)
Set NextSong = CheckPlaylist.Item(RandomTrack)
i = i + 1
Loop while (IsInSongList(NextSong, SDB.Player.CurrentPlaylist) Or SameGroup(NextSong, DJTSG_LastSong, ByAlbum)) AND i < CheckPlaylist.Count
end if
' If you don't want to be asked what to play when it's a multi-disc album, simply replace the block below by: DiscNo = 0
if (NextSong.TrackOrderStr <> "") then
DiscNo = Fix(NextSong.TrackOrderStr / 100)
else
DiscNo = 0
end if
if (ByAlbum AND DiscNo > 0) then
' Ask to play full album or disc only
answer = SDB.MessageBox( NextSong.AlbumArtistName & Chr(13) & NextSong.AlbumName & Chr(13) & Chr(13) & "Add full album? (No = Disc " & DiscNo & " only)", mtConfirmation, Array(mbYes,mbNo))
if answer = mrYes then
DiscNo = 0
end if
end if
logme( "Track selected : " & NextSong.AlbumArtistName & " - " & NextSong.AlbumName & " - " & NextSong.Title )
If ByAlbum OR Left(NextSong.Custom3, 2) = "LT" Then
if ByAlbum then
Set NextGroup = SDB.Database.QuerySongs("Songs.IDAlbum='" & NextSong.Album.Id & "' ORDER BY abs(Songs.TrackNumber) ASC")
else
Set NextGroup = SDB.Database.QuerySongs("Songs.Custom3='" & NextSong.Custom3 & "' ORDER BY abs(Songs.TrackNumber) ASC")
end if
' Insert directly whole group at end of Now Playing - return nothing
Set DJTSG_LastSong = NextGroup.Item
Do While Not NextGroup.EOF
dim NextNo
if NextGroup.Item.TrackOrderStr <> "" then
NextNo = Fix(NextGroup.Item.TrackOrderStr / 100)
else
NextNo = 0
end if
if (NOT ByAlbum OR DiscNo = 0 OR NextNo = DiscNo ) then
DJTSG_NbAdded = DJTSG_NbAdded + 1
Call SDB.Player.PlaylistAddTrack( NextGroup.Item )
end if
NextGroup.Next
Loop
else
' Return track found
DJTSG_NbAdded = DJTSG_NbAdded + 1
Set GenerateNewTrack = NextSong
Set DJTSG_LastSong = NextSong
end if
DJTSG_LastCall = Now
End Function
Function IsInSongList( Song, List )
Dim i
IsInSongList = False
if not isEmpty(Song) AND List.Count > 0 then
for i = 0 to List.Count -1
if List.Item(i).SongId = Song.SongId then
IsInSongList = True
exit for
end if
next
end if
End Function
Function SameGroup( Song1, Song2, ByAlbum )
if isEmpty(Song1) or isEmpty(Song2) then
SameGroup = False
else
if ByAlbum then
SameGroup = Song1.Album.Id = Song2.Album.Id
else
SameGroup = Song1.SongId = Song2.SongId OR (Left(Song1.Custom3, 2) = "LT" AND Song1.Custom3 = Song2.Custom3)
end if
end if
End Function
Sub logme(msg)
' usage: logme( "text" & VarName )
' Don't forget to define LogF and Fso as Public
' If DebugSt Then
If IsEmpty(LogF) Then
Set Fso = CreateObject("Scripting.FileSystemObject")
Set LogF = Fso.OpenTextFile(Script.ScriptPath&".log",8,True)
End If
LogF.WriteLine Now() & ": " & msg
' End If
End Sub
Let me know if I can provide more info. I'm running Win7 64bits.
Tanguy

