Here is an update of the DJTiedSongsGroups script.
For a party I wanted to have some smooth music earlier in the evening, and switch to a rockier/dancier mood during the evening. But not have to go on the computer to change the source.
I've modified the script, now in the config window there is a field to specify a second source playlist, and a date time field (enter the date in format: 2011-11-23 18:10). The first playlist is used before the specified date/time, and after that time it switches to the second playlist (if one is specified).
NOTE: with MM4, there is a error that pops-up whenever multiple tracks are added at once (with the option By album or tagged tracks). Everything seems to work fine, but you get a pop-up message that you have to close. I've started a thread about that problem, no news yet on that.
Here is the updated 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
'
' Modified: 05.12.2011
' - Added a second source playlist, and a date/time field after which the second playlist should be used.
' - Date should be in format: 2011-11-23 18:10
'
' 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 76, 1, 200, 20
Edt.Common.ControlName = "TagGroupPlaylist"
Edt.Text = SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist")
Set Edt = SDB.UI.NewCheckBox(Panel)
Edt.Common.SetRect 285, 2, 75, 20
Edt.Common.ControlName = "ByAlbum"
Edt.Caption = "By Album"
Edt.Checked = SDB.IniFile.BoolValue("TagGroup", "ByAlbum")
Set Edt = SDB.UI.NewLabel(Panel)
Edt.Common.SetRect 1, 26, 75, 20
Edt.Caption = "2nd playlist:"
Edt.Autosize = False
Edt.Alignment = 0
Set Edt = SDB.UI.NewDropDown(Panel)
for i = 0 to Lists.Count-1
Edt.AddItem(Lists.Item(i).Title)
next
Edt.Common.SetRect 76, 22, 200, 20
Edt.Common.ControlName = "TagGroupPlaylist2"
Edt.Text = SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist2")
Set Edt = SDB.UI.NewEdit(Panel)
Edt.Common.SetRect 285, 22, 125, 20
Edt.Common.ControlName = "List2Time"
Edt.Text = SDB.IniFile.StringValue("TagGroup", "List2Time")
End Sub
Sub CloseConfigSheet(Panel, SaveConfig)
if Saveconfig then
SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist") = Panel.Common.ChildControl("TagGroupPlaylist").Text
SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist2") = Panel.Common.ChildControl("TagGroupPlaylist2").Text
SDB.IniFile.StringValue("TagGroup", "List2Time") = Panel.Common.ChildControl("List2Time").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
' answer = SDB.MessageBox("Start of GenerateNewTrack", mtConfirmation, Array(mbYes,mbNo))
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")
if (Len(SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist2")) > 0) AND (Now > CDate(SDB.IniFile.StringValue("TagGroup", "List2Time"))) then
TagGroupPlaylist = SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist2")
else
TagGroupPlaylist = SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist")
end if
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
Set NextSong = NextGroup.Item
if NextSong.TrackOrderStr <> "" then
NextNo = Fix(NextSong.TrackOrderStr / 100)
else
NextNo = 0
end if
NextGroup.Next
if (NOT ByAlbum OR DiscNo = 0 OR NextNo = DiscNo ) then
DJTSG_NbAdded = DJTSG_NbAdded + 1
Call SDB.Player.PlaylistAddTrack( NextSong )
end if
Loop
else
' Return track found
DJTSG_NbAdded = DJTSG_NbAdded + 1
Set GenerateNewTrack = NextSong
Set DJTSG_LastSong = NextSong
end if
DJTSG_LastCall = Now
' answer = SDB.MessageBox("End of GenerateNewTrack", mtConfirmation, Array(mbYes,mbNo))
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