How to find if a child playlist exists with specific name

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

telecore
Posts: 57
Joined: Thu Jan 28, 2021 10:20 pm

How to find if a child playlist exists with specific name

Post by telecore »

Given a playlist, I want to programmatically see if a child playlist with the same name as the parent plus a '*' at the end exists and if it does, I want to get the playlist and clear its tracklist - if it does not exist then I want to create it - can anyone demonstrate how to do this?

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);
				});
			}
telecore
Posts: 57
Joined: Thu Jan 28, 2021 10:20 pm

Re: How to find if a child playlist exists with specific name

Post by telecore »

ALL - NEVERMIND - I got it working
Post Reply