Page 1 of 4

Clear Now Playing 3.1 - Updated 09/07/2012

Posted: Tue Nov 22, 2005 7:49 am
by trixmoto
I thought I'd created a topic on this, but obviously I haven't. Here is a bit of background: http://www.mediamonkey.com/forum/viewtopic.php?t=4644
judas wrote:Hey...i checked out the clear now playing script in your page, its a great idea...one small suggestion to add to the next version: why not leave say 10 (or five) files? that way you wouldn't start with an empty now playing...or i dont know if it can be done, but is there a way to know what was the last song in now playing that was played? this way you could remove all songs before that one and you get to keep the ones you didnt get to hear.

Code: Select all

'
' MediaMonkey Script
'
' NAME: ClearNowPlaying 3.1
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 09/07/2012
'
' INSTALL: Copy to Scripts\Auto directory
'
' FIXES: Fixed mode setting not storing correctly
'

Option Explicit       

Sub OnStartup
  'default settings
  Dim ini : Set ini = SDB.IniFile
  If ini.StringValue("ClearNowPlaying","Limit") = "" Then
    ini.IntValue("ClearNowPlaying","Limit") = 100
  End If
  If ini.StringValue("ClearNowPlaying","Mode") = "" Then
    ini.IntValue("ClearNowPlaying","Mode") = 4
  End If
  
  'add option sheet
  Call SDB.UI.AddOptionSheet("ClearNowPlaying Settings",Script.ScriptPath,"InitSheet","SaveSheet",-2)
  
  'run script
  Dim cur : cur = ini.IntValue("Player","NowPlayingPosition")
  Dim lim : lim = ini.IntValue("ClearNowPlaying","Limit")
  If SDB.Player.PlaylistCount > lim Then 
    Select Case ini.IntValue("ClearNowPlaying","Mode")
      Case 1
        Call SDB.Player.PlaylistClear()
      Case 2
        Call ClearPlayed(cur,lim) 
      Case 3
        Call ClearExtra(lim)
      Case 4
        If Not ClearPlayed(cur,lim) Then 
          Call ClearExtra(lim)
        End If        
    End Select
  End If
End Sub

Function ClearPlayed(cur,lim)
  Dim i : i = 0
  For i = 0 To cur-1
    Call SDB.Player.PlaylistDelete(0)
  Next
  If SDB.Player.PlaylistCount > lim Then
    ClearPlayed = False
  Else
    ClearPlayed = True
  End If
End Function

Function ClearExtra(lim)
  Dim i : i = 0
  For i = lim To SDB.Player.PlaylistCount
    Call SDB.Player.PlaylistDelete(lim)
  Next   
  ClearExtra = True
End Function

Sub InitSheet(Sheet)
  Dim ini : Set ini = SDB.IniFile  
  Dim ui : Set ui = SDB.UI
  Dim edt : Set edt = ui.NewLabel(Sheet)
  edt.Common.SetRect 5, 10, 50, 20
  edt.Caption = "Run mode:"
  edt.Autosize = False  
  
  Set edt = ui.NewDropdown(Sheet)
  edt.Common.SetRect 80, 7, 300, 20
  edt.Common.ControlName = "CNPMode" 
  edt.Style = 2
  edt.AddItem("Disabled")
  edt.AddItem("Clear all tracks")
  edt.AddItem("Clear played tracks")
  edt.AddItem("Clear tracks leaving 'limit' remaining")
  edt.AddItem("Clear played tracks then leave 'limit' remaining")
  edt.ItemIndex = ini.IntValue("ClearNowPlaying","Mode")
  
  Set edt = ui.NewLabel(Sheet)
  edt.Common.SetRect 5, 35, 50, 20
  edt.Caption = "Track limit:"
  edt.Autosize = False
  
  Set edt = ui.NewSpinEdit(Sheet)
  edt.Common.SetRect 80, 32, 50, 20
  edt.Common.ControlName = "CNPLimit"
  edt.MinValue = 0
  edt.MaxValue = 9999
  edt.Value = ini.IntValue("ClearNowPlaying","Limit")            
