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-27T17:01:52Z2021-08-27T17:01:54ZOpening a single playlist with Groovy<div><p>I've been trying to programmatically create a new playlist with another larger playlist as my source.<br>
I'm having trouble opening up a single playlist instead of working with all songs in the library. I've reviewed the code samples in the beaTunes Plugins documentation and GitHub archive, and nothing seems to show how to either open and/or access a given playlist or to write a new playlist to anything other than a file.</p>
<p>Do you have any code samples I could look at? I'd prefer Groovy, but can probably figure it out from anything you have laying around.</p></div>patrick.garytag: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