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 #470 from a93-39a/master
Browse files Browse the repository at this point in the history
Orange Squeeze and albumArtist
  • Loading branch information
Austin H authored Aug 10, 2019
2 parents 112678d + 866121c commit 2eb4e8d
Show file tree
Hide file tree
Showing 27 changed files with 220 additions and 24 deletions.
14 changes: 9 additions & 5 deletions Developer's API.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The possible fields for the intent (to be put in its extras bundle) are:
| app-package | String | Yes | The package of the music app |
| state | int | Yes | One of the states above |
| album | String | No | The album name _Strongly recommended_ |
| albumartist | String | No | The album artist name _Strongly recommended_ |
| artist | String | Yes | The artist name |
| track | String | Yes | The track name |
| duration | int | Yes | The duration of the track (in seconds) |
Expand Down Expand Up @@ -68,12 +69,13 @@ bCast.putExtra("app-name", "Example App");
bCast.putExtra("app-package", "com.example.exampleapp");
bCast.putExtra("artist", "Chris Cornell");
bCast.putExtra("album", "Casino Royale");
bCast.putExtra("albumartist", "David Arnold");
bCast.putExtra("track", "You Know My Name");
bCast.putExtra("duration", 244);
sendBroadcast(bCast);
~~~

And this says that James Marster's song "Looking At You" has finished playing and should be scrobbled:
And this says that James Marster's song "Looking At You" has finished playing and should be scrobbled:

~~~ java
Intent bCast = new Intent("com.adam.aslfms.notify.playstatechanged");
Expand All @@ -82,6 +84,7 @@ bCast.putExtra("app-name", "Example App");
bCast.putExtra("app-package", "com.example.exampleapp");
bCast.putExtra("artist", "James Marsters");
bCast.putExtra("album", "Like A Waterfall");
bCast.putExtra("albumartist", "James Marsters");
bCast.putExtra("track", "Looking At You");
bCast.putExtra("duration", 175);
sendBroadcast(bCast);
Expand All @@ -96,6 +99,7 @@ bCast.putExtra("app-name", "Example App");
bCast.putExtra("app-package", "com.example.exampleapp");
bCast.putExtra("artist", "Yohanna");
bCast.putExtra("album", "Eurovision Song Contest: Moscow 2009 (disc 2)");
bCast.putExtra("albumartist", "Óskar Páll Sveinsson");
bCast.putExtra("track", "Is It True? (Iceland)");
bCast.putExtra("duration", 181);
bCast.putExtra("track-number", 3);
Expand All @@ -104,7 +108,7 @@ bCast.putExtra("source", "R");
sendBroadcast(bCast);
~~~

The app ³ (cubed) [implements](http://github.com/fabrantes/rockonnggl/blob/master/src/org/abrantix/rockon/rockonnggl/RockOnNextGenService.java) this API.
The app (cubed) [implements](http://github.com/fabrantes/rockonnggl/blob/master/src/org/abrantix/rockon/rockonnggl/RockOnNextGenService.java) this API.

## Internals

Expand All @@ -114,7 +118,7 @@ The behavioiur to handle these API broadcasts is implemented in the `BroadcastRe

When a user starts playing music in a music app using this api, she will automatically have her music scrobbled. The first broadcast to be sent to SLS will create an entry in the Supported Apps section, where the user can disable/enable scrobbling from that application (it is enabled by default).

To make this work properly, the two fields `app-name` and `app-package` are crucial. `app-name` is the string that gets displayed to the user, and `app-package` is what identifies the source of the music played. This should be the "root package" (or whatever it's called) of the music app, and it should never change.
To make this work properly, the two fields `app-name` and `app-package` are crucial. `app-name` is the string that gets displayed to the user, and `app-package` is what identifies the source of the music played. This should be the "root package" (or whatever it's called) of the music app, and it should never change.

## Troubleshooting

Expand Down Expand Up @@ -146,8 +150,8 @@ Open an issue here on github and we'll look into an problems you might have. Sav

## Custom Broadcasts

If you already broadcast your own intents, tell me about them and I'll see if I can work them into SLS.
If you already broadcast your own intents, tell me about them and I'll see if I can work them into SLS.

## Thanks

A tip of the hat to jjc1138 of Scrobble Droid, his/her documentation is superb.
A tip of the hat to jjc1138 of Scrobble Droid, his/her documentation is superb.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Before the release of a new version of SLS, it will be available here to test fo
* Sequential storage of all tracks, scrobbled, skipped, hearted, and failed with explanations
* markers in scrobble cache for logged in accounts
* Store scrobbles before user is logged in
* Manual scrobbling, for example Vinyl Records, CD, Cassette and other older media machines.

## Features

Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ android {
lintOptions {
abortOnError false
// TODO: fix all lint warnings
// TODO: decide what to do about at:Supress("Deprecation")
ignoreWarnings true
}

Expand Down
2 changes: 1 addition & 1 deletion app/debug/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":49,"versionName":"1.5.8","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"app-debug.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":49,"versionName":"1.5.8","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"app-debug.apk","properties":{}}]
Binary file added app/release/app-release.apk
Binary file not shown.
Binary file added app/release/app.aab
Binary file not shown.
1 change: 1 addition & 0 deletions app/release/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":49,"versionName":"1.5.8","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,16 @@
<action android:name="com.android.mediacenter.metachanged" />
</intent-filter>
</receiver>
<receiver android:name=".receiver.OrangeSqueezeReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<!-- https://www.orangebikelabs.com/products/orangesqueeze/broadcast-intents -->
<!-- ISSUE! SEE playername intent, hence, won't be taking the time to track multiple players -->
<action android:name="com.orangebikelabs.orangesqueeze.metachanged" />
<action android:name="com.orangebikelabs.orangesqueeze.playstatechanged" />
</intent-filter>
</receiver>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.e(TAG, getResources().getResourceName(settings.getAppTheme()));
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/adam/aslfms/ChangeThemeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.e(TAG, getResources().getResourceName(settings.getAppTheme()));
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/adam/aslfms/MusicAppsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.e(TAG, getResources().getResourceName(settings.getAppTheme()));
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/adam/aslfms/OptionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.e(TAG, getResources().getResourceName(settings.getAppTheme()));
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/adam/aslfms/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.e(TAG, getResources().getResourceName(settings.getAppTheme()));
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down Expand Up @@ -123,10 +123,12 @@ protected void onCreate(Bundle savedInstanceState) {
permsCheck();
credsCheck();

// TODO: VERIFY EVERYTHING BELOW IS SAFE
int v = Util.getAppVersionCode(this, getPackageName());
if (settings.getWhatsNewViewedVersion() < v) {
new WhatsNewDialog(this).show();
settings.setWhatsNewViewedVersion(v);
mDb.alterDataBaseOnce(); // version 1.5.8 only!
}

// Start Apple listening service if applicabble
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/adam/aslfms/StatusActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.e(TAG, getResources().getResourceName(settings.getAppTheme()));
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/adam/aslfms/UserCredActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.e(TAG, getResources().getResourceName(settings.getAppTheme()));
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.e(TAG, getResources().getResourceName(settings.getAppTheme()));
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.e(TAG, getResources().getResourceName(settings.getAppTheme()));
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.e(TAG, getResources().getResourceName(settings.getAppTheme()));
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*/
public abstract class AbstractPlayStatusReceiver extends BroadcastReceiver {

private static final String TAG = "SLSPlayStatusReceiver";
private static final String TAG = "AbsPlayStatusReceiver";

private MusicAPI mMusicAPI = null;
private Intent mService = null;
Expand All @@ -59,12 +59,12 @@ public static void dumpIntent(Bundle bundle){
if (bundle != null) {
Set<String> keys = bundle.keySet();
Iterator<String> it = keys.iterator();
Log.e(TAG,"Dumping Intent start");
Log.d(TAG,"Dumping Intent start");
while (it.hasNext()) {
String key = it.next();
Log.e(TAG,"[" + key + "=" + bundle.get(key)+"]");
Log.d(TAG,"[" + key + "=" + bundle.get(key)+"]");
}
Log.e(TAG,"Dumping Intent end");
Log.d(TAG,"Dumping Intent end");
}
}

Expand All @@ -75,7 +75,7 @@ public final void onReceive(Context context, Intent intent) {

dumpIntent(bundle);

Log.e(TAG, "Action received was: " + action);
Log.d(TAG, "Action received was: " + action);

// check to make sure we actually got something
if (action == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ void readTrackFromMediaStore(Context ctx, Track.Builder b, long audioid) {
MediaStore.Audio.AudioColumns.TITLE,
MediaStore.Audio.AudioColumns.DURATION,
MediaStore.Audio.AudioColumns.ALBUM,
MediaStore.Audio.AudioColumns.TRACK, };
MediaStore.Audio.AudioColumns.TRACK,
MediaStore.Audio.AudioColumns.COMPOSER};

Cursor cur = ctx.getContentResolver().query(
ContentUris.withAppendedId(
Expand All @@ -242,6 +243,10 @@ void readTrackFromMediaStore(Context ctx, Track.Builder b, long audioid) {
String album = cur.getString(cur.getColumnIndex(MediaStore.Audio.AudioColumns.ALBUM));
b.setAlbum(album);

String albumArtist = cur.getString(cur.getColumnIndex(MediaStore.Audio.AudioColumns.COMPOSER));
b.setAlbumArtist(albumArtist);


int duration = (int) (cur.getLong(cur.getColumnIndex(MediaStore.Audio.AudioColumns.DURATION)) / 1000);

if (duration != 0) {
Expand Down Expand Up @@ -303,7 +308,17 @@ void readTrackFromBundleData(Track.Builder b, Bundle bundle) {
b.setAlbum(al.toString());
}
} else {
b.setAlbum("");
b.setAlbum(""); // album is not required to scrobble
}
if (bundle.containsKey("albumartist")){
CharSequence al = bundle.getCharSequence("albumartist");
if (al == null || "Unknown albumArtist".equals(al.toString()) || "Unknown".equals(al.toString())) {
b.setAlbumArtist(""); // albumArtist is not required to scrobble.
} else {
b.setAlbumArtist(al.toString());
}
} else {
b.setAlbumArtist(""); // albumArtist is not required to scrobble
}
b.setArtist(ar.toString());
b.setTrack(tr.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.adam.aslfms.receiver;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.adam.aslfms.util.Track;
import com.adam.aslfms.util.Util;

/**
* A BroadcastReceiver for intents sent by the Orange Squeeze music player
*
* @see AbstractPlayStatusReceiver
*
* @author Austin Hogan <[email protected]>
* @since 1.5.8
*/
public class OrangeSqueezeReceiver extends AbstractPlayStatusReceiver {

static final String APP_PACKAGE = "com.orangebikelabs.orangesqueeze";
static final String APP_NAME = "Orange Squeeze";

static final String ACTION_ORANGE_METACHANGED = "com.orangebikelabs.orangesqueeze.metachanged";
static final String ACTION_ORANGE_PLAYSTATECHANGED = "com.orangebikelabs.orangesqueeze.playstatechanged";

static final String TAG = "OrangeSqzReceiver";
static private Track track = null;

@Override
protected void parseIntent(Context ctx, String action, Bundle bundle) {

MusicAPI musicAPI = MusicAPI.fromReceiver(
ctx, APP_NAME, APP_PACKAGE, null, false);
setMusicAPI(musicAPI);

if (action.equals(ACTION_ORANGE_METACHANGED)) {
boolean isPlaying = bundle.getBoolean("isplaying");
boolean isPaused = bundle.getBoolean("ispaused");
if (isPaused) {
setState(Track.State.PAUSE);
Log.d(TAG, "Setting state to PAUSE");
}
if (isPlaying) {
setState(Track.State.RESUME);
Log.d(TAG, "Setting state to RESUME");
}
Track.Builder b = new Track.Builder();
b.setMusicAPI(musicAPI);
b.setWhen(Util.currentTimeSecsUTC());

b.setArtist(bundle.getString("artist"));
b.setAlbum(bundle.getString("album"));
b.setTrack(bundle.getString("track"));
b.setAlbumArtist(bundle.getString("albumartist"));
b.setTrackArtist(bundle.getString("trackartist"));
b.setTrackNr(bundle.getString("tracknr"));
b.setDuration(bundle.getInt("duration")/1000); // convert ms to
setTrack(b.build());
}
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/com/adam/aslfms/receiver/SLSAPIReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ else if (state == STATE_COMPLETE)
} else {
b.setAlbum("");
}
// albumartist name, optional (recommended)
if (bundle.containsKey("albumartist")){
CharSequence al = bundle.getCharSequence("albumartist");
if (al == null || "Unknown albumArtist".equals(al.toString()) || "Unknown".equals(al.toString())) {
b.setAlbumArtist(""); // albumArtist is not required to scrobble.
} else {
b.setAlbumArtist(al.toString());
}
} else {
b.setAlbumArtist(""); // albumArtist is not required to scrobble
}
// track name, required
b.setTrack(bundle.getString("track"));

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/adam/aslfms/service/NPNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ public void notifyNowPlaying(Track track, HandshakeResult hInfo)
if (track.getAlbum() != null) {
params.put("album", track.getAlbum());
}
if (track.getAlbumArtist() != null) {
params.put("albumArtist", track.getAlbumArtist());
}
params.put("api_key", settings.rcnvK(settings.getAPIkey()));
params.put("artist", track.getArtist());
if (track.getDuration() != 180) {
Expand Down
Loading

0 comments on commit 2eb4e8d

Please sign in to comment.