Skip to main content

Topic: foo_enhanced_playcount - Record every time a song plays (JScript/WSH) (Read 983 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • MordredKLB
  • [*][*][*]
  • Developer
foo_enhanced_playcount - Record every time a song plays (JScript/WSH)
I wrote a little component to record the timestamp of every play of every song (after the component was installed). This component provides three fields right now, all of which return JSON formatted arrays.

  • %played_times% - Date formatted list - ["2012-08-04 15:58:37", "2012-12-10 14:40:46", "2018-01-02 23:38:13"]
  • %played_times_js% - JS timestamp list: [1344117517000, 1355172047000, 1514957893431]
  • %played_times_raw% - raw foobar timestamps: [129885911170000000, 129996456470000000, 131594314934316754]

Unfortunately, there's no way to write a component that honors the $meta_num/$meta(prop, index) standard (because it's not a meta field) so the only use this will really have is in JScript/WSH panels where you can actually loop through the javascript and do fancy things.

IMO, %played_times_js% is by far the most useful because you can actually do stuff with it, i.e. after retrieving the value, looping through and calling new Date() on it. Will add some example code for that.

Note: If you have foo_playcount installed already, then the first time the song is played after adding this component, it will also append the %first_played% and %last_played% values to the array. Sorry if you've already played a song 68 other times, there's no way of knowing when those times were. Currently considering querying last.fm to retrieve those stored play times as well.

Note: If you have a version installed prior to v.1.0.2, you will have to manually delete it from your components folder! The filename has changed from foo_enhanced_playback_statistics to foo_enhanced_playcount. Foobar will fail to launch if both are installed at the same time. Please delete the entire foo_enhanced_playback_statistics folder.
  • Last Edit: 11 January, 2018, 04:26:52 PM by MordredKLB

  • MordredKLB
  • [*][*][*]
  • Developer
Re: foo_enhanced_playcount - Record every time a song plays (JScript/WSH)
Reply #1
How to use this:
Code: [Select]
var raw = fb.TitleFormat('[%played_times_js%]').Eval();
var playedTimes = [];
try {
playedTimes = JSON.parse(raw); // this is required because the value is a string
} catch (e) {
fb.trace('<<< ERROR parsing JSON >>>');  // you probably don't need this try/catch, but it was helpful in my debugging
}
for (i=0; i < playedTimes.length; i++) {
var p = new Date(playedTimes[i]);
// do something with this value
}

Just as an example of what you can do, I'm taking the individual play times and plotting them on a song "lifecycle" timeline where it starts at the date the song was added, and runs to the present. I calculate each play's "age" by subtracting it from the current time (new Date() ), and then use the ratio of age / added to determine where to draw the line.

For the record, you can convert a Foobar string timestamp ("2018-01-04 00:36:15") into a string you can pass into new Date() by doing the following:
Code: [Select]
var added = fb.TitleFormat('%added%').Eval().replace(' ','T');
  • Last Edit: 11 January, 2018, 04:32:18 PM by MordredKLB

  • MordredKLB
  • [*][*][*]
  • Developer
Re: foo_enhanced_playcount - Record every time a song plays (JScript/WSH)
Reply #2
v.1.0.1 released
 - Updated the component so that it returns an empty JSON array if no playtimes have been saved so far.

This version is obsolete, but leaving it up as it's the last released version using the old filename.
  • Last Edit: 11 January, 2018, 04:33:19 PM by MordredKLB

  • MordredKLB
  • [*][*][*]
  • Developer
Re: foo_enhanced_playcount - Record every time a song plays (JScript/WSH)
Reply #3
So, I know I said I wouldn't query last.fm, but now I'm considering querying last.fm when we're about to record a new play. When saving this data to the component's index db, I plan to remove all plays that the component already knows about. That means this would only record last.fm plays with a timestamp the component didn't record or can't find from %first_played%/%last_played%.

There are some issues with this, namely that last.fm does not differentiate beyond "artist - album - tracktitle" where foo_playcount and this component also use %date% %discnumber% and %tracknumber% to differentiate songs.

For example:
I've played the song "Battery" from the original Master of Puppets release in 1986 five times.
I just got the 10 disc Master of Puppets reissue which came out in 2017. Last.fm will report plays of "Battery" from disc 1 and also the 1986 release.
Even worse, Battery appears 4 other times in different live recordings on the 10 disc reissue. Because my tagging does not separate out all those discs (i.e. for one of the live discs, album is tagged "Master of Puppets" and not "Live at Solnahallen, Stockholm, Sweden - September 26th, 1986") if I play "Battery" from that live disc, it will also count as a play of the song on the 1986 release, which is very obviously wrong.

