2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.upnpcontrol.internal.queue;
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
19 import java.util.stream.Collectors;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.upnpcontrol.internal.util.StringUtils;
27 * @author Mark Herwege - Initial contribution
28 * @author Karel Goderis - Based on UPnP logic in Sonos binding
31 public class UpnpEntry {
33 private static final String DIRECTORY_ROOT = "0";
35 private static final Pattern CONTAINER_PATTERN = Pattern.compile("object.container");
39 private String parentId;
40 private String upnpClass;
41 private String title = "";
42 private List<UpnpEntryRes> resList = new ArrayList<>();
43 private String album = "";
44 private String albumArtUri = "";
45 private String creator = "";
46 private String artist = "";
47 private String publisher = "";
48 private String genre = "";
49 private @Nullable Integer originalTrackNumber;
51 private boolean isContainer;
57 public UpnpEntry(String id, String refId, String parentId, String upnpClass) {
60 this.parentId = parentId;
61 this.upnpClass = upnpClass;
63 Matcher matcher = CONTAINER_PATTERN.matcher(upnpClass);
64 isContainer = matcher.find();
67 public UpnpEntry withTitle(String title) {
72 public UpnpEntry withAlbum(String album) {
77 public UpnpEntry withAlbumArtUri(String albumArtUri) {
78 this.albumArtUri = albumArtUri;
82 public UpnpEntry withCreator(String creator) {
83 this.creator = creator;
87 public UpnpEntry withArtist(String artist) {
92 public UpnpEntry withPublisher(String publisher) {
93 this.publisher = publisher;
97 public UpnpEntry withGenre(String genre) {
102 public UpnpEntry withResList(List<UpnpEntryRes> resList) {
103 this.resList = resList;
107 public UpnpEntry withTrackNumber(@Nullable Integer originalTrackNumber) {
108 this.originalTrackNumber = originalTrackNumber;
113 * @return the title of the entry.
116 public String toString() {
121 * @return the unique identifier of this entry.
123 public String getId() {
128 * @return the title of the entry.
130 public String getTitle() {
135 * @return the identifier of the entry this reference intry refers to.
137 public String getRefId() {
142 * @return the unique identifier of the parent of this entry.
144 public String getParentId() {
145 return parentId.isEmpty() ? DIRECTORY_ROOT : parentId;
149 * @return a URI for this entry. Thumbnail resources are not considered.
151 public String getRes() {
152 return resList.stream().filter(res -> !res.isThumbnailRes()).map(UpnpEntryRes::getRes).findAny().orElse("");
155 public List<String> getProtocolList() {
156 return resList.stream().map(UpnpEntryRes::getProtocolInfo).collect(Collectors.toList());
160 * @return the UPnP classname for this entry.
162 public String getUpnpClass() {
166 public boolean isContainer() {
171 * @return the name of the album.
173 public String getAlbum() {
178 * @return the URI for the album art.
180 public String getAlbumArtUri() {
181 return StringUtils.unEscapeXml(albumArtUri);
185 * @return the name of the artist who created the entry.
187 public String getCreator() {
191 public String getArtist() {
195 public String getPublisher() {
199 public String getGenre() {
203 public @Nullable Integer getOriginalTrackNumber() {
204 return originalTrackNumber;