View Issue Details

IDProjectCategoryView StatusLast Update
0018202MMW 5Extensions (bundled)public2022-09-14 14:39
Reporterdrakinite Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Product Version5.0.1 
Target Version5.2 
Summary0018202: Addon to warn user when deleting Library tracks included in a playlist
Description(Ticket 0002392) A user has requested an addon that will warn the user when deleting a library track that exists in a playlist.

Original request:
Just wondering if its possible to write a script to warn you if you are trying to delete a library track that is included in one of your playlists, if so which one.

Its like deleting a duplicate, am I deleteing the one that is in a playlist???

-
The warning dialog should include a list of the playlists that the song is in. (Might want to include an option to ignore the automatic playlists such as Accessible Tracks.)
TagsNo tags attached.
Fixed in build

Activities

drakinite

2021-08-16 21:22

developer   ~0064383

Notes on how it can be done (as I misinterpreted the user's request initially):

The first thing you'll want to do is override the "remove" action (actions.remove.execute), and run your own code to check the tracks before running the delete action.

The "remove" action uses a local function inside actions.js, named deleteSelected, but it is small so it is not difficult to override. I would put the code before if (lastControl.controlClass.deleteSelected && lastControl.controlClass.canDeleteSelected()) {, because you have little control over overriding the way all of those controls handle item deletions. First you can take the selected tracklist with:

var list = uitools.getSelectedTracklist();

Then you can use the getPlaylistsForTrackAsync() method in the Playlists class here: https://www.mediamonkey.com/docs/api/classes/Playlists.html#method_getPlaylistsForTrackAsync

That method is not available in app.playlists. What you can do is:

var playlists = app.get_playlists();

Here's an example of what you can do:

 

var playlists = app.get_playlists();

var list = uitools.getSelectedTracklist();

list.whenLoaded()

.then(function () {

list.forEach(function(track) {

  var playlistMatches = playlists.getPlaylistsForTrackAsync(track);

  playlistMatches.whenLoaded()

  .then(function () {

    // do whatever you like with the list of matching playlists

  });

});

});

 

You may want to be careful to exclude auto-playlists like Accessible Tracks, Recently Added, etc., as if you have the Accessible Tracks playlist enabled for example, all songs will show up in that one.