[SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: [SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

Re: [SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by Andre_H » Sun Nov 13, 2022 11:27 am

sonos wrote: ↑Sun Nov 13, 2022 9:40 am Did you write an addon for this task?
Basically Ludek and drakinite wrote it, I just put it together, but yes. :-)
Send me a PM with an email address; I can send you this as a ZIP.

Re: [SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by sonos » Sun Nov 13, 2022 9:40 am

Hi Andre,
Thanks for your quick reply. I use the Addon SQL Editor to display some values.
For example, list all total runtimes of audiobooks, because sometimes I am looking for audiobooks that do not exceed a certain total runtime (e.g. because of traveling etc.)

Code: Select all

SELECT
  Songs.IDAlbum, TrackType, 
  Author, Songs.Album ,
  time(SUM(SongLength) / 1000, 'unixepoch' )  AS total_time
FROM
   Songs
INNER JOIN Albums ON albums.ID = Songs.IDAlbum  AND TrackType = 2
GROUP BY
 Songs.IDAlbum
ORDER BY total_time DESC;
or list all date/time stamps from the Played table of certain songs.

Code: Select all

SELECT Strftime('%Y/%m/%d %H:%M:%S', ( Julianday(playdate) + 2415018.5 ),
       'localtime') AS plays
FROM   played AS p
       JOIN songs AS s
         ON s.id = p.idsong
WHERE  album = 'A Tribute To Jack Johnson'
       AND songtitle = 'Yesternow';
Although the SQL editor is very handy, I would like to add some of the SQL queries to the CustomNodes.
But I am beginner in java script and just tried to paste the query into the sql album part in customNodesDefinitions.js. However it doesn't work unfortunately.

Where do you write the data: Playcounter, LastPlayed, SkipCounter, LastSkipped? Did you write an addon for this task?

Carsten

Re: [SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by Andre_H » Sun Nov 13, 2022 4:50 am

sonos wrote: ↑Sat Nov 12, 2022 10:38 am What is the idea of:
[REQ] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag ?
Hi Carsten,

They are in the database, and that's the point: only there. Call it "my personal paranoia" or "lessons learned from iTunes". I used iTunes over years before switching to MMW. whenever i renamed, moved or even replaced (higher bitrate or forewhat reason ever) a file, iTunes resetted all track statistics for this track, the track was classified as "new added". i lost a lot of statistics that way.

My playlists, on the other hand, are mostly dynamic and are heavily based on this values.

So i just wanted these data saved to the track itself, in case of "whatever happens", i can recover them. i even export a full csv list of all the fields from [songs] to csv on daily base.

To be honest: I barely had any use of it so far, since MMW doesn't reset anything within the file actions from above, but ... you know ... "besser haben als brauchen" ... ;-)

Re: [SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by sonos » Sat Nov 12, 2022 10:38 am

I am not sure if I have understood it correctly here. I assumed that the values Playcounter, LastPlayed (PlayDate) are stored in the DB table Played.
What is the idea of:
[REQ] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag ?

Carsten

Re: [SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by Andre_H » Tue Jun 15, 2021 9:33 am

Can confirm that the thread does not need to be set to [REQ] again! :wink:
Tested on .2416, works fine.

Re: [SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by Peke » Mon Jun 14, 2021 7:10 pm

Hi,
Changed back to [SOLVED] so that you can test it and hopefully not change back to [REQ] ;)

Re: [REQ] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by Andre_H » Mon Jun 14, 2021 1:38 pm

Will check, when out, and give feedback then.

Thanks again!

Re: [REQ] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by Ludek » Mon Jun 14, 2021 11:27 am

...But if I only listen to tracks in MMA and sync back, MMW correctly updates the data for the playcounter and lastplayed, but the script does not seem to trigger: neither playcount to custom6 or lastplayed to custom7 were updated.
OK, seeing the reason in MM5 code, will be fixed in 2416+

Thanks!

Re: [SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by Andre_H » Thu Jun 10, 2021 10:39 am

Hi guys,

I got the following phenomenon: when I syncronize tracks from MMA where the rating has been changed (thats basicly what i've done all the time while testing; not sure what happens if i change other stuff in MMA), my (your ;-)) script works fine. But if I only listen to tracks in MMA and sync back, MMW correctly updates the data for the playcounter and lastplayed, but the script does not seem to trigger: neither playcount to custom6 or lastplayed to custom7 were updated.

I checked the conditions for triggering again, but did not see the error // the difference between "listen & change rating & sync back" and "just listen & sync back":

Code: Select all

requirejs('actions');
// Execute when the window is ready
window.whenReady(() => {
	app.listen(app, 'trackmodified', function (track) {
		
		var modified = false;
		
		//convert rating from 20-100 to 1-5 value as "varrating", save "varrating" to customfield, if changed ...
		let varrating = track.rating/20;
		if(track.custom5 != varrating.toString()) {
		  track.custom5 = varrating.toString();
		  modified = true;
		};

		//save playcounter & last played, if playcounter>0 and changed ...
		if(track.playCounter > 0 && track.custom6 != track.playCounter.toString()) {
        	   track.custom6 = track.playCounter.toString();
		   track.custom7 = app.utils.dateTime2Timestamp(track.lastTimePlayed);
		   modified = true;
		};
		
		if (modified)
		  track.commitAsync();                    
	});
});
would you help thinking again please? ;-)

Edit: "Just listening" from MMW5 works fine, script runs.
Edit2: changed Topic from [SOLVED] to [REQ]

Re: [SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by Andre_H » Wed Jun 09, 2021 9:14 am

Ludek wrote: ↑Tue Jun 08, 2021 7:55 am Just remove the _UTC and use:

Code: Select all

app.utils.dateTime2Timestamp(itm.lastTimePlayed) 

that's all ;-)
Update:

File info.json:

Code: Select all

{
    "title": "saveStatisticsToTag",
    "id": "saveStatistics",
    "description": "save statistics to IDTag-CustomFields",
    "version": "1.0.0",
    "author": "programmed by 'ludek' and 'drakinite' (MediaMonkey), cobbled together by Andre_H :-)",
    "type": "general",
    "icon": "saveStatistics.svg"
}
File init.js - for automatic saving on "change"-event (after playing, editing data or syncing back from MMA):

Code: Select all

//* save track-statistics to CustomFields.*//
// Custom1=DateAdded
// Custom2=Source
// Custom3=Media
// Custom4=CoverCheck
// Custom5=Rating
// Custom6=Playcount
// Custom7=LastPlayed


requirejs('actions');
// Execute when the window is ready
window.whenReady(() => {
	app.listen(app, 'trackmodified', function (track) {
		
		var modified = false;
		
		//convert rating from 20-100 to 1-5 value as "varrating", save "varrating" to customfield, if changed ...
		let varrating = track.rating/20;
		if(track.custom5 != varrating.toString()) {
		  track.custom5 = varrating.toString();
		  modified = true;
		};

		//save playcounter & last played, if playcounter>0 and changed ...
		if(track.playCounter > 0 && track.custom6 != track.playCounter.toString()) {
        	   track.custom6 = track.playCounter.toString();
		   track.custom7 = app.utils.dateTime2Timestamp(track.lastTimePlayed));
		   modified = true;
		};
		
		if (modified)
		  track.commitAsync();                    
	});
});
File actions_add.js - same functionality "on demand", per right-click menu under "edit tags"

Code: Select all

//* save track-statistics to CustomFields.*//
// Custom1=DateAdded
// Custom2=Source
// Custom3=Media
// Custom4=CoverCheck
// Custom5=Rating
// Custom6=Playcount
// Custom7=LastPlayed


actions.saveStatistics = {
    title: _('Speichere Statistik-Daten in CustomFields ...'),
    hotkeyAble: false,
    //icon: 'saveStatistics',
    disabled: uitools.notMediaListSelected,
    visible: window.uitools.getCanEdit,
    execute: async function () {
        var list = await uitools.getSelectedTracklist().whenLoaded();
        if (list.count === 0) {
            return;
        }
        list.forEach(function(itm) {

            	var modified = false;

		//convert rating from 20-100 to 1-5 value as "varrating", save "varrating" to customfield, if changed ...
		let varrating = itm.rating/20;
		if(itm.custom5 != varrating.toString()) {
		  itm.custom5 = varrating.toString();
		  modified = true;
		};	
		
		//save playcounter, if changed ...
		if(itm.custom6 != itm.playCounter.toString()) {
                  itm.custom6 = itm.playCounter.toString();
		  modified = true;
		};

		//save lastplayed, if playcounter>0 and changed ...
		if(itm.playCounter > 0 && itm.custom7 != app.utils.dateTime2Timestamp(itm.lastTimePlayed)) {
                  itm.custom7 = app.utils.dateTime2Timestamp(itm.lastTimePlayed);
		  modified = true;
		};

           if (modified)
		itm.commitAsync(); 

        });       
    }
}

window._menuItems.editTags.action.submenu.push({
        action: actions.saveStatistics,
        order: 90,
        grouporder: 10
});
icon commented out, as that file has to be in the right place.

Re: [REQ] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by Ludek » Tue Jun 08, 2021 7:55 am

Andre_H wrote: ↑Thu May 27, 2021 4:13 pm 2 (maybe :wink: ) final questions:

Code: Select all

app.utils.dateTime2Timestamp(itm.lastTimePlayed_UTC
is 2 hours behind my local time. any quick fix for that? if not, not a big thing.
Just remove the _UTC and use:

Code: Select all

app.utils.dateTime2Timestamp(itm.lastTimePlayed) 

that's all ;-)

Re: [SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by drakinite » Tue Jun 08, 2021 3:26 am

Very nice, great job! You can also feel free to upload it to the Addons site: https://www.mediamonkey.com/addon_system/admin/

I should probably write a snippet on the wiki explaining how to submit, since I recall it being confusing when I first did it.

1) Click on the category you'd like it to be in (in this case, I'd put it in Behavior Tweaks)
2) click Submit New Addon
3) Fill out the necessary information; Support/donate/buy/author links are optional, as well as license type and a thumbnail image. If you upload an image, I'd recommend making it square. Then click save. This step is for meta information about the addon itself.
4) Next, you'll be taken to the "Add Version" page, where you upload the addon itself. You have the choice of uploading a file or providing an external link, and you must enter which MediaMonkey versions it's compatible with. (In this case, I'd put 5.0.0 to 5.0.1.) Then click save.
5) Now, you'll be taken to a review screen; if everything looks good, click Finish.

I should then get a notification (if that part is working) that an addon has been submitted, and I'll review and approve it.

Re: [SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by Andre_H » Tue Jun 08, 2021 2:32 am

Since the two scripts are very individually tailored to my use of the custom tags, i guess hardly anyone will use them directly. I was thinking of posting the final code in full rather than a sample for similar ideas. So, here we go:

File info.json:

Code: Select all

{
    "title": "saveStatisticsToTag",
    "id": "saveStatistics",
    "description": "save statistics to IDTag-CustomFields",
    "version": "1.0.0",
    "author": "programmed by 'ludek' and 'drakinite' (MediaMonkey), cobbled together by Andre_H :-)",
    "type": "general",
    "icon": "saveStatistics.svg"
}
File init.js - for automatic saving on "change"-event (after playing, editing data or syncing back from MMA):

Code: Select all

//* save track-statistics to CustomFields.*//
// Custom1=DateAdded
// Custom2=Source
// Custom3=Media
// Custom4=CoverCheck
// Custom5=Rating
// Custom6=Playcount
// Custom7=LastPlayed


requirejs('actions');
// Execute when the window is ready
window.whenReady(() => {
	app.listen(app, 'trackmodified', function (track) {
		
		var modified = false;
		
		//convert rating from 20-100 to 1-5 value as "varrating", save "varrating" to customfield, if changed ...
		let varrating = track.rating/20;
		if(track.custom5 != varrating.toString()) {
		  track.custom5 = varrating.toString();
		  modified = true;
		};

		//save playcounter & last played, if playcounter>0 and changed ...
		if(track.playCounter > 0 && track.custom6 != track.playCounter.toString()) {
        	   track.custom6 = track.playCounter.toString();
		   track.custom7 = app.utils.dateTime2Timestamp(UTCtoLocal(track.lastTimePlayed_UTC));
		   modified = true;
		};
		
		if (modified)
		  track.commitAsync();                    
	});
});


function UTCtoLocal(date) {
    var now = new Date();
    var offset = now.getTimezoneOffset(); // offset from UTC in minutes
    return new Date(date.valueOf() - offset * 60000);
}
File actions_add.js - same functionality "on demand", per right-click menu under "edit tags"

Code: Select all

//* save track-statistics to CustomFields.*//
// Custom1=DateAdded
// Custom2=Source
// Custom3=Media
// Custom4=CoverCheck
// Custom5=Rating
// Custom6=Playcount
// Custom7=LastPlayed


actions.saveStatistics = {
    title: _('Speichere Statistik-Daten in CustomFields ...'),
    hotkeyAble: false,
    //icon: 'saveStatistics',
    disabled: uitools.notMediaListSelected,
    visible: window.uitools.getCanEdit,
    execute: async function () {
        var list = await uitools.getSelectedTracklist().whenLoaded();
        if (list.count === 0) {
            return;
        }
        list.forEach(function(itm) {

            	var modified = false;

		//convert rating from 20-100 to 1-5 value as "varrating", save "varrating" to customfield, if changed ...
		let varrating = itm.rating/20;
		if(itm.custom5 != varrating.toString()) {
		  itm.custom5 = varrating.toString();
		  modified = true;
		};	
		
		//save playcounter, if changed ...
		if(itm.custom6 != itm.playCounter.toString()) {
                  itm.custom6 = itm.playCounter.toString();
		  modified = true;
		};

		//save lastplayed, if playcounter>0 and changed ...
		if(itm.playCounter > 0 && itm.custom7 != app.utils.dateTime2Timestamp(UTCtoLocal(itm.lastTimePlayed_UTC))) {
                  itm.custom7 = app.utils.dateTime2Timestamp(UTCtoLocal(itm.lastTimePlayed_UTC));
		  modified = true;
		};

           if (modified)
		itm.commitAsync(); 

        });       
    }
}


function UTCtoLocal(date) {
    var now = new Date();
    var offset = now.getTimezoneOffset(); // offset from UTC in minutes
    return new Date(date.valueOf() - offset * 60000);
}

window._menuItems.editTags.action.submenu.push({
        action: actions.saveStatistics,
        order: 90,
        grouporder: 10
});
icon commented out, as that file has to be in the right place.

Of course I create the MMIP if someone wants it. PM!

Re: [SOLVED] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by Peke » Mon Jun 07, 2021 9:58 pm

Andre_H wrote: ↑Mon Jun 07, 2021 2:26 pm If anyone is interested in the final scripts, leave a note, i gladly share them.
Sure that someone will be interested prepare MMIP files and in case of issues @drakinite should be able to help you.

Re: [REQ] Addon to save Playcounter, LastPlayed, SkipCounter, LastSkipped to tag

by Andre_H » Mon Jun 07, 2021 2:26 pm

Hi guys,

I was on vacation for a couple of days and couldn't work on this anymore. Final report: Everything is now working as intended: I can save my stuff on demand, and it is automaticly saved on every change, including syncing back from MMA.

Many thanks to drakinite and Ludek for the great support, in the end I just muddled together what you programmed. You guys rock! ;-)

If anyone is interested in the final scripts, leave a note, i gladly share them.

Topic is set to [Solved].

Top