Skip to content

Commit

Permalink
Improve track meta data handling
Browse files Browse the repository at this point in the history
Signed-off-by: Karel Goderis <[email protected]>
  • Loading branch information
kgoderis committed Feb 16, 2015
1 parent a866116 commit 9f107a3
Showing 1 changed file with 67 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public class ZonePlayerHandler extends BaseThingHandler implements
@Override
public void run() {
try {
updateCurrentURIFormatted();
updateZoneInfo();
updateRunningAlarmProperties();
updateLed();
Expand Down Expand Up @@ -452,6 +451,14 @@ public void onValueReceived(String variable, String value, String service) {
stateMap.get("CurrentAlbum")) : UnDefType.UNDEF);
break;
}
case "CurrentTrackMetaData": {
updateTrackMetaData();
break;
}
case "CurrentURI": {
updateCurrentURIFormatted();
break;
}
}

}
Expand Down Expand Up @@ -587,14 +594,51 @@ public boolean isCoordinator() {
return getUDN().equals(getCoordinator());
}

protected void updateTrackMetaData() {

SonosMetaData currentTrack = getTrackMetadata();

if (currentTrack != null) {

String artist = "";
if (currentTrack.getAlbumArtist().equals("")) {
artist = currentTrack.getCreator();
} else {
artist = currentTrack.getAlbumArtist();
}

String album = currentTrack.getAlbum();
String title = "";
if(!currentTrack.getTitle().contains("x-sonosapi-stream")) {
title = currentTrack.getTitle();
}

// update individual variables
this.onValueReceived("CurrentArtist", (artist != null) ? artist
: "", "AVTransport");
this.onValueReceived("CurrentTitle", (title != null) ? title : "",
"AVTransport");
this.onValueReceived("CurrentAlbum", (album != null) ? album : "",
"AVTransport");

if(currentTrack.getTitle().contains("x-sonosapi-stream")) {
updateMediaInfo();
}
}

}

protected void updateCurrentURIFormatted() {

String currentURI = null;
SonosMetaData currentTrack = null;
String coordinator = getCoordinator();
ZonePlayerHandler coordinatorHandler = getHandlerByName(coordinator);

if (!isGroupCoordinator() && coordinatorHandler != null) {
if (coordinatorHandler != null) {
if(getCurrentURI().contains("x-rincon")) {
coordinatorHandler.updateMediaInfo();
}
currentURI = coordinatorHandler.getCurrentURI();
currentTrack = coordinatorHandler.getTrackMetadata();
} else {
Expand All @@ -603,11 +647,9 @@ protected void updateCurrentURIFormatted() {
}

if (currentURI != null) {

String resultString = null;
String artist = null;
String album = null;
String title = null;
String title = stateMap.get("CurrentTitle");
String resultString = stateMap.get("CurrentURIFormatted");
boolean needsUpdating = false;

if (opmlPartnerID != null && currentURI.contains("x-sonosapi-stream")) {

Expand Down Expand Up @@ -657,47 +699,34 @@ protected void updateCurrentURIFormatted() {
resultString = resultString + " - ";
}
}

needsUpdating = true;
}
}
} else {
resultString = stateMap.get("CurrentURIFormatted");
title = stateMap.get("CurrentTitle");
}

} else {
if (currentTrack != null) {
if (!currentTrack.getTitle().contains("x-sonosapi-stream")) {
if (currentTrack.getAlbumArtist().equals("")) {
resultString = currentTrack.getCreator() + " - "
+ currentTrack.getAlbum() + " - "
+ currentTrack.getTitle();
artist = currentTrack.getCreator();
} else {
resultString = currentTrack.getAlbumArtist()
+ " - " + currentTrack.getAlbum() + " - "
+ currentTrack.getTitle();
artist = currentTrack.getAlbumArtist();
}

album = currentTrack.getAlbum();
title = currentTrack.getTitle();
if (currentTrack != null && !currentTrack.getTitle().contains("x-sonosapi-stream")) {
if (currentTrack.getAlbumArtist().equals("")) {
resultString = currentTrack.getCreator() + " - "
+ currentTrack.getAlbum() + " - "
+ currentTrack.getTitle();
} else {
resultString = currentTrack.getAlbumArtist()
+ " - " + currentTrack.getAlbum() + " - "
+ currentTrack.getTitle();
}

} else {
resultString = "";
needsUpdating = true;
}
}

this.onValueReceived("CurrentURIFormatted", resultString,
"AVTransport");

// update individual variables
this.onValueReceived("CurrentArtist", (artist != null) ? artist
: " ", "AVTransport");
this.onValueReceived("CurrentTitle", (title != null) ? title : " ",
"AVTransport");
this.onValueReceived("CurrentAlbum", (album != null) ? album : " ",
"AVTransport");
if(needsUpdating) {
this.onValueReceived("CurrentURIFormatted", (resultString != null) ? resultString : "",
"AVTransport");
this.onValueReceived("CurrentTitle", (title != null) ? title : "",
"AVTransport");
}
}
}

Expand All @@ -716,7 +745,6 @@ public String getUDN() {
}

public String getCurrentURI() {
updateMediaInfo();
return stateMap.get("CurrentURI");
}

Expand Down

0 comments on commit 9f107a3

Please sign in to comment.