actions.playlistRemoveDuplicatesByTitle = {
    title: function () {
        return _('Remove duplicates by title');
    },
    hotkeyAble: true,
    icon: 'remove',
    visible: function () {
        if (!window.uitools.getCanEdit())
            return false;
        else {
            var pl = resolveToValue(this.boundObject);
            return (pl.parent != undefined); // to exclude root playlists node
        }
    },
    execute: function () {
        var pl = resolveToValue(this.boundObject);
        var list = pl.getTracklist();
        var newList = app.utils.createTracklist();
        list.whenLoaded().then(async () => {
            var hasher = {};
            listForEach(list, (track, idx) => {
                if (!hasher[track.title])
                    newList.add(track); // not a duplicate
                hasher[track.title] = true;
            });
            var newplaylist = app.playlists.root.newPlaylist();
            newplaylist.name = pl.name + ' (filtered)';
            await newplaylist.commitAsync();
            newplaylist.addTracksAsync(newList);
        });
    }
};
