Skip to content

Commit

Permalink
Merge pull request openhab#140 from kgoderis/sonos
Browse files Browse the repository at this point in the history
Further improvement of Metadata methods
  • Loading branch information
kaikreuzer committed Feb 20, 2015
2 parents ddaf474 + e5fc3eb commit 232b275
Showing 1 changed file with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public void onValueReceived(String variable, String value, String service) {
break;
}
case "CurrentURI": {
updateCurrentURIFormatted();
updateCurrentURIFormatted(value);
break;
}
}
Expand Down Expand Up @@ -596,8 +596,15 @@ public boolean isCoordinator() {

protected void updateTrackMetaData() {

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

if (coordinatorHandler != null && coordinatorHandler != this) {
coordinatorHandler.updateMediaInfo();
currentTrack = coordinatorHandler.getTrackMetadata();
}

if (currentTrack != null) {

String artist = null;
Expand All @@ -623,38 +630,36 @@ protected void updateTrackMetaData() {
this.onValueReceived("CurrentAlbum", (album != null) ? album : "",
"AVTransport");

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

}

}

protected void updateCurrentURIFormatted() {
protected void updateCurrentURIFormatted(String URI) {

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

if (coordinatorHandler != null && coordinatorHandler != this) {
if(getCurrentURI().contains("x-rincon")) {
if(currentURI.contains("x-rincon-stream")) {
coordinatorHandler.updateMediaInfo();
}
currentURI = coordinatorHandler.getCurrentURI();
currentTrack = coordinatorHandler.getTrackMetadata();
} else {
currentURI = getCurrentURI();
// currentURI = getCurrentURI();
currentTrack = getTrackMetadata();
}

if (currentURI != null) {
String title = stateMap.get("CurrentTitle");
String resultString = stateMap.get("CurrentURIFormatted");
boolean needsUpdating = false;

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

String stationID = StringUtils.substringBetween(currentURI,
":s", "?sid");
String previousStationID = stateMap.get("StationID");
Expand Down Expand Up @@ -706,9 +711,18 @@ protected void updateCurrentURIFormatted() {
}
}
}
} else {
}

if(currentURI.contains("x-rincon-stream")) {
if(currentTrack != null) {
resultString = stateMap.get("CurrentTitle");
needsUpdating = true;
}
}

if (currentTrack != null && !currentTrack.getTitle().contains("x-sonosapi-stream")) {

if (!currentURI.contains("x-rincon-mp3") && !currentURI.contains("x-rincon-stream") && !currentURI.contains("x-sonosapi")) {
if(currentTrack != null) {
if (currentTrack.getAlbumArtist().equals("")) {
resultString = currentTrack.getCreator() + " - "
+ currentTrack.getAlbum() + " - "
Expand All @@ -723,6 +737,7 @@ protected void updateCurrentURIFormatted() {
}
}


if(needsUpdating) {
this.onValueReceived("CurrentURIFormatted", (resultString != null) ? resultString : "",
"AVTransport");
Expand Down Expand Up @@ -1776,7 +1791,7 @@ public String getCurrentZoneName() {
}

public String getCurrentURIFormatted() {
updateCurrentURIFormatted();
updateCurrentURIFormatted(getCurrentURI());
return stateMap.get("CurrentURIFormatted");
}

Expand Down

0 comments on commit 232b275

Please sign in to comment.