I have some code here that doesn't seem to work: (pl is the playlist, newList is the new tracklist to add/replace)
Code: Select all
//-------------------------------------------------------------------------
// see if playlist already exists
var plname = pl.name + '*';
var plpromise = app.playlists.getByTitleAsync(plname);
var plexist=false;
plpromise.then((pl2) => {
if (pl2)
{
plexist=true;
pl2.commitAsync().then(function() {
pl2.clearTracksAsync();
pl2.addTracksAsync(newList);
});
}
});
if (!plexist)
{
//-------------------------------------------------------------------------
var newplaylist = app.playlists.root.newPlaylist();
newplaylist.parent = pl;
newplaylist.name = pl.name + '*';
//-------------------------------------------------------------------------
newplaylist.commitAsync().then(function () {
newplaylist.addTracksAsync(newList);
});
}