by IMcA » Tue Apr 17, 2012 8:01 am
I was looking for the same thing, but also with the added ability prevent duplicate songs being added.
I found the PartyLimit script
http://www.mediamonkey.com/forum/viewto ... =2&t=48536
This script limits to 10 songs in the now playing list and prevents the same artist being added more than once.
For my purpose I only require that the same song is not added. So I have modified the original script to check for duplicate song titles instead of duplicate artists.
I intend to use this script with party mode, in my case I would like to load a "starting" playlist of say 20 songs and then start it playing in party mode, and then once that list falls below 10 to allow more songs to be added and then keep the limit at 10.
So I have simplified the deletion routine, so that it would only delete the last added song, the original routine would try to cull down to the limit and therefore take my "starting" playlist with it.
I also tweaked the deletion routine so that it deletes before showing a warning box, otherwise I noticed that if the warning box is open while a track ends it changes the position of the just added track and it doesn't get deleted.
Another problem I encountered was when the now playing list is over the limit and the song changed, it would start the deletion routine, so I also had to add a routine to prevent the deletion routine from running when the track changed.
I have not done any coding for over 10 years, but this is more of a hack job anyway, but it seems to do the job that I need.
I use this with Party Mode and with AutoDJ using an autoplaylist with a last played filter as a source, this ensures that AutoDJ will only add tracks that have not yet been played.
Like the original author, I am happy for anyone to do what they want with this.
Hopefully this modified script works for the OP's request. You just need to modify 10 to whatever number you wish to use.
Code: Select all
Sub OnStartup
SDB.IniFile.BoolValue("PartyLimit", "Enabled") = false
'add toolbar button
Set but = SDB.UI.AddMenuItem(SDB.UI.Menu_TbStandard, 0, 0)
but.Caption = "Party limit"
but.IconIndex = 48
but.UseScript = Script.ScriptPath
but.OnClickFunc = "ToggleOnOff"
Set SDB.Objects("PartyLimitButton") = but
'register events for PlayEnd and CheckNowPlaying subs
Call Script.RegisterEvent(SDB, "OnPlaybackEnd", "PlayEnd")
Call Script.RegisterEvent(SDB, "OnNowPlayingModified", "CheckNowPlaying")
End Sub
Sub ToggleOnOff(arg)
IsEnabled = SDB.IniFile.BoolValue("PartyLimit", "Enabled")
Set but = SDB.Objects("PartyLimitButton")
If(IsEnabled) Then
SDB.IniFile.BoolValue("PartyLimit", "Enabled") = false
but.Checked = false
Else
SDB.IniFile.BoolValue("PartyLimit", "Enabled") = true
but.Checked = true
End If
Set SDB.Objects("PartyLimitButton") = but
End Sub
'Sub to disable script on track change, to prevent culling of a playlist larger than limit
Sub PlayEnd
SDB.IniFile.BoolValue("PartyLimit", "Enabled") = false
End Sub
Sub CheckNowPlaying
Set but = SDB.Objects("PartyLimitButton")
IsEnabled = SDB.IniFile.BoolValue("PartyLimit", "Enabled")
IsButton = but.Checked
'Only continue if button is down and script is enabled
If Not (IsEnabled) Then
If Not (IsButton) Then
'Button is up and script is disabled in inifile, so exit
Exit Sub
End If
'Button is down and script is disabled in inifile, so set inifile to true and exit sub
SDB.IniFile.BoolValue("PartyLimit", "Enabled") = true
Exit Sub
End If
'First step, cull the now playing list if there are too many
Set NowPlayingList = SDB.Player.CurrentSongList
If(NowPlayingList.Count > 10) Then
'Delete last track in NowPlayingList
SDB.Player.PlaylistDelete(NowPlayingList.Count - 1)
'Message box called after delete, otherwise track change during dialog can cause track to sneak around deletion
Call SDB.MessageBox("Maximum of 10 songs in queue. Try again later.", mtInformation, Array(mbOk))
End If
'Now look for duplicate objects and delete them
Set NowPlayingList = SDB.Player.CurrentSongList
Set TrackNamesUsed = CreateObject("Scripting.Dictionary")
Set PositionsToRemove = CreateObject("Scripting.Dictionary")
For i = 0 to (NowPlayingList.Count - 1)
Set NowPlayingListSong = NowPlayingList.Item(i)
TrackName = NowPlayingListSong.Title
If(TrackNamesUsed.Exists( TrackName )) Then
PositionsToRemove.Add i, i
Else
TrackNamesUsed.Add TrackName, TrackName
End If
Next
'Now get removing!
If(PositionsToRemove.Count > 0) Then
Call SDB.MessageBox("Song already in queue.", mtInformation, Array(mbOk))
End If
PositionsToRemoveItems = PositionsToRemove.Items
'As we remove things the list index changes on us
PositionToRemoveIncrement = 0
For Each PositionToRemove in PositionsToRemoveItems
SDB.Player.PlaylistDelete( PositionToRemove - PositionToRemoveIncrement)
PositionToRemoveIncrement = PositionToRemoveIncrement + 1
Next
End Sub
I was looking for the same thing, but also with the added ability prevent duplicate songs being added.
I found the PartyLimit script http://www.mediamonkey.com/forum/viewtopic.php?f=2&t=48536
This script limits to 10 songs in the now playing list and prevents the same artist being added more than once.
For my purpose I only require that the same song is not added. So I have modified the original script to check for duplicate song titles instead of duplicate artists.
I intend to use this script with party mode, in my case I would like to load a "starting" playlist of say 20 songs and then start it playing in party mode, and then once that list falls below 10 to allow more songs to be added and then keep the limit at 10.
So I have simplified the deletion routine, so that it would only delete the last added song, the original routine would try to cull down to the limit and therefore take my "starting" playlist with it.
I also tweaked the deletion routine so that it deletes before showing a warning box, otherwise I noticed that if the warning box is open while a track ends it changes the position of the just added track and it doesn't get deleted.
Another problem I encountered was when the now playing list is over the limit and the song changed, it would start the deletion routine, so I also had to add a routine to prevent the deletion routine from running when the track changed.
I have not done any coding for over 10 years, but this is more of a hack job anyway, but it seems to do the job that I need.
I use this with Party Mode and with AutoDJ using an autoplaylist with a last played filter as a source, this ensures that AutoDJ will only add tracks that have not yet been played.
Like the original author, I am happy for anyone to do what they want with this.
Hopefully this modified script works for the OP's request. You just need to modify 10 to whatever number you wish to use.
[code]
Sub OnStartup
SDB.IniFile.BoolValue("PartyLimit", "Enabled") = false
'add toolbar button
Set but = SDB.UI.AddMenuItem(SDB.UI.Menu_TbStandard, 0, 0)
but.Caption = "Party limit"
but.IconIndex = 48
but.UseScript = Script.ScriptPath
but.OnClickFunc = "ToggleOnOff"
Set SDB.Objects("PartyLimitButton") = but
'register events for PlayEnd and CheckNowPlaying subs
Call Script.RegisterEvent(SDB, "OnPlaybackEnd", "PlayEnd")
Call Script.RegisterEvent(SDB, "OnNowPlayingModified", "CheckNowPlaying")
End Sub
Sub ToggleOnOff(arg)
IsEnabled = SDB.IniFile.BoolValue("PartyLimit", "Enabled")
Set but = SDB.Objects("PartyLimitButton")
If(IsEnabled) Then
SDB.IniFile.BoolValue("PartyLimit", "Enabled") = false
but.Checked = false
Else
SDB.IniFile.BoolValue("PartyLimit", "Enabled") = true
but.Checked = true
End If
Set SDB.Objects("PartyLimitButton") = but
End Sub
'Sub to disable script on track change, to prevent culling of a playlist larger than limit
Sub PlayEnd
SDB.IniFile.BoolValue("PartyLimit", "Enabled") = false
End Sub
Sub CheckNowPlaying
Set but = SDB.Objects("PartyLimitButton")
IsEnabled = SDB.IniFile.BoolValue("PartyLimit", "Enabled")
IsButton = but.Checked
'Only continue if button is down and script is enabled
If Not (IsEnabled) Then
If Not (IsButton) Then
'Button is up and script is disabled in inifile, so exit
Exit Sub
End If
'Button is down and script is disabled in inifile, so set inifile to true and exit sub
SDB.IniFile.BoolValue("PartyLimit", "Enabled") = true
Exit Sub
End If
'First step, cull the now playing list if there are too many
Set NowPlayingList = SDB.Player.CurrentSongList
If(NowPlayingList.Count > 10) Then
'Delete last track in NowPlayingList
SDB.Player.PlaylistDelete(NowPlayingList.Count - 1)
'Message box called after delete, otherwise track change during dialog can cause track to sneak around deletion
Call SDB.MessageBox("Maximum of 10 songs in queue. Try again later.", mtInformation, Array(mbOk))
End If
'Now look for duplicate objects and delete them
Set NowPlayingList = SDB.Player.CurrentSongList
Set TrackNamesUsed = CreateObject("Scripting.Dictionary")
Set PositionsToRemove = CreateObject("Scripting.Dictionary")
For i = 0 to (NowPlayingList.Count - 1)
Set NowPlayingListSong = NowPlayingList.Item(i)
TrackName = NowPlayingListSong.Title
If(TrackNamesUsed.Exists( TrackName )) Then
PositionsToRemove.Add i, i
Else
TrackNamesUsed.Add TrackName, TrackName
End If
Next
'Now get removing!
If(PositionsToRemove.Count > 0) Then
Call SDB.MessageBox("Song already in queue.", mtInformation, Array(mbOk))
End If
PositionsToRemoveItems = PositionsToRemove.Items
'As we remove things the list index changes on us
PositionToRemoveIncrement = 0
For Each PositionToRemove in PositionsToRemoveItems
SDB.Player.PlaylistDelete( PositionToRemove - PositionToRemoveIncrement)
PositionToRemoveIncrement = PositionToRemoveIncrement + 1
Next
End Sub[/code]