Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #394 from 19379/listenbrainz-fixes
Browse files Browse the repository at this point in the history
Listenbrainz fixes
  • Loading branch information
Debugs committed Sep 16, 2017
2 parents c8cf316 + 8fb70a3 commit c78ceb2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
7 changes: 3 additions & 4 deletions app/src/main/java/com/adam/aslfms/service/NPNotifier.java
Expand Up @@ -210,8 +210,7 @@ public void notifyNowPlaying(Track track, HandshakeResult hInfo)
JSONObject baseObj = new JSONObject();
baseObj.put("listen_type", "playing_now");
JSONObject trackInfo = new JSONObject();
trackInfo.put("listened_at", Long.toString(track.getWhen()));


JSONObject trackMetaData = new JSONObject();
trackMetaData.put("artist_name", track.getArtist());
trackMetaData.put("track_name", track.getTrack());
Expand Down Expand Up @@ -262,12 +261,12 @@ public void notifyNowPlaying(Track track, HandshakeResult hInfo)
Log.d(TAG, response);
if (resCode == 401) {
settings.setListenBrainzToken(netApp, "");
throw new BadSessionException("Now Playing failed because of badsession");
throw new BadSessionException("Now Playing failed because of bad token.");
}
if (response.equals("")) {
throw new AuthStatus.UnknownResponseException("Empty response");
}
if (response.startsWith("success")) {
if (resCode == 200 && response.indexOf("ok") > -1) {
Log.i(TAG, "Now Playing success: " + netAppName);
} else {
throw new AuthStatus.UnknownResponseException("Invalid Response");
Expand Down
17 changes: 11 additions & 6 deletions app/src/main/java/com/adam/aslfms/service/Scrobbler.java
Expand Up @@ -304,16 +304,21 @@ public void scrobbleCommit(HandshakeResult hInfo, Track[] tracks)
Log.d(TAG, response);
if (resCode == 401) {
settings.setListenBrainzToken(netApp, "");
throw new BadSessionException("Now Playing failed because of badsession");
throw new BadSessionException("Listenbrainz submission failed because of bad token.");
}
if (response.equals("")) {
throw new AuthStatus.UnknownResponseException("Empty response");
}
if (response.startsWith("success")) {
Log.i(TAG, "Scrobble success: " + netAppName);
/*if (settings.isNowPlayingEnabled(pow)) { // support is coming
mNetManager.launchGetUserInfo(getNetApp());
}*/
JSONObject jObject = new JSONObject(response);
if (jObject.has("status")) {
Log.i(TAG, "Listen success: " + netAppName);
} else if (jObject.has("error")) {
Log.i(TAG, "Listen failed: " + response);
if (resCode != 400) {
// don't throw if code is 400 because it's a badly formatted
// submission and we don't want to cache/try again
throw new AuthStatus.UnknownResponseException("Invalid Response");
}
} else {
throw new AuthStatus.UnknownResponseException("Invalid Response");
}
Expand Down

0 comments on commit c78ceb2

Please sign in to comment.