Skip to content

Commit

Permalink
[sonos] Added support of RadioApp music service
Browse files Browse the repository at this point in the history
Fix #13208

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo committed Aug 8, 2022
1 parent 581a04b commit 41e15b8
Showing 1 changed file with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici
private static final String STREAM_URI = "x-sonosapi-stream:";
private static final String RADIO_URI = "x-sonosapi-radio:";
private static final String RADIO_MP3_URI = "x-rincon-mp3radio:";
private static final String RADIOAPP_URI = "x-sonosapi-hls:radioapp_";
private static final String OPML_TUNE = "http://opml.radiotime.com/Tune.ashx";
private static final String FILE_URI = "x-file-cifs:";
private static final String SPDIF = ":spdif";
Expand Down Expand Up @@ -1300,6 +1301,38 @@ else if (isPlayingStream(currentURI) || isPlayingRadioStartedByAmazonEcho(curren
}
}

else if (isPlayingRadioApp(currentURI)) {
if (currentUriMetaData != null) {
title = currentUriMetaData.getTitle();
resultString = title;
if (currentTrack != null) {
String[] contents = currentTrack.getStreamContent().split("\\|");
String songTitle = null;
for (int i = 0; i < contents.length; i++) {
if (contents[i].startsWith("TITLE ")) {
songTitle = contents[i].substring(6).trim();
}
if (contents[i].startsWith("ARTIST ")) {
artist = contents[i].substring(7).trim();
}
if (contents[i].startsWith("ALBUM ")) {
album = contents[i].substring(6).trim();
}
}
if (artist != null && !artist.isEmpty()) {
resultString += " - " + artist;
}
if (album != null && !album.isEmpty()) {
resultString += " - " + album;
}
if (songTitle != null && !songTitle.isEmpty()) {
resultString += " - " + songTitle;
}
}
needsUpdating = true;
}
}

else if (isPlayingLineIn(currentURI)) {
if (currentTrack != null) {
title = currentTrack.getTitle();
Expand All @@ -1310,7 +1343,6 @@ else if (isPlayingLineIn(currentURI)) {

else if (isPlayingRadio(currentURI)
|| (!currentURI.contains("x-rincon-mp3") && !currentURI.contains("x-sonosapi"))) {
// isPlayingRadio(currentURI) is true for Google Play Music radio or Apple Music radio
if (currentTrack != null) {
artist = !currentTrack.getAlbumArtist().isEmpty() ? currentTrack.getAlbumArtist()
: currentTrack.getCreator();
Expand Down Expand Up @@ -1712,7 +1744,7 @@ protected void saveState() {

if (currentURI != null) {
if (isPlayingStream(currentURI) || isPlayingRadioStartedByAmazonEcho(currentURI)
|| isPlayingRadio(currentURI)) {
|| isPlayingRadio(currentURI) || isPlayingRadioApp(currentURI)) {
// we are streaming music, like tune-in radio or Google Play Music radio
SonosMetaData track = getTrackMetadata();
SonosMetaData current = getCurrentURIMetadata();
Expand Down Expand Up @@ -2654,7 +2686,7 @@ public void playNotificationSoundURI(Command notificationURL) {
coordinator.getCurrentURIMetadataAsString());

if (isPlayingStream(currentURI) || isPlayingRadioStartedByAmazonEcho(currentURI)
|| isPlayingRadio(currentURI)) {
|| isPlayingRadio(currentURI) || isPlayingRadioApp(currentURI)) {
handleNotifForRadioStream(currentURI, notificationURL, coordinator);
} else if (isPlayingLineIn(currentURI)) {
handleNotifForLineIn(currentURI, notificationURL, coordinator);
Expand Down Expand Up @@ -2692,9 +2724,15 @@ private boolean isPlayingStream(@Nullable String currentURI) {
}

private boolean isPlayingRadio(@Nullable String currentURI) {
// Google Play Music radio or Apple Music radio
return currentURI != null && currentURI.contains(RADIO_URI);
}

private boolean isPlayingRadioApp(@Nullable String currentURI) {
// RadioApp music service
return currentURI != null && currentURI.contains(RADIOAPP_URI);
}

private boolean isPlayingRadioStartedByAmazonEcho(@Nullable String currentURI) {
return currentURI != null && currentURI.contains(RADIO_MP3_URI) && currentURI.contains(OPML_TUNE);
}
Expand Down

0 comments on commit 41e15b8

Please sign in to comment.