End Sub

Sub SaveSheet(Sheet)
  Dim ini : Set ini = SDB.IniFile  
  ini.IntValue("ClearNowPlaying","Mode") = Sheet.Common.ChildControl("CNPMode").ItemIndex
  ini.IntValue("ClearNowPlaying","Limit") = Sheet.Common.ChildControl("CNPLimit").Value
End Sub

Posted: Tue Nov 22, 2005 8:43 am
by trixmoto
Is there a way to know what was the last song in now playing that was played? I notice that when you close MM and reopen it, the song that was selected in now playing is selected again. Where is this information stored and can it be accessed from a script?

Posted: Tue Nov 22, 2005 9:42 am
by psyXonova
Current now playing list is stored inside mediamonkey.m3u which is located under the My Music/Media Monkey folder.

Now playing position (or else last song played in now playing list) is stored inside the MediaMonkey.ini file, Player section, NowPlayingPosition line.
If NowPlayingPosition is 1 then the last song played was the second song inside the mediamonkey.m3u playlist.

There is a method (cant recall it now) to access MediaMonkey.ini entries.
As for m3u, cant remember if there is an out of the box method, but it is just a text file and thus you can easily parse its contents

Posted: Tue Nov 22, 2005 10:15 am
by trixmoto
I was looking in the database. Never though to look in the ini. Thanks! :)

Posted: Tue Nov 22, 2005 10:18 am
by trixmoto
My .ini says "NowPlayingPosition=16" but in my Now Playing list the selected song is 62. Any ideas why the discrepancy?

Posted: Tue Nov 22, 2005 10:26 am
by psyXonova
I believe (not sure though) that the ini entry is written while MM shuts downs, so it can continue playback after it has restarted. So, shut down MM and the check for NowPlayingPosition (should be 61).
Now playing position is available through other methods when MM is running so there is no need to be written inside the ini.

Posted: Tue Nov 22, 2005 10:27 am
by trixmoto
It turns out MM is completely ignoring the .ini in the MM folder and created a new one in MyMusic folder. Why is it ignoring my .ini file?

Posted: Tue Nov 22, 2005 10:31 am
by psyXonova
Ts, forgot to mention that MM reads the ini file inside my music folder
This way every user can personalize MM even on the same computer!

now playing list is personalized also

Posted: Tue Nov 22, 2005 10:38 am
by trixmoto
I thought if you put an ini in the program folder then it used this instead?

Anyway, any idea how to read from the ini file? [Found in helpfile!]

Posted: Tue Nov 22, 2005 11:26 am
by judas
I hope i could be of any help here... :-)

Posted: Tue Nov 22, 2005 11:28 am
by trixmoto
Ok here is the new script. Much more advanced:

1) New version allows user to set limit to anything (default=100).
2) Has the option of:
a) Clearing list if over the limit (removing all)
b) Reducing list size to the limit (removing from the end)
c) Removing those before currently playing (removing from the beginning)

N.B. Option C - If this is still over the limit then option B is run and if you are listening to your list with shuffle mode on then this option doesn't really make sense!

An installer for this script can be downloaded from my website.

Code: Select all

See first post

Posted: Tue Nov 22, 2005 12:49 pm
by judas
WOW!!! I was needing this...now MM loads so fast!!!!!

Heres something in return trix:

Image

Posted: Wed Nov 23, 2005 1:37 am
by onkel_enno
Doesn't AutoDJ do the same???

Posted: Wed Nov 23, 2005 4:36 am
by trixmoto
1) I don't think Auto-DJ does this when you start up. This script was originally designed to help load MM because it was struggling to read in a long Now Playing list on startup

2) If Auto-DJ does do this, then you'll be glad to know that my script is backward compatible with MM2.4 so people without Auto-DJ will still have a solution!

:)

Posted: Wed Nov 23, 2005 5:15 am
by onkel_enno
I didn't want to criticize it, I only wanted to give a hint :wink: :)