Re: TiedSongsGroups: lets you make tied groups of songs
Posted: Mon Oct 13, 2008 3:50 am
Message from Guest is mine - Login must have timed out
Regards
Regards
The Music Manager for Serious Collectors
http://mediamonkey.com/forum/
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
'
' 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 TagGroupPlaylist, LastSong
Sub InitConfigSheet(Panel)
Dim Edt, Lists, i
Set Edt = SDB.UI.NewLabel(Panel)
Edt.Common.SetRect 1, 1, 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")
End Sub
Sub CloseConfigSheet(Panel, SaveConfig)
if Saveconfig then
SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist") = Panel.Common.ChildControl("TagGroupPlaylist").Text
end if
End Sub
Function GenerateNewTrack
Dim LastGroup, NextSong, NextFound
NextFound = false
if isEmpty(LastSong) AND SDB.Player.PlaylistCount > 0 then
Set LastSong = SDB.Player.PlaylistItems(SDB.Player.PlaylistCount - 1)
end if
if NOT isEmpty(LastSong) then
If Left(LastSong.Custom3, 2) = "LT" Then
Set LastGroup = SDB.Database.QuerySongs("Songs.Custom3='" & LastSong.Custom3 & "' ORDER BY abs(Songs.TrackNumber) ASC")
Do While Not LastGroup.EOF
if LastGroup.Item.TrackOrder > LastSong.TrackOrder then
Set NextSong = LastGroup.Item
NextFound = true
exit do
end if
LastGroup.Next
Loop
end if
end if
If NextFound Then
Set LastSong = NextSong
Set GenerateNewTrack = NextSong
else
Dim CheckPlaylist, RandomTrack, i
TagGroupPlaylist = SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist")
Set CheckPlaylist = SDB.PlaylistByTitle(TagGroupPlaylist).Tracks
i = 0
Do
RandomTrack = Int((Rnd() * CheckPlaylist.Count) + 1)
Set NextSong = CheckPlaylist.Item(RandomTrack)
i = i + 1
Loop while (IsInSongList(NextSong, SDB.Player.CurrentPlaylist) Or SameGroup(NextSong, LastSong)) AND i < CheckPlaylist.Count
If Left(NextSong.Custom3, 2) = "LT" Then
Set LastGroup = SDB.Database.QuerySongs("Songs.Custom3='" & NextSong.Custom3 & "' ORDER BY abs(Songs.TrackNumber) ASC")
Set LastSong = LastGroup.Item
Set GenerateNewTrack = LastGroup.Item
else
Set LastSong = NextSong
Set GenerateNewTrack = NextSong
end if
End If
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 )
if isEmpty(Song1) or isEmpty(Song2) then
SameGroup = False
else
if Song1.SongId <> Song2.SongId AND (Left(Song1.Custom3, 2) <> "LT" OR Song1.Custom3 <> Song2.Custom3) then
SameGroup = False
else
SameGroup = True
end if
end if
End Function
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
'
' 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 TagGroupPlaylist, LastSong
Sub InitConfigSheet(Panel)
Dim Edt, Lists, i
Set Edt = SDB.UI.NewLabel(Panel)
Edt.Common.SetRect 1, 1, 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")
End Sub
Sub CloseConfigSheet(Panel, SaveConfig)
if Saveconfig then
SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist") = Panel.Common.ChildControl("TagGroupPlaylist").Text
end if
End Sub
Function GenerateNewTrack
Dim LastGroup, NextSong, NextFound
NextFound = false
if isEmpty(LastSong) then
Randomize
if SDB.Player.PlaylistCount > 0 then
Set LastSong = SDB.Player.PlaylistItems(SDB.Player.PlaylistCount - 1)
end if
end if
if NOT isEmpty(LastSong) then
If Left(LastSong.Custom3, 2) = "LT" Then
Set LastGroup = SDB.Database.QuerySongs("Songs.Custom3='" & LastSong.Custom3 & "' ORDER BY abs(Songs.TrackNumber) ASC")
Do While Not LastGroup.EOF
if LastGroup.Item.TrackOrder > LastSong.TrackOrder then
Set NextSong = LastGroup.Item
NextFound = true
exit do
end if
LastGroup.Next
Loop
end if
end if
If NextFound Then
Set LastSong = NextSong
Set GenerateNewTrack = NextSong
else
Dim CheckPlaylist, RandomTrack, i
TagGroupPlaylist = SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist")
Set CheckPlaylist = SDB.PlaylistByTitle(TagGroupPlaylist).Tracks
i = 0
Do
RandomTrack = Int(Rnd() * CheckPlaylist.Count)
Set NextSong = CheckPlaylist.Item(RandomTrack)
i = i + 1
Loop while (IsInSongList(NextSong, SDB.Player.CurrentPlaylist) Or SameGroup(NextSong, LastSong)) AND i < CheckPlaylist.Count
If Left(NextSong.Custom3, 2) = "LT" Then
Set LastGroup = SDB.Database.QuerySongs("Songs.Custom3='" & NextSong.Custom3 & "' ORDER BY abs(Songs.TrackNumber) ASC")
Set LastSong = LastGroup.Item
Set GenerateNewTrack = LastGroup.Item
else
Set LastSong = NextSong
Set GenerateNewTrack = NextSong
end if
End If
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 )
if isEmpty(Song1) or isEmpty(Song2) then
SameGroup = False
else
if Song1.SongId <> Song2.SongId AND (Left(Song1.Custom3, 2) <> "LT" OR Song1.Custom3 <> Song2.Custom3) then
SameGroup = False
else
SameGroup = True
end if
end if
End Function
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.
'
' 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
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
ByAlbum = SDB.IniFile.BoolValue("TagGroup", "ByAlbum")
TagGroupPlaylist = SDB.IniFile.StringValue("TagGroup", "DefaultPlaylist")
Set CheckPlaylist = SDB.PlaylistByTitle(TagGroupPlaylist).Tracks
i = 0
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
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
DJTSG_NbAdded = DJTSG_NbAdded + 1
Call SDB.Player.PlaylistAddTrack( NextGroup.Item )
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
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.
'
' 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
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
RandomTrack = Int(Rnd() * AlbumTrackList.Count)
Set NextSong = AlbumTrackList.Item(RandomTrack)
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
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
if (NOT ByAlbum OR DiscNo = 0 OR Fix(NextGroup.Item.TrackOrderStr / 100) = 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