Modification of Copy and Swap Fields 1.0.1

Get help for different MediaMonkey 5 Addons.

Moderators: jiri, drakinite, Addon Administrators

jcorrell
Posts: 8
Joined: Thu Aug 30, 2018 5:32 pm

Modification of Copy and Swap Fields 1.0.1

Post by jcorrell »

Firstly, thanks to Drakinite for Copy and Swap Fields.

Back in the MM4 days, I would copy a track's Added date to Custom1 so that if I ever had to reload the library, I could copy Custom1 -> Added and my smart playlists would still work correctly. In MM5 I'd like to do the copy back so I thought I'd just modify drakinite's script for my own usage. I added dateAdded to the supported fields but it wasn't that simple :) I can't get the dateAdded to copy to a custom field or replace it's value with a custom field.

It seems obvious that the dateAdded is treated differently than the other fields. So can someone direct me to some documentation on how and why it's different? I'd like to modify the software as a learning experience.

Thanks.
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Modification of Copy and Swap Fields 1.0.1

Post by drakinite »

jcorrell wrote: Tue May 17, 2022 5:02 pm Firstly, thanks to Drakinite for Copy and Swap Fields.
No problem :slight_smile:

jcorrell wrote: Tue May 17, 2022 5:02 pm Back in the MM4 days, I would copy a track's Added date to Custom1 so that if I ever had to reload the library, I could copy Custom1 -> Added and my smart playlists would still work correctly. In MM5 I'd like to do the copy back so I thought I'd just modify drakinite's script for my own usage. I added dateAdded to the supported fields but it wasn't that simple :) I can't get the dateAdded to copy to a custom field or replace it's value with a custom field.

It seems obvious that the dateAdded is treated differently than the other fields. So can someone direct me to some documentation on how and why it's different? I'd like to modify the software as a learning experience.
dateAdded is get/set via a native JS Date object: https://developer.mozilla.org/en-US/doc ... jects/Date
In MM4 there might have been an automatic conversion to and from the Date type (in https://www.mediamonkey.com/wiki/SDBSongData), not sure.

In MM5, you'll need to do the conversion from Date <-> string yourself, but it's much easier than you might think. There are many ways of doing it, here's one example using toISOString():

Code: Select all

var dateAdded = itm.dateAdded;
var dateString = dateAdded.toISOString(); // example: 2019-08-11T23:40:24.000Z
itm.custom1 = dateString;
// then, in reverse
var dateString = itm.custom1;
var dateAdded = new Date(dateString);
if (!isNaN(dateAdded.valueOf()) itm.dateAdded = dateAdded;
(Make sure to check if the date you parsed is valid before you set it to the tag!)
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Post Reply