Looking for track transition logger

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

Owyn
Posts: 2018
Joined: Fri Mar 21, 2008 10:55 am
Location: Canada

Looking for track transition logger

Post 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.
Cogito cogito ergo cogito sum. (Ambrose Bierce)
I drink therefore I am. (Monty Python)
Vista 32bit Home Premium SP2 / MM3.2.1.1297 Gold / Last.Fm 1.0.2.22 / IE8
Dell Inspiron 530 (1.8 Core2 / 2GB)
Skin: Vitreous Blue
Scripts: Add/Remove Playstat|Advanced Duplicate Find & Fix|Album Art Tagger|Backup|Batch Art Finder|Calculate Cover Size|Case&Leading Zero Fixer|DB_Audit|DB_Clean|DB_Schema|Event Logger|Genre Finder|Lyricator|Magic Nodes|MM2VLC|Monkey Rok|MusicIP Tagger|PUID Generator|RegExp Find & Replace|Right Click for Scripts|Scriptreloader|SQL Viewer|Stats(Filtered)|Tagging Inconsistencies
ZvezdanD
Posts: 3257
Joined: Thu Jun 08, 2006 7:40 pm

Re: Looking for track transition logger

Post 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
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
Owyn
Posts: 2018
Joined: Fri Mar 21, 2008 10:55 am
Location: Canada

Re: Looking for track transition logger

Post by Owyn »

Thanks.
Got an early Xmas gift. :D
Cogito cogito ergo cogito sum. (Ambrose Bierce)
I drink therefore I am. (Monty Python)
Vista 32bit Home Premium SP2 / MM3.2.1.1297 Gold / Last.Fm 1.0.2.22 / IE8
Dell Inspiron 530 (1.8 Core2 / 2GB)
Skin: Vitreous Blue
Scripts: Add/Remove Playstat|Advanced Duplicate Find & Fix|Album Art Tagger|Backup|Batch Art Finder|Calculate Cover Size|Case&Leading Zero Fixer|DB_Audit|DB_Clean|DB_Schema|Event Logger|Genre Finder|Lyricator|Magic Nodes|MM2VLC|Monkey Rok|MusicIP Tagger|PUID Generator|RegExp Find & Replace|Right Click for Scripts|Scriptreloader|SQL Viewer|Stats(Filtered)|Tagging Inconsistencies
Owyn
Posts: 2018
Joined: Fri Mar 21, 2008 10:55 am
Location: Canada

Re: Looking for track transition logger

Post 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.
Last edited by Owyn on Sat Jan 03, 2009 6:21 am, edited 1 time in total.
Cogito cogito ergo cogito sum. (Ambrose Bierce)
I drink therefore I am. (Monty Python)
Vista 32bit Home Premium SP2 / MM3.2.1.1297 Gold / Last.Fm 1.0.2.22 / IE8
Dell Inspiron 530 (1.8 Core2 / 2GB)
Skin: Vitreous Blue
Scripts: Add/Remove Playstat|Advanced Duplicate Find & Fix|Album Art Tagger|Backup|Batch Art Finder|Calculate Cover Size|Case&Leading Zero Fixer|DB_Audit|DB_Clean|DB_Schema|Event Logger|Genre Finder|Lyricator|Magic Nodes|MM2VLC|Monkey Rok|MusicIP Tagger|PUID Generator|RegExp Find & Replace|Right Click for Scripts|Scriptreloader|SQL Viewer|Stats(Filtered)|Tagging Inconsistencies
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Looking for track transition logger

Post 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).
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Owyn
Posts: 2018
Joined: Fri Mar 21, 2008 10:55 am
Location: Canada

Re: Looking for track transition logger

Post 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
Cogito cogito ergo cogito sum. (Ambrose Bierce)
I drink therefore I am. (Monty Python)
Vista 32bit Home Premium SP2 / MM3.2.1.1297 Gold / Last.Fm 1.0.2.22 / IE8
Dell Inspiron 530 (1.8 Core2 / 2GB)
Skin: Vitreous Blue
Scripts: Add/Remove Playstat|Advanced Duplicate Find & Fix|Album Art Tagger|Backup|Batch Art Finder|Calculate Cover Size|Case&Leading Zero Fixer|DB_Audit|DB_Clean|DB_Schema|Event Logger|Genre Finder|Lyricator|Magic Nodes|MM2VLC|Monkey Rok|MusicIP Tagger|PUID Generator|RegExp Find & Replace|Right Click for Scripts|Scriptreloader|SQL Viewer|Stats(Filtered)|Tagging Inconsistencies
Owyn
Posts: 2018
Joined: Fri Mar 21, 2008 10:55 am
Location: Canada

Re: Looking for track transition logger

Post by Owyn »

The reason I was looking for real Play complete was to specifically correlate DebugView, Procmon, Last.fm, etc. logs to specific events.
Cogito cogito ergo cogito sum. (Ambrose Bierce)
I drink therefore I am. (Monty Python)
Vista 32bit Home Premium SP2 / MM3.2.1.1297 Gold / Last.Fm 1.0.2.22 / IE8
Dell Inspiron 530 (1.8 Core2 / 2GB)
Skin: Vitreous Blue
Scripts: Add/Remove Playstat|Advanced Duplicate Find & Fix|Album Art Tagger|Backup|Batch Art Finder|Calculate Cover Size|Case&Leading Zero Fixer|DB_Audit|DB_Clean|DB_Schema|Event Logger|Genre Finder|Lyricator|Magic Nodes|MM2VLC|Monkey Rok|MusicIP Tagger|PUID Generator|RegExp Find & Replace|Right Click for Scripts|Scriptreloader|SQL Viewer|Stats(Filtered)|Tagging Inconsistencies
ZvezdanD
Posts: 3257
Joined: Thu Jun 08, 2006 7:40 pm

Re: Looking for track transition logger

Post 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.
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
Owyn
Posts: 2018
Joined: Fri Mar 21, 2008 10:55 am
Location: Canada

Re: Looking for track transition logger

Post 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
Cogito cogito ergo cogito sum. (Ambrose Bierce)
I drink therefore I am. (Monty Python)
Vista 32bit Home Premium SP2 / MM3.2.1.1297 Gold / Last.Fm 1.0.2.22 / IE8
Dell Inspiron 530 (1.8 Core2 / 2GB)
Skin: Vitreous Blue
Scripts: Add/Remove Playstat|Advanced Duplicate Find & Fix|Album Art Tagger|Backup|Batch Art Finder|Calculate Cover Size|Case&Leading Zero Fixer|DB_Audit|DB_Clean|DB_Schema|Event Logger|Genre Finder|Lyricator|Magic Nodes|MM2VLC|Monkey Rok|MusicIP Tagger|PUID Generator|RegExp Find & Replace|Right Click for Scripts|Scriptreloader|SQL Viewer|Stats(Filtered)|Tagging Inconsistencies
Post Reply