Page 1 of 1

Looking for track transition logger

Posted: Tue Dec 23, 2008 7:23 am
by Owyn
Looking for a short script to log Track Played, Track Advance and Track Start events to a log file.
Needs most accurate time stamps available.

Nothing fancy. Can run until MM exits.

Have not used this section of the API yet or I would give it a try myself.

Re: Looking for track transition logger

Posted: Tue Dec 23, 2008 12:55 pm
by ZvezdanD

Code: Select all

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub OnStartUp()
    Script.RegisterEvent SDB, "OnPlay", "OnPlay"
    Script.RegisterEvent SDB, "OnStop", "OnStop"
    Script.RegisterEvent SDB, "OnSeek", "OnSeek"
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub OnPlay()
    Log "Play"
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub OnStop()
    Log "Stop"
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub OnSeek()
    Log "Seek"
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Log(sText)
    Dim oLogFile
    Dim dTime

    Set oLogFile = CreateObject("Scripting.FileSystemObject").OpenTextFile _
            (Script.ScriptPath & ".log", 8, True)
    dTime = Timer
    oLogFile.WriteLine Now & Mid(FormatNumber(dTime - Int(dTime), 3), 2) _
            & " - " & sText & " - " & SDB.Player.CurrentSong.Path
    oLogFile.Close
End Sub

Re: Looking for track transition logger

Posted: Tue Dec 23, 2008 2:05 pm
by Owyn
Thanks.
Got an early Xmas gift. :D

Re: Looking for track transition logger

Posted: Sat Jan 03, 2009 5:42 am
by Owyn
Worked fine. I made some minor changes but that was trivial once I had your script to start with.
I checked the Wiki and could not see any event available for Play Complete. Oh well.

Code: Select all

' MediaMonkey3 Script
' LogPlays.vbs
Option Explicit
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub OnStartUp()
        Script.RegisterEvent SDB, "OnPlay", "OnPlay"
        Script.RegisterEvent SDB, "OnStop", "OnStop"
        Script.RegisterEvent SDB, "OnPause", "OnPause"
        Script.RegisterEvent SDB, "OnSeek", "OnSeek"
        Log "***Started***"
    End Sub

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub OnPlay()
        Log "Play"
    End Sub

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub OnPause()
        Log "Pause"
    End Sub

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub OnStop()
        Log "Stop"
    End Sub

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub OnSeek()
        Log "Seek"
    End Sub

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub Log(sText)
        Dim oLogFile
        Dim dTime

        Set oLogFile = CreateObject("Scripting.FileSystemObject").OpenTextFile _
                (Script.ScriptPath & ".log", 8, True)
        dTime = Timer
        oLogFile.WriteLine Now & Mid(FormatNumber(dTime - Int(dTime), 3), 2) _
                & " - " & sText & " - " & SDB.Player.CurrentSong.Path
        oLogFile.Close
    End Sub
Appreciate the appending to the log. I sometimes keep the log open during testing and edit in notes about the test. e.g.

Code: Select all

****Start of new test. 
03/01/2009 4:53:23 AM.643 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\03 - Time of the Preacher Theme.mp3
03/01/2009 4:53:23 AM.648 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\03 - Time of the Preacher Theme.mp3
03/01/2009 4:54:36 AM.342 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\04 - Medley - Blue Rock Montana - Red Headed Stranger.mp3
03/01/2009 4:54:36 AM.346 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\04 - Medley - Blue Rock Montana - Red Headed Stranger.mp3
03/01/2009 4:56:42 AM.613 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\07 - Time of the Preacher Theme.mp3
03/01/2009 4:56:42 AM.615 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\07 - Time of the Preacher Theme.mp3
03/01/2009 4:57:09 AM.230 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\08 - Just as I Am.mp3
03/01/2009 4:57:09 AM.232 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\08 - Just as I Am.mp3
*****Duplicate Plays. Crossfade??****
*****Exited MM. Munged Last.Fm password. Restart MM and disable crossfade*****

03/01/2009 5:21:31 AM.936 - ***Started*** - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\09 - Denver.mp3
03/01/2009 5:21:41 AM.496 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\10 - O'er the Waves.mp3
03/01/2009 5:21:41 AM.496 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\10 - O'er the Waves.mp3
**Fixed last.fm password via service**
**Still have duplicate plays with Crossfade disabled**

03/01/2009 5:29:38 AM.506 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\11 - Down Yonder.mp3
03/01/2009 5:29:38 AM.508 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\11 - Down Yonder.mp3
03/01/2009 5:31:30 AM.936 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\16 - Bach Minuet in G.mp3
03/01/2009 5:31:30 AM.939 - Play - C:\Users\Public\Music\Willie Nelson\Red Headed Stranger\16 - Bach Minuet in G.mp3
Noticed that I am getting duplicate OnPlay events. DIIK.

Thanks again for the help.

Re: Looking for track transition logger

Posted: Sat Jan 03, 2009 6:05 am
by trixmoto
You've registered two OnPlay events, that's why you're getting two log entries for it. If in the OnPlay function you store the current track then when the next one fires you can run any code you want to on the previous track (to simulate a OnPlayComplete).

Re: Looking for track transition logger

Posted: Sat Jan 03, 2009 6:18 am
by Owyn
trixmoto wrote:You've registered two OnPlay events, that's why you're getting two log entries for it. If in the OnPlay function you store the current track then when the next one fires you can run any code you want to on the previous track (to simulate a OnPlayComplete).
The old cut/copy and smash trick. Should have looked for the obvious.
Only excuse is insomniac testing.

Edit: Fixed. The second OnPlay back to OnStop

Re: Looking for track transition logger

Posted: Sat Jan 03, 2009 6:28 am
by Owyn
The reason I was looking for real Play complete was to specifically correlate DebugView, Procmon, Last.fm, etc. logs to specific events.

Re: Looking for track transition logger

Posted: Sat Jan 03, 2009 6:44 am
by ZvezdanD
Owyn wrote:

Code: Select all

03/01/2009 4:53:23 AM.643
This time format with AM/PM is not very nice if you want to store milliseconds. It should be better if you switch to 24 hours time format. Or delete Mid(FormatNumber(dTime - Int(dTime), 3), 2) to remove milliseconds from a log.

Re: Looking for track transition logger

Posted: Sat Jan 03, 2009 7:30 am
by Owyn
Yeah. I had made a mental note to fix that. (Now an actual note).

FYI: Here is an example of how I used the script.
http://www.mediamonkey.com/forum/viewto ... 04#p183404