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.mpd.internal.protocol;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Class for representing a song.
24 * @author Stefan Röllin - Initial contribution
27 public class MPDSong {
29 private final Logger logger = LoggerFactory.getLogger(MPDSong.class);
31 private final String filename;
32 private final String album;
33 private final String artist;
34 private final String name;
35 private final int song;
36 private final int songId;
37 private final String title;
38 private final int track;
40 public MPDSong(MPDResponse response) {
41 Map<String, String> values = MPDResponseParser.responseToMap(response);
42 filename = values.getOrDefault("file", "");
43 album = values.getOrDefault("Album", "");
44 artist = values.getOrDefault("Artist", "");
45 name = values.getOrDefault("Name", "");
46 song = parseInteger(values.getOrDefault("Pos", "0"), 0);
47 songId = parseInteger(values.getOrDefault("Id", "0"), 0);
48 title = values.getOrDefault("Title", "");
49 track = parseInteger(values.getOrDefault("Track", "-1"), -1);
52 public String getFilename() {
56 public String getAlbum() {
60 public String getArtist() {
64 public String getName() {
68 public int getSong() {
72 public int getSongId() {
76 public String getTitle() {
80 public int getTrack() {
84 private int parseInteger(String value, int aDefault) {
86 return Integer.parseInt(value);
87 } catch (NumberFormatException e) {
88 logger.debug("parseInt of {} failed", value);