last.fm does include MBID's for releases and recordings, but in my testing they are very often wildly wrong (when they are even present) and it seems every version of "Battery" will map to the same MBID, regardless of whether they really are different or not.

Is this a limitation people are willing to live with? Does a system that works perfectly 98% of the time, but drastically overcounts plays the other 2% of the time okay? Should last.fm plays be mixed in with the standard calls, or separated from the other plays (i.e. adding a %played_times_lastfm_js% field)?

  • loz
  • [*]
Re: foo_enhanced_playcount - Record every time a song plays (JScript/WSH)
Reply #4
Is this a limitation people are willing to live with?
Yes. Absolutely. Either in this component or another separate playcount component.

And in case you missed it,Last.fm is planning on revamping their api in the coming months according to the devs posting on the getsatisfaction.com/lastfm board. What that means at this point I couldn't tell you, but hopefully they'll add some new endpoints. Thanks.

  • jazzthieve
  • [*][*][*][*][*]
Re: foo_enhanced_playcount - Record every time a song plays (JScript/WSH)
Reply #5
Is this a limitation people are willing to live with? Does a system that works perfectly 98% of the time, but drastically overcounts plays the other 2% of the time okay? Should last.fm plays be mixed in with the standard calls, or separated from the other plays (i.e. adding a %played_times_lastfm_js% field)?

I'd say no. This would be a reason for me to avoid it completely. Most scrobbles on last.fm that are not from the user itself come from either youtube or spotify and spotify in particular is a complete mess with its tagging. The more someone uses other sources to scrobble which they didn't tag themselves the more there will be a disconnection between the "real" plays and the ones reported. What loz is saying about lastfm revamping their api in the coming months should be taken with a serious grain of salt as the site has been in beta since september 2015 and new implementations are moving on with a snail pace (and getting slower).

  • MordredKLB
  • [*][*][*]
  • Developer
Re: foo_enhanced_playcount - Record every time a song plays (JScript/WSH)
Reply #6
I'd say no. This would be a reason for me to avoid it completely. Most scrobbles on last.fm that are not from the user itself come from either youtube or spotify and spotify in particular is a complete mess with its tagging. The more someone uses other sources to scrobble which they didn't tag themselves the more there will be a disconnection between the "real" plays and the ones reported. What loz is saying about lastfm revamping their api in the coming months should be taken with a serious grain of salt as the site has been in beta since september 2015 and new implementations are moving on with a snail pace (and getting slower).
Yeah, I'm not holding my breath on the API changing anytime soon.

You're actually bringing up a second issue. I was only referencing the first where an album with the same song on multiple tracks (live versions/demos etc.) could show up all together (assuming the song isn't tagged differently for whatever reason). That's the overcounting problem.

When you're scrobbling songs you haven't tagged, then there's a possibility it won't show up in the list. I tag using an edition field because I don't want the album title to be "Master of Puppets [2017 Deluxe Remaster]". If Spotify or whoever has that as the album title then when I look for plays with an album exactly matching "Master of Puppets" then it won't show up. That's the undercounting problem and one that I can happily live with. Sorry it didn't count the one time you played it on YT from some guy's sketchy upload.

Now, maybe that truly is a dealbreaker, but you'll easily be able to stop pulling last.fm plays just by not entering in your Username.

That said I think you're pushing me towards having a separate blob in the index_data which would keep last.fm plays from getting intermixed with the foobar recorded plays. Not sure if that means having a checkbox to check when you want it to return last.fm plays in the list as well, or having just another field which will return those and allow the user to dedupe as needed.

  • MordredKLB
  • [*][*][*]
  • Developer
Re: foo_enhanced_playcount - Record every time a song plays (JScript/WSH)
Reply #7
v.1.0.2 release notes
 - File name change from foo_enhanced_playback_statistics to foo_enhanced_playcount
 - In preparation for retrieving last.fm playtimes, js playtimes now return timestamps rounded to the nearest second.

Note: If you have a version installed prior to v.1.0.2, you will have to manually delete it from your components folder! The filename has changed from foo_enhanced_playback_statistics to foo_enhanced_playcount. Foobar will fail to launch if both are installed at the same time. Please delete the entire foo_enhanced_playback_statistics folder.