* @param filters list of elements to be returned
* @return
*/
private MusicTrack getUpnpMusicTrackFromSmdTrackEntity(ResultItem<TrackEntity> trackResultItem, String parentId, List<String> filters) {
MusicTrack upnpTrack = new MusicTrack();
TrackEntity trackItem = trackResultItem.getItem();
// Mandatory elements:
upnpTrack.setId(parentId+"/"+trackResultItem.getId());
upnpTrack.setRefID(trackResultItem.getId());
upnpTrack.setTitle(trackResultItem.getName());
if(wantedProperty("dc:creator", filters)) {
try {
upnpTrack.setCreator(trackItem.getRecording().getContributors().iterator().next().getArtist().getName());
}catch (Exception NoSuchElementException) {
upnpTrack.setCreator("unknown");
}
}
if(wantedProperty("upnp:album", filters)) {
upnpTrack.setAlbum(trackItem.getRelease().getName());
}
if(wantedProperty("upnp:originalTrackNumber", filters)) {
upnpTrack.setOriginalTrackNumber(trackItem.getNumber());
}
if(wantedProperty("dc:date", filters)) {
// TODO: verify date nullity
// upnpTrack.setDate(trackItem.getRelease().getDate().toString());
}
if(wantedProperty("upnp:artists", filters)) {
//upnpTrack.setArtists()
List<PersonWithRole> contributors = new ArrayList<PersonWithRole>();
for(Contributor contributor: trackItem.getRecording().getContributors()) {
contributors.add(new PersonWithRole(contributor.getArtist().getName(),
contributor.getType()));
}
upnpTrack.setArtists(contributors.toArray(new PersonWithRole[0]));
}
if(wantedProperty("res", filters)) {
Res upnpResource = new Res();
upnpResource.setProtocolInfo(new ProtocolInfo("*:*:*:*"));
if(trackResultItem.getItem().getPlayableElements().size() != 1 ) {
// TODO: handle track items with multiple playable elements
System.err.println("Track "+trackResultItem.getName()+" ("+trackResultItem.getId()+") has "+
trackItem.getPlayableElements().size()+
" playable elements item, no support yet for ");
}
upnpResource.setValue(trackItem.getPlayableElements().iterator().next().getUri());
upnpTrack.addResource(upnpResource);
}
return upnpTrack;
// unnecessary, initialized by constructor
// upnpTrack.setClazz(new org.teleal.cling.support.model.DIDLObject.Class("object.item.audioItem.musicTrack"));