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 #543 from a93h/master
Browse files Browse the repository at this point in the history
Simple Scrobbler codename Mingus
  • Loading branch information
Austin H authored Sep 22, 2019
2 parents 3ad6964 + 174c68d commit 294ecfe
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 61 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.adam.aslfms"
minSdkVersion 14
targetSdkVersion 26
versionCode = 60
versionName = "1.6.9"
versionCode = 61
versionName = "1.7.0"

testApplicationId "com.adam.aslfms.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/assets/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ For more details.
https://github.com/simple-last-fm-scrobbler/sls/wiki/Privacy-Concerns
For privacy concerns.

- 1.7.0 (2019-9-22) codename: mingus
* Login notification bug
* Music App Activity bug
* Rate Limit Exceeded status for Last.fm

- 1.6.9 (2019-9-15) codename: lingus
* major database patch


- 1.6.8 (2019-9-15) codename: kingus
* Database problems fixed
* Database migration
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/adam/aslfms/MusicAppsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void update() {
break;
case 2:
default:
appPref.setIcon(android.R.drawable.stat_sys_warning);
appPref.setIcon(android.R.drawable.ic_menu_help);
break;
}

Expand Down Expand Up @@ -225,8 +225,7 @@ private void setSMASummary(Preference pref, MusicAPI mapi) {
pref.setSummary(getString(R.string.incompatability_short)
.replaceAll("%1", mScrobbleDroidLabel));
} else {
if (!mapi.getMessage().equals("generic receiver")) pref.setSummary(mapi.getMessage());
else pref.setSummary("");
pref.setSummary(mapi.getMessage());
}
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/adam/aslfms/StatusActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import com.adam.aslfms.service.NetApp;
import com.adam.aslfms.util.AppSettings;
import com.adam.aslfms.util.AuthStatus;
import com.adam.aslfms.util.ScrobblesDatabase;
import com.adam.aslfms.util.Util;

Expand Down Expand Up @@ -139,7 +140,7 @@ private void setupViewPager(ViewPager viewPager) {
TabAdapter adapter = new TabAdapter(getSupportFragmentManager());

for (NetApp napp : NetApp.values()) {
if (settings.isAuthenticated(napp)) {
if(settings.getAuthStatus(napp) != AuthStatus.AUTHSTATUS_NOAUTH) {
adapter.addFragment(StatusFragment.newInstance(napp.getValue()), napp.getName());
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/adam/aslfms/StatusFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected void fillData() {
auth.setKey(getString(R.string.logged_in_just));
auth.setValue(settings.getUsername(mNetApp));
} else {
auth.setKey(getString(R.string.not_logged_in));
auth.setKey(Util.getStatusSummary(getContext(), settings, mNetApp));
auth
.setValue(Util.getStatusSummary(getActivity(), settings, mNetApp,
false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.adam.aslfms.MusicAppsActivity;
import com.adam.aslfms.R;
import com.adam.aslfms.UserCredActivity;
import com.adam.aslfms.service.NetApp;
import com.adam.aslfms.service.ScrobblingService;
import com.adam.aslfms.util.AppSettings;
import com.adam.aslfms.util.InternalTrackTransmitter;
Expand Down Expand Up @@ -92,9 +93,9 @@ public final void onReceive(Context context, Intent intent) {
bundle = Bundle.EMPTY;
}

// start/call the Scrobbling Service
mService = new Intent(context, ScrobblingService.class);
mService.setAction(ScrobblingService.ACTION_PLAYSTATECHANGED);

try {
parseIntent(context, action, bundle); // might throw

Expand All @@ -114,24 +115,34 @@ public final void onReceive(Context context, Intent intent) {
} else if (mMusicAPI.getEnabledValue() == 2) {
Util.myNotify(context, mMusicAPI.getName(), context.getString(R.string.new_music_app), 12473, new Intent(context, MusicAppsActivity.class));
Log.d(TAG, "App: " + mMusicAPI.getName()
+ " has been ignored, will propagate");
+ " has been ignored, won't propagate");
return;
}

// submit track for the ScrobblingService
InternalTrackTransmitter.appendTrack(mTrack);
AppSettings settings = new AppSettings(context);
// start/call the Scrobbling Service

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && settings.isActiveAppEnabled(Util.checkPower(context))) {
context.startForegroundService(mService);
} else {
context.startService(mService);
}

// we must be logged in to scrobble
if (!settings.isAnyAuthenticated()) {
Intent i = new Intent(context, UserCredActivity.class);
i.putExtra("netapp", NetApp.LASTFM.getIntentExtraValue());
Util.myNotify(context, context.getResources().getString(R.string.warning) , context.getResources().getString(R.string.not_logged_in),05233, i);
Log
.d(TAG,
"The user has not authenticated, won't propagate the submission request");
return;
}
} catch (IllegalArgumentException e) {
Log.i(TAG, "Got a bad track from: "
+ ((mMusicAPI == null) ? "null" : mMusicAPI.getName())
+ ", ignoring it (" + e.getMessage() + ")");
}

}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/adam/aslfms/receiver/MusicAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static MusicAPI fromReceiver(Context ctx, String name, String pkg,
vals.put("pkg", pkg);
vals.put("msg", msg);
vals.put("sdclash", clashWithScrobbleDroid ? 1 : 0);
if (msg.equals("generic receiver")) vals.put("enabled", 2);
if (msg != null && msg.equals("generic receiver")) vals.put("enabled", 2);
else vals.put("enabled", 1);

long id = db.insert("music_api", null, vals);
Expand All @@ -309,7 +309,7 @@ public static MusicAPI fromReceiver(Context ctx, String name, String pkg,
Log.d(TAG, "new mapiinserted into db");
}

if (msg.equals("generic receiver")) mapi = new MusicAPI(id, name, pkg, msg, clashWithScrobbleDroid, 2);
if (msg != null && msg.equals("generic receiver")) mapi = new MusicAPI(id, name, pkg, msg, clashWithScrobbleDroid, 2);
else mapi = new MusicAPI(id, name, pkg, msg, clashWithScrobbleDroid, 1);
Log.d(TAG, mapi.toString());
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/adam/aslfms/service/Handshaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,13 @@ public HandshakeResult handshake() throws BadAuthException,
}
} else if (jObject.has("error")) {
int code = jObject.getInt("error");
if (code == 4 || code == 6) {
if (code == 9) {
Log.e(TAG, "Handshake fails: wrong username/password");
settings.setSessionKey(netApp, "");
throw new BadAuthException(getContext().getString(
R.string.auth_bad_auth));
} else if (code == 26 || code == 10) {
Log.e(TAG, "Handshake fails: client banned: " + netAppName);
settings.setSessionKey(netApp, "");
throw new ClientBannedException(getContext().getString(
R.string.auth_client_banned));
} else {
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/com/adam/aslfms/service/Heart.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ public class Heart extends NetRunnable {

protected ScrobblesDatabase db;
protected AppSettings settings;
protected NetApp napp;

Context mCtx;


public Heart(NetApp napp, Context ctx, Networker net, ScrobblesDatabase db) {
super(napp, ctx, net);
this.napp = napp;
this.db = db;
this.mCtx = ctx;
}
Expand All @@ -71,11 +74,11 @@ public final void run() {
// can't heart track


String[][] strings = db.fetchHeartsArray();
String[][] strings = db.fetchHeartsArray(napp);

for (String[] s : strings) {

boolean failure = false;
boolean submitted = false;
String sigText = "api_key"
+ settings.rcnvK(settings.getAPIkey())
+ "artist" + s[1]
Expand All @@ -91,6 +94,7 @@ public final void run() {
// TODO: ascertain if string is Json
if (response.equals("okSuccess")) {
Log.d(TAG, "Successful heart track: " + getNetApp().getName());
submitted = true;
} else {
JSONObject jObject = new JSONObject(response);
if (jObject.has("error")) {
Expand All @@ -100,15 +104,13 @@ public final void run() {
}
} else {
Log.d(TAG, "Failed heart track.");
failure = true;
}
}
} catch (Exception e) {
Log.e(TAG, "Heart track fail " + e);
//e.printStackTrace();
failure = true;
}
if (failure) db.deleteHeart(s);
if (submitted) db.deleteHeart(s);
}
}

Expand Down
28 changes: 20 additions & 8 deletions app/src/main/java/com/adam/aslfms/service/NPNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ protected boolean doRun(HandshakeResult hInfo) {
notifySubmissionStatusFailure(getContext().getString(
R.string.auth_network_error_retrying));
ret = false;
} catch (AuthStatus.RetryLaterFailureException e){
Log.i(TAG, "Tempfail: " + e.getMessage() + ": "
+ getNetApp().getName());
notifyAuthStatusUpdate(AuthStatus.AUTHSTATUS_RETRYLATER_RATE_LIMIT_EXCEEDED);
notifySubmissionStatusFailure(getContext().getString(
R.string.auth_rate_limit_exceeded));
getNetworker().launchSleeper();
e.getStackTrace();
ret = false;
} catch (AuthStatus.ClientBannedException e) {
Log.e(TAG, "This version of the client has been banned!!" + ": "
+ getNetApp().getName());
Expand Down Expand Up @@ -163,7 +172,7 @@ private void notifyAuthStatusUpdate(int st) {
* @throws UnknownResponseException {@link UnknownResponseException}
*/
public void notifyNowPlaying(Track track, HandshakeResult hInfo)
throws BadSessionException, TemporaryFailureException, AuthStatus.ClientBannedException, AuthStatus.UnknownResponseException {
throws BadSessionException, TemporaryFailureException, AuthStatus.ClientBannedException, AuthStatus.UnknownResponseException, AuthStatus.RetryLaterFailureException {
NetApp netApp = getNetApp();
String netAppName = netApp.getName();

Expand Down Expand Up @@ -465,17 +474,20 @@ public void notifyNowPlaying(Track track, HandshakeResult hInfo)
Log.i(TAG, "Now Playing success: " + netAppName);
} else if (jObject.has("error")) {
int code = jObject.getInt("error");
if (code == 26 || code == 10) {
Log.e(TAG, "Now Playing failed: client banned: " + netAppName);
settings.setSessionKey(netApp, "");
throw new AuthStatus.ClientBannedException("Now Playing failed because of client banned");
if (code == 26 || code == 10 ) {
Log.e(TAG, "Now playing failed: client banned: " + netApp.getName());
throw new AuthStatus.ClientBannedException("Now playing failed because of client banned");
} else if (code == 9) {
Log.e(TAG, "Now Playing failed: bad auth: " + netAppName);
Log.i(TAG, "Now playing failed: bad auth: " + netApp.getName());
settings.setSessionKey(netApp, "");
throw new BadSessionException("Now Playing failed because of badsession");
throw new BadSessionException("Now playing failed because of badsession");
} else if (code == 29) {
Log.i(TAG, "Now playing failed: rate limit exceeded: " + netApp.getName());
throw new AuthStatus.RetryLaterFailureException("Now playing failed because of client rate limit");
} else {
Log.e(TAG, "Now Playing fails: FAILED " + response + ": " + netAppName);
Log.e(TAG, "Now playing fails: FAILED " + response + ": " + netApp.getName());
//settings.setSessionKey(netApp, "");

throw new TemporaryFailureException("Now playing failed because of " + response);
}
} else {
Expand Down
24 changes: 18 additions & 6 deletions app/src/main/java/com/adam/aslfms/service/Scrobbler.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,19 @@ public boolean doRun(HandshakeResult hInfo) {
Util.myNotify(mCtx, getNetApp().getName(),
mCtx.getString(R.string.auth_bad_auth), 39201, new Intent(mCtx, SettingsActivity.class));
ret = true;
} catch (AuthStatus.RetryLaterFailureException e){
Log.i(TAG, "Tempfail: " + e.getMessage() + ": "
+ getNetApp().getName());
notifyAuthStatusUpdate(AuthStatus.AUTHSTATUS_RETRYLATER);
notifySubmissionStatusFailure(getContext().getString(
R.string.auth_rate_limit_exceeded));
getNetworker().launchSleeper();
e.getStackTrace();
ret = false;
} catch (TemporaryFailureException e) {
Log.i(TAG, "Tempfail: " + e.getMessage() + ": "
+ getNetApp().getName());
notifyAuthStatusUpdate(AuthStatus.AUTHSTATUS_RETRYLATER);
notifySubmissionStatusFailure(getContext().getString(
R.string.auth_network_error_retrying));
e.getStackTrace();
Expand Down Expand Up @@ -200,7 +210,7 @@ private void notifyAuthStatusUpdate(int st) {
* @throws AuthStatus.BadSessionException
*/
public void scrobbleCommit(HandshakeResult hInfo, Track[] tracks)
throws BadSessionException, TemporaryFailureException, AuthStatus.ClientBannedException, AuthStatus.UnknownResponseException {
throws BadSessionException, TemporaryFailureException, AuthStatus.ClientBannedException, AuthStatus.UnknownResponseException, AuthStatus.RetryLaterFailureException {

NetApp netApp = getNetApp();
String netAppName = netApp.getName();
Expand Down Expand Up @@ -551,14 +561,16 @@ public void scrobbleCommit(HandshakeResult hInfo, Track[] tracks)
Log.i(TAG, "Scrobble success: " + netAppName + ": Ignored Count: " + Integer.toString(scrobsIgnored));
} else if (jObject.has("error")) {
int code = jObject.getInt("error");
if (code == 26 || code == 10) {
Log.e(TAG, "Scobble failed: client banned: " + netApp.getName());
settings.setSessionKey(netApp, "");
throw new AuthStatus.ClientBannedException("Now Playing failed because of client banned");
if (code == 26 || code == 10 || code == 15) { // code 15 is for token has expired
Log.e(TAG, "Scrobble failed: client banned: " + netApp.getName());
throw new AuthStatus.ClientBannedException("Scrobbling failed because of client banned");
} else if (code == 9) {
Log.i(TAG, "Scrobble failed: bad auth: " + netApp.getName());
settings.setSessionKey(netApp, "");
throw new BadSessionException("Now Playing failed because of badsession");
throw new BadSessionException("Scrobbling failed because of badsession");
} else if (code == 29) {
Log.i(TAG, "Scrobble failed: rate limit exceeded: " + netApp.getName());
throw new AuthStatus.RetryLaterFailureException("Scrobbling failed because of client rate limit");
} else {
Log.e(TAG, "Scrobble fails: FAILED " + response + ": " + netApp.getName());
//settings.setSessionKey(netApp, "");
Expand Down
15 changes: 0 additions & 15 deletions app/src/main/java/com/adam/aslfms/service/ScrobblingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,21 +286,6 @@ private synchronized void onPlayStateChanged(Track track, Track.State state) {
tryNotifyNP(mCurrentTrack);

foreGroundService();
// we must be logged in to scrobble
if (!settings.isAnyAuthenticated()) {

Intent intent = new Intent(mCtx, UserCredActivity.class);
for (NetApp netApp : NetApp.values()) {
if (settings.isAuthenticated(netApp)) {
intent.putExtra("netappid", netApp.getIntentExtraValue());
break;
}
}
Util.myNotify(this, this.getResources().getString(R.string.warning) , this.getResources().getString(R.string.not_logged_in),05233, intent);
Log
.d(TAG,
"The user has not authenticated, won't propagate the submission request");
}
} else if (state == Track.State.PAUSE) { // pause
// TODO: test this state
if (mCurrentTrack == null) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/adam/aslfms/util/AuthStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class AuthStatus {
public static final int AUTHSTATUS_OK = 5;
public static final int AUTHSTATUS_CLIENTBANNED = 6;
public static final int AUTHSTATUS_NETWORKUNFIT = 7;
public static final int AUTHSTATUS_RETRYLATER_RATE_LIMIT_EXCEEDED = 8;

public static class StatusException extends Exception {
private static final long serialVersionUID = 7204759787220898684L;
Expand Down Expand Up @@ -78,6 +79,15 @@ public TemporaryFailureException(String detailMessage) {
}
}

public static class RetryLaterFailureException extends StatusException {

private static final long serialVersionUID = 8815752389387226812L;

public RetryLaterFailureException(String detailMessage) {
super(detailMessage);
}
}

public static class UnknownResponseException extends StatusException {
private static final long serialVersionUID = 7351097754868391707L;

Expand Down
Loading

0 comments on commit 294ecfe

Please sign in to comment.