tag:help.beatunes.com,2009-07-24:/discussions/plugin/2017-opening-a-single-playlist-with-groovybeaTunes: Discussion 2021-08-29T19:26:50Ztag:help.beatunes.com,2009-07-24:Comment/493615202021-08-28T10:51:16Z2021-08-28T10:51:16ZOpening a single playlist with Groovy<div><p>Hi,</p>
<p>I just realized you are trying to program a solution for <a href="http://help.beatunes.com/discussions/questions/15651-how-to-create-a-list-with-unique-artists">http://help.beatunes.com/discussions/questions/15651-how-to-create-...</a></p>
<p>Before I realized that, I remembered that I had a request recently and that I could use that request to illustrate a solution for what you're asking. I guess I have just solved both issues. :-)</p>
<p>Typically, you would want to extend a <code>com.tagtraum.beatunes.action.BaseAction</code> and then perform the desired task in the <code>actionPerformed(event)</code> method. This would be a perfectly valid approach. To create a new playlist, you'd do something like (Java code):</p>
<pre>
<code>protected PlayList createEmptyPlayList() {
final BeaTunes application = getApplication();
final MediaLibrary library = application.getMediaLibrary();
final boolean isITunesLibrary = library.getLibraryDescriptor() instanceof ITunesLibraryDescriptor
|| library.getLibraryDescriptor() instanceof ITLibraryDescriptor;
return library.createPlayList(application.getNewPlaylistParentId(), isITunesLibrary ? null : application.localize("untitled"));
}</code>
</pre>
<p>And then simply add tracks to the newly created playlist.</p>
<p>To get the tracks you want, you could use the method <code>getSelectedPlayList()</code>, call <code>getSongs()</code>, filter the iterable in the way you want it, and then call something like <code>newPlayList.addSongIds(newSongIds)</code>. Note that it's always preferable to work with ids rather than <code>AudioSong</code> objects.</p>
<p>That all said, there is a smarter way to do it.</p>
<p>Extend <code>com.tagtraum.beatunes.action.standard.NewPlayListAction</code> and implement <code>fillPlayList(newPlaylist, selectedSongIds)</code>. It will take care of a couple of UI hiccups and also playlist creation. How it is done is shown in (the newly created sample) at <a href="https://github.com/beatunes/beaTlet-samples/blob/master/groovy/UniqueArtistPlaylist.groovy">https://github.com/beatunes/beaTlet-samples/blob/master/groovy/Uniq...</a></p>
<p>Hope this helps,</p>
<p>-hendrik</p></div>hendriktag:help.beatunes.com,2009-07-24:Comment/493615202021-08-28T22:55:22Z2021-08-28T22:55:22ZOpening a single playlist with Groovy<div><p>Thank you so much!I have been trying to figure out a way to automate this off and on for at least 2 years but haven't ever gotten very far.You are a life saver Sent via the Samsung Galaxy S10, an AT&T 5G Evolution capable smartphone<br>
-------- Original message --------From: hendrik <a href="mailto:tender+d662cbf094@tenderapp.com">tender+d662cbf094@tenderapp.com</a> Date: 8/28/21 5:51 AM (GMT-06:00) To: <a href="mailto:patrick.gary@gmail.com">patrick.gary@gmail.com</a> Subject: Re: Opening a single playlist with Groovy [Plugin #2017]</p></div>patrick.gary