Skip to content

Commit

Permalink
v0.0.17-rho
Browse files Browse the repository at this point in the history
Version [0.0.17] - 2020-10-18
- added dynamic limit for response size (Ampache API)
- added handling 'session expired' error (Ampache API)
- fixed progressbar during sync (remote playlists do not count)
- fixed order of playlists, locals always first
- fixed some crashes
- added support for D2 Air, Sq. Music
  • Loading branch information
memen45 committed Oct 18, 2020
1 parent 6a92aa2 commit 4786d37
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 153 deletions.
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version [0.0.17] - 2020-10-18
- added dynamic limit for response size (Ampache API)
- added handling 'session expired' error (Ampache API)
- fixed progressbar during sync (remote playlists do not count)
- fixed order of playlists, locals always first
- fixed some crashes
- added support for D2 Air, Sq. Music

Version [0.0.16] - 2020-10-08
- added support for d2 delta series and Venu Mercedes-Benz Collection
- fixed null handling (Nextcloud + SMB storage bug)
Expand Down
4 changes: 3 additions & 1 deletion manifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. --><iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="3">
<iq:application entry="SubMusicApp" id="62436b93f69e4823a8b41854b6684b4a" launcherIcon="@Drawables.LauncherIcon" name="@Strings.AppName" type="audio-content-provider-app" version="0.0.16">
<iq:application entry="SubMusicApp" id="62436b93f69e4823a8b41854b6684b4a" launcherIcon="@Drawables.LauncherIcon" name="@Strings.AppName" type="audio-content-provider-app" version="0.0.17">
<iq:products>
<iq:product id="d2air"/>
<iq:product id="d2delta"/>
<iq:product id="d2deltapx"/>
<iq:product id="d2deltas"/>
Expand Down Expand Up @@ -28,6 +29,7 @@
<iq:product id="marqgolfer"/>
<iq:product id="venu"/>
<iq:product id="venud"/>
<iq:product id="venusqm"/>
<iq:product id="vivoactive3m"/>
<iq:product id="vivoactive3mlte"/>
<iq:product id="vivoactive4"/>
Expand Down
2 changes: 1 addition & 1 deletion resources/strings/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<strings>
<string id="AppName">SubMusic</string>

<string id="AppVersionTitle">0.0.16 - pi</string>
<string id="AppVersionTitle">0.0.17 - rho</string>
<string id="ApiStandard">API backend</string>
<string id="ApiStandardSubsonic">Subsonic API</string>
<string id="ApiStandardAmpache">Ampache API</string>
Expand Down
79 changes: 36 additions & 43 deletions source/AmpacheAPI.mc
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ class AmpacheAPI {
private var d_expire;

private var d_callback;
private var d_ecallback;
private var d_fallback;


function initialize(settings, fallback) {
function initialize(settings, ecallback, fallback) {
set(settings);

// set name for this client
d_client = (WatchUi.loadResource(Rez.Strings.AppName) + " v" + WatchUi.loadResource(Rez.Strings.AppVersionTitle));
System.println("Initialize AmpacheAPI(client name: " + d_client + ")");

d_fallback = fallback;
d_ecallback = ecallback;

// check if auth is expired, it may be usable!
d_expire = new Time.Moment(0);
Expand All @@ -47,6 +49,10 @@ class AmpacheAPI {
// update the settings
set(settings);

deleteSession();
}

function deleteSession() {
// reset the session
d_expire = new Time.Moment(0);
Application.Storage.deleteValue("AMPACHE_API_SESSION");
Expand Down Expand Up @@ -126,22 +132,9 @@ class AmpacheAPI {
params.put("action", "playlists");
params.put("auth", d_session.get("auth"));

Communications.makeWebRequest(d_url, params, {}, self.method(:onPlaylists));
Communications.makeWebRequest(d_url, params, {}, self.method(:onArrayResponse));
}

function onPlaylists(responseCode, data) {
System.println("AmpacheAPI::onPlaylists with responseCode: " + responseCode + ", payload " + data);

// check if request was successful and response is ok
if ((responseCode != 200)
|| (data == null)
|| !(data instanceof Lang.Array)) {
d_fallback.invoke(responseCode, data);
return;
}
d_callback.invoke(data);
}

// returns single playlist info
function playlist(callback, params) {
System.println("AmpacheAPI::playlist( id: " + params["filter"] + ")");
Expand All @@ -150,22 +143,9 @@ class AmpacheAPI {

params.put("action", "playlist");
params.put("auth", d_session.get("auth"));
Communications.makeWebRequest(d_url, params, {}, self.method(:onPlaylist));
Communications.makeWebRequest(d_url, params, {}, self.method(:onArrayResponse));
}

function onPlaylist(responseCode, data) {
System.println("AmpacheAPI::onPlaylist with responseCode: " + responseCode + ", payload " + data);

// check if request was successful and response is ok
if ((responseCode != 200)
|| (data == null)
|| !(data instanceof Lang.Array)) {
d_fallback.invoke(responseCode, data);
return;
}
d_callback.invoke(data);
}

// returns array of song objects
function playlist_songs(callback, params) {
System.println("AmpacheAPI::playlist_songs( id: " + params["filter"] + ")");
Expand All @@ -174,22 +154,9 @@ class AmpacheAPI {

params.put("action", "playlist_songs");
params.put("auth", d_session.get("auth"));
Communications.makeWebRequest(d_url, params, {}, self.method(:onPlaylist_songs));
Communications.makeWebRequest(d_url, params, {}, self.method(:onArrayResponse));
}

function onPlaylist_songs(responseCode, data) {
System.println("AmpacheAPI::onPlaylist_songs with responseCode: " + responseCode + ", payload " + data);

// check if request was successful and response is ok
if ((responseCode != 200)
|| (data == null)
|| !(data instanceof Lang.Array)) {
d_fallback.invoke(responseCode, data);
return;
}
d_callback.invoke(data);
}

// returns refId to the downloaded song
function stream(callback, params, encoding) {
System.println("AmpacheAPI::stream( id : " + params["id"] + " )");
Expand Down Expand Up @@ -231,6 +198,32 @@ class AmpacheAPI {
}
return now.lessThan(d_expire);
}

function onArrayResponse(responseCode, data) {
System.println("AmpacheAPI::onArrayResponse with responseCode: " + responseCode + ", payload " + data);

// watch Communication errors are filtered first
if ((responseCode != 200)
|| (data == null)) {
d_fallback.invoke(responseCode, data);
return;
}

// callback when data is indeed an Array
if (data instanceof Lang.Array) {
d_callback.invoke(data);
return;
}

// error callback when data is an ampache error
if (data instanceof Lang.Dictionary) {
d_ecallback.invoke(data["error"]["code"], data["error"]["message"]);
return;
}

// unknown problem, call fallback
d_fallback.invoke(responseCode, data);
}

// converts rfc3339 formatted timestamp to Time::Moment (null on error)
function parseISODate(date) {
Expand Down
Loading

0 comments on commit 4786d37

Please sign in to comment.