Page 1 of 1

Script Request for Party Mode

Posted: Sun Nov 28, 2010 8:47 am
by Onweerwolf
Hi guys, I was wondering if something like this is possible: during parties I often have an autoplaylist that's based on popular songs that everyone likes seeding the auto DJ. Then everyone that feels like it can browse the library and add songs to the now playing queue if they want. However sometimes guests 'abuse' their freedom and add a # of songs worth several hours to the playlist to the annoyance of the other guests. To prevent such, how about a script that limits the # of upcoming songs that are allowed in now playing during party mode. Let's say you limit it to 5. Then if someone adds 4 songs to the now playing queue the total will become 5 (as auto-dj also adds one song itself) and the ability to adds songs temporarily ceases until the next song starts at which point one new song can be added. Hopefully at that point the 'Serial Song Adder' has lost interest and moved on for the time being, allowing someone else to add some songs or let auto-dj take care of the work again.

Doable?

Re: Script Request for Party Mode

Posted: Tue Dec 14, 2010 5:47 pm
by Onweerwolf
So, bumping this a bit. Does anyone know if it's a possibility?

I basically just need a script that limits the amount of tracks that you can add to the now playing list after the current playing song.

Re: Script Request for Party Mode

Posted: Tue Dec 14, 2010 5:53 pm
by nohitter151
I'd think it's probably possible, but unless you want to write it yourself, there doesn't seem to be much interest for it.

Re: Script Request for Party Mode

Posted: Tue Dec 14, 2010 5:56 pm
by Onweerwolf
Heh! I'd write it, but I have no clue how to do that. :(

Re: Script Request for Party Mode

Posted: Tue Apr 17, 2012 8:01 am
by IMcA
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

Re: Script Request for Party Mode

Posted: Tue Apr 17, 2012 9:09 am
by Onweerwolf
That looks promising, I will check this out when I have the time. :D