Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Facebook authentication flow #356

Closed
wants to merge 127 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
2757273
Implementing the new Facebook auth flow
devgianlu May 9, 2021
325a350
Bump maven-gpg-plugin from 1.6 to 3.0.1
dependabot[bot] May 10, 2021
edb8f16
Merge pull request #357 from librespot-org/dependabot/maven/org.apach…
devgianlu May 10, 2021
c9f9f53
Fixed `/discovery/list` not returning available clients (#352)
devgianlu May 11, 2021
2745b50
Fixed `/discovery/list` failing with multiple clients on the network …
devgianlu May 11, 2021
ff7f261
Minor state adjustments
devgianlu May 11, 2021
1f62642
Added Player#isReady
devgianlu May 12, 2021
2fec5c2
Bump protobuf-java from 3.16.0 to 3.17.0
dependabot[bot] May 13, 2021
3b3f24f
Bump junit-jupiter from 5.7.1 to 5.7.2
dependabot[bot] May 17, 2021
8cdc197
Merge pull request #358 from librespot-org/dependabot/maven/com.googl…
devgianlu May 17, 2021
e3bd578
Merge pull request #359 from librespot-org/dependabot/maven/org.junit…
devgianlu May 17, 2021
1c507ad
Bump annotations from 20.1.0 to 21.0.0
dependabot[bot] May 21, 2021
abd2016
Bump maven-javadoc-plugin from 3.2.0 to 3.3.0
dependabot[bot] May 24, 2021
2224fcd
Bump gson from 2.8.6 to 2.8.7
dependabot[bot] May 25, 2021
5e80106
Merge pull request #364 from librespot-org/dependabot/maven/com.googl…
devgianlu May 25, 2021
fc3fc6d
Merge pull request #362 from librespot-org/dependabot/maven/org.apach…
devgianlu May 25, 2021
075dcf0
Merge pull request #360 from librespot-org/dependabot/maven/org.jetbr…
devgianlu May 25, 2021
b699f55
Bump protobuf-java from 3.17.0 to 3.17.1
dependabot[bot] May 25, 2021
9f90502
Merge pull request #363 from librespot-org/dependabot/maven/com.googl…
devgianlu May 25, 2021
7015cc5
Base64 URL safe encoding + fixed OAuth2 flow
devgianlu May 25, 2021
482bf45
Bump undertow-core from 2.2.7.Final to 2.2.8.Final in /api
dependabot[bot] May 26, 2021
4a2ce2e
Bump annotations from 21.0.0 to 21.0.1
dependabot[bot] May 26, 2021
a3f65f4
Bump undertow-core from 2.2.7.Final to 2.2.8.Final
dependabot[bot] May 26, 2021
a89e613
Merge pull request #367 from librespot-org/dependabot/maven/io.undert…
devgianlu May 26, 2021
375f870
Merge pull request #365 from librespot-org/dependabot/maven/api/io.un…
devgianlu May 26, 2021
cf0774a
Merge pull request #366 from librespot-org/dependabot/maven/org.jetbr…
devgianlu May 26, 2021
90a53e6
Added env variables to shell events (#368)
devgianlu May 26, 2021
e3b4f7e
Removed redundant pfls message (#361)
devgianlu May 27, 2021
e1eb2f4
Send DACP pipe flush command only if track change is user initiated (…
devgianlu May 28, 2021
bc5d332
Fixed build
devgianlu May 28, 2021
5e1f6ff
Space volume updates 500ms apart (#369)
devgianlu May 30, 2021
ada6472
Added configuration option to execute shell commands with bash (#368)
devgianlu Jun 1, 2021
240f6fe
Bump protobuf-java from 3.17.1 to 3.17.2
dependabot[bot] Jun 3, 2021
27783e0
Merge pull request #371 from librespot-org/dependabot/maven/com.googl…
devgianlu Jun 6, 2021
b4abb97
Bump zeroconf-java to 1.3.2 (#352)
devgianlu Jun 20, 2021
e35b60f
Bump slf4j-api from 1.7.30 to 1.7.31
dependabot[bot] Jun 21, 2021
591fb92
Refresh AP pool before reconnecting
devgianlu Jun 25, 2021
47ea001
Merge pull request #374 from librespot-org/dependabot/maven/org.slf4j…
devgianlu Jun 30, 2021
18174dd
Bump protobuf-java from 3.17.2 to 3.17.3
dependabot[bot] Jun 30, 2021
3f1582e
Merge pull request #372 from librespot-org/dependabot/maven/com.googl…
devgianlu Jun 30, 2021
d922f80
Removed debug statement
devgianlu Jul 13, 2021
5e7d124
Release 1.6.1
devgianlu Jul 18, 2021
9d2bd84
Bump slf4j-api from 1.7.31 to 1.7.32
dependabot[bot] Jul 21, 2021
56c7a2c
Fixed #383
devgianlu Aug 8, 2021
de14d8b
Bump toml from 3.6.3 to 3.6.4 in /player
dependabot[bot] Aug 9, 2021
ed15b64
Bump toml from 3.6.3 to 3.6.4
dependabot[bot] Aug 9, 2021
43e9d2b
Bump undertow-core from 2.2.8.Final to 2.2.10.Final in /api
dependabot[bot] Aug 11, 2021
e7e4df4
Bump undertow-core from 2.2.8.Final to 2.2.10.Final
dependabot[bot] Aug 11, 2021
d0763ac
Bump annotations from 21.0.1 to 22.0.0
dependabot[bot] Aug 13, 2021
5af8a38
HTTPS proxy support
Chainfire Aug 18, 2021
9628376
Merge pull request #390 from Chainfire/https-proxy
devgianlu Aug 18, 2021
a457231
Merge pull request #388 from librespot-org/dependabot/maven/org.jetbr…
devgianlu Aug 18, 2021
48f1926
Merge pull request #387 from librespot-org/dependabot/maven/io.undert…
devgianlu Aug 18, 2021
6f08a8f
Merge pull request #386 from librespot-org/dependabot/maven/api/io.un…
devgianlu Aug 18, 2021
b9564c1
Merge pull request #385 from librespot-org/dependabot/maven/com.elect…
devgianlu Aug 18, 2021
b5d6f59
Merge pull request #384 from librespot-org/dependabot/maven/player/co…
devgianlu Aug 18, 2021
440d2a3
Merge pull request #378 from librespot-org/dependabot/maven/org.slf4j…
devgianlu Aug 18, 2021
0aa4243
Bump gson from 2.8.7 to 2.8.8
dependabot[bot] Aug 23, 2021
c8e32c0
Bump maven-javadoc-plugin from 3.3.0 to 3.3.1
dependabot[bot] Sep 8, 2021
b14f248
Bump junit-jupiter from 5.7.2 to 5.8.0
dependabot[bot] Sep 13, 2021
53c86bf
Merge pull request #391 from librespot-org/dependabot/maven/com.googl…
devgianlu Sep 13, 2021
6b83385
Merge pull request #400 from librespot-org/dependabot/maven/org.apach…
devgianlu Sep 13, 2021
5b6d5c0
Merge pull request #402 from librespot-org/dependabot/maven/org.junit…
devgianlu Sep 13, 2021
a77fad7
feat: Add GET /instance endpoint, which returns some basic informatio…
Twinki14 Sep 15, 2021
a1d13e7
Bump protobuf-java from 3.17.3 to 3.18.0
dependabot[bot] Sep 16, 2021
8e11556
resolve: extract InstanceHandler.forSession into a variable
Twinki14 Sep 16, 2021
ef4e95d
resolve: add Utils.methodNotAllowed
Twinki14 Sep 16, 2021
60ebdc6
Merge pull request #403 from Twinki14/dev-feat-instance-get
devgianlu Sep 16, 2021
2f963e8
Add MMM-LibrespotJava to related projects
l3d00m Sep 21, 2021
5158930
Merge pull request #406 from l3d00m/patch-1
devgianlu Sep 21, 2021
06031a8
Merge pull request #404 from librespot-org/dependabot/maven/com.googl…
devgianlu Sep 22, 2021
219cc7b
Bump junit-jupiter from 5.8.0 to 5.8.1
dependabot[bot] Sep 23, 2021
92991e7
Merge pull request #407 from librespot-org/dependabot/maven/org.junit…
devgianlu Sep 27, 2021
b3d61f4
Use synchronized HashMap instead of ConcurrentHashMap for cache file …
devgianlu Sep 27, 2021
5607c5d
Added onStartedLoading and onFinishedLoading listeners
devgianlu Sep 27, 2021
e743f1b
Load missing configuration events
devgianlu Sep 27, 2021
6395cf3
Bump undertow-core from 2.2.10.Final to 2.2.12.Final
dependabot[bot] Sep 30, 2021
c6d8edf
Bump undertow-core from 2.2.10.Final to 2.2.12.Final in /api
dependabot[bot] Sep 30, 2021
6c58351
Bump okhttp from 4.9.1 to 4.9.2 in /lib
dependabot[bot] Oct 1, 2021
28a924d
Bump okhttp from 4.9.1 to 4.9.2
dependabot[bot] Oct 1, 2021
4b3f527
Merge pull request #415 from librespot-org/dependabot/maven/lib/com.s…
devgianlu Oct 3, 2021
3f2afac
Merge pull request #416 from librespot-org/dependabot/maven/com.squar…
devgianlu Oct 3, 2021
f83a6b1
Merge pull request #414 from librespot-org/dependabot/maven/api/io.un…
devgianlu Oct 3, 2021
353c9db
Merge pull request #413 from librespot-org/dependabot/maven/io.undert…
devgianlu Oct 3, 2021
ee14087
Bump protobuf-java from 3.18.0 to 3.19.0
dependabot[bot] Oct 21, 2021
e06e3ac
Merge pull request #422 from librespot-org/dependabot/maven/com.googl…
devgianlu Oct 23, 2021
88149a2
Minimize audio pop when using owntone with metadata pipe (fixes #389)
devgianlu Oct 23, 2021
132910e
Bump protobuf-java from 3.19.0 to 3.19.1
dependabot[bot] Oct 29, 2021
fdc36bf
Bump toml from 3.6.4 to 3.6.5 in /player
dependabot[bot] Nov 3, 2021
949ff10
Bump toml from 3.6.4 to 3.6.5
dependabot[bot] Nov 3, 2021
1e03081
Bump annotations from 22.0.0 to 23.0.0
dependabot[bot] Nov 11, 2021
1e939d7
Bump okhttp from 4.9.2 to 4.9.3 in /lib
dependabot[bot] Nov 22, 2021
8af1396
Bump okhttp from 4.9.2 to 4.9.3
dependabot[bot] Nov 22, 2021
94fe4f7
Bump junit-jupiter from 5.8.1 to 5.8.2
dependabot[bot] Nov 29, 2021
a3428c0
Bump undertow-core from 2.2.12.Final to 2.2.14.Final
dependabot[bot] Dec 6, 2021
aefe155
Bump undertow-core from 2.2.12.Final to 2.2.14.Final in /api
dependabot[bot] Dec 6, 2021
1cf11a9
Merge pull request #423 from librespot-org/dependabot/maven/com.googl…
devgianlu Dec 6, 2021
b1992bc
Merge pull request #426 from librespot-org/dependabot/maven/com.elect…
devgianlu Dec 6, 2021
8a57eac
Merge pull request #429 from librespot-org/dependabot/maven/com.squar…
devgianlu Dec 6, 2021
32ae03d
Merge pull request #425 from librespot-org/dependabot/maven/player/co…
devgianlu Dec 6, 2021
c68db5d
Merge pull request #427 from librespot-org/dependabot/maven/org.jetbr…
devgianlu Dec 6, 2021
fef4913
Merge pull request #435 from librespot-org/dependabot/maven/io.undert…
devgianlu Dec 6, 2021
756c5ef
Merge pull request #436 from librespot-org/dependabot/maven/api/io.un…
devgianlu Dec 6, 2021
90cb51e
Bump gson from 2.8.8 to 2.8.9
dependabot[bot] Dec 6, 2021
190004e
Merge pull request #434 from librespot-org/dependabot/maven/org.junit…
devgianlu Dec 6, 2021
b44e79b
Merge pull request #428 from librespot-org/dependabot/maven/lib/com.s…
devgianlu Dec 6, 2021
981aee8
Merge pull request #424 from librespot-org/dependabot/maven/com.googl…
devgianlu Dec 6, 2021
a93ed62
Bump log4j.version from 2.14.1 to 2.15.0
dependabot[bot] Dec 10, 2021
b5ae675
Merge pull request #437 from librespot-org/dependabot/maven/log4j.ver…
devgianlu Dec 11, 2021
3306760
Release 1.6.2
devgianlu Dec 11, 2021
0dfb6c5
Bump to snapshot version
devgianlu Dec 11, 2021
c083e5f
Bump log4j.version from 2.15.0 to 2.17.0
dependabot[bot] Dec 20, 2021
e709421
Merge pull request #440 from librespot-org/dependabot/maven/log4j.ver…
devgianlu Dec 20, 2021
18f53d5
ApResolver: Removed unused private function return
iscle Dec 20, 2021
704ca19
ApResolver: Use OkHttpClient for requesting the list
iscle Dec 20, 2021
dae67be
ApResolver: Make getUrls static
iscle Dec 22, 2021
d240c5a
ApResolver: Make request inside a try-with-resources block
iscle Dec 22, 2021
9d17a72
Merge pull request #441 from Iscle/apresolver-proxy
devgianlu Dec 22, 2021
1d31b3a
Bump log4j.version from 2.17.0 to 2.17.1
dependabot[bot] Dec 29, 2021
48f3f94
Bump protobuf-java from 3.19.1 to 3.19.2
dependabot[bot] Jan 6, 2022
d09e27e
Merge pull request #442 from librespot-org/dependabot/maven/log4j.ver…
devgianlu Jan 6, 2022
5bbad63
Merge pull request #444 from librespot-org/dependabot/maven/com.googl…
devgianlu Jan 6, 2022
08b7890
Support client-token header in API requests
devgianlu Jan 6, 2022
8a6d9a6
Moved tests to correct location
devgianlu Jan 6, 2022
978345c
Implementing the new Facebook auth flow
devgianlu May 9, 2021
4181640
Base64 URL safe encoding + fixed OAuth2 flow
devgianlu May 25, 2021
26c8591
Merge remote-tracking branch 'origin/new-facebook-flow' into new-face…
devgianlu Jan 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.6.2] - 11-12-2021
### Added
- Added HTTPS proxy support (#390)
- Added `GET /instance` API endpoint (#403)

### Fixed
- Fixed track repeat behavior (#383)
- Fixed cache synchronization issue (b3d61f4c3bb7398e2f2246f6aa274f8d903c492b)
- Minimize audio pop when using pipe (#389)
- Fix CVE-2021-44228 (#438)

## [1.6.1] - 18-07-2021
### Added
- Added `/discovery/list` API endpoint (#352)
- Added environment variables to shell event hooks (#368)
- Added `shell.executeWithBash` configuration option (#368)

### Changed
- Space volume events 500ms apart (#369)

### Fixed
- Removed redundant pfls message (#361)
- Refresh AP pool before reconnecting (591fb92db5931d611779ab83f9747f4decaea3f7)

## [1.6.0] - 09-05-2021
### Added
- Added extended metadata API (#311)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Snapshots for all variants are available [here](https://oss.sonatype.org/content
- [ansible-role-librespot](https://github.com/xMordax/ansible-role-librespot/tree/master) - Ansible role that will build, install and configure librespot-java.
- [spocon](https://github.com/spocon/spocon) - Install librespot-java from APT
- [librespot-android](https://github.com/devgianlu/librespot-android) - Run librespot-java on your Android device
- [MMM-LibrespotJava](https://github.com/l3d00m/MMM-LibrespotJava) - Show the current librespot-java playback on your [MagicMirror](https://github.com/MichMich/MagicMirror)

# Special thanks
- All the developers of [librespot](https://github.com/librespot-org/librespot) which started this project in Rust
Expand Down
1 change: 1 addition & 0 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ All the endpoints will respond with `200` if successful or:
- `GET /profile/{user_id}/following` Retrieve a list of profiles that the specified user is following

### Instance
- `GET /instance` Returns a json model that contains basic information about the current session; `device_id`, `device_name`,`device_type`, `country_code`, and `preferred_locale`
- `POST /instance/terminate` Terminates the API server.
- `POST /instance/close` Closes the current session (and player).

Expand Down
4 changes: 2 additions & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>xyz.gianlu.librespot</groupId>
<artifactId>librespot-java</artifactId>
<version>1.6.1-SNAPSHOT</version>
<version>1.6.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -99,7 +99,7 @@
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>2.2.7.Final</version>
<version>2.2.14.Final</version>
</dependency>
</dependencies>
</project>
5 changes: 4 additions & 1 deletion api/src/main/java/xyz/gianlu/librespot/api/ApiServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class ApiServer {
private Undertow undertow = null;

public ApiServer(int port, @NotNull String host, @NotNull SessionWrapper wrapper) {
AbsSessionHandler instanceHandler = InstanceHandler.forSession(this, wrapper);

this.port = port;
this.host = host;
this.wrapper = wrapper;
Expand All @@ -45,7 +47,8 @@ public ApiServer(int port, @NotNull String host, @NotNull SessionWrapper wrapper
.post("/token/{scope}", new TokensHandler(wrapper))
.post("/profile/{user_id}/{action}", new ProfileHandler(wrapper))
.post("/web-api/{endpoint}", new WebApiHandler(wrapper))
.post("/instance/{action}", InstanceHandler.forSession(this, wrapper))
.get("/instance", instanceHandler)
.post("/instance/{action}", instanceHandler)
.post("/discovery/{action}", new DiscoveryHandler())
.get("/events", events)
.setFallbackHandler(new PathHandler(ResponseCodeHandler.HANDLE_404)
Expand Down
5 changes: 5 additions & 0 deletions api/src/main/java/xyz/gianlu/librespot/api/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ public static void internalError(@NotNull HttpServerExchange exchange, @NotNull
exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR);
exchange.getResponseSender().send(String.format(INTERNAL_ERROR_BODY, reason));
}

public static void methodNotAllowed(@NotNull HttpServerExchange exchange) {
exchange.setStatusCode(StatusCodes.METHOD_NOT_ALLOWED);
exchange.getResponseSender().send(StatusCodes.METHOD_NOT_ALLOWED_STRING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,36 @@
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.gianlu.librespot.ZeroconfServer;
import xyz.gianlu.librespot.api.Utils;
import xyz.gianlu.zeroconf.DiscoveredService;
import xyz.gianlu.zeroconf.Zeroconf;

import java.io.IOException;
import java.util.Deque;
import java.util.Map;

/**
* @author devgianlu
*/
public final class DiscoveryHandler implements HttpHandler {
private final Zeroconf zeroconf;
private static final Logger LOGGER = LoggerFactory.getLogger(DiscoveryHandler.class);
private final Zeroconf.DiscoveredServices discoverer;

public DiscoveryHandler() {
zeroconf = new Zeroconf();
Zeroconf zeroconf = new Zeroconf()
.setUseIpv4(true)
.setUseIpv6(false);

try {
zeroconf.addAllNetworkInterfaces();
} catch (IOException ex) {
LOGGER.error("Failed adding network interfaces for Zeroconf.", ex);
}

discoverer = zeroconf.discover(ZeroconfServer.SERVICE, "tcp", ".local");
}

@Override
Expand All @@ -57,7 +71,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
switch (action) {
case "list":
JsonArray array = new JsonArray();
for (DiscoveredService service : zeroconf.discover(ZeroconfServer.SERVICE, "tcp", ".local")) {
for (DiscoveredService service : discoverer.getServices()) {
JsonObject obj = new JsonObject();
obj.addProperty("name", service.name);
obj.addProperty("target", service.target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ public void onContextChanged(@NotNull Player player, @NotNull String newUri) {
}

@Override
public void onTrackChanged(@NotNull Player player, @NotNull PlayableId id, @Nullable MetadataWrapper metadata) {
public void onTrackChanged(@NotNull Player player, @NotNull PlayableId id, @Nullable MetadataWrapper metadata, boolean userInitiated) {
JsonObject obj = new JsonObject();
obj.addProperty("event", "trackChanged");
obj.addProperty("userInitiated", userInitiated);
obj.addProperty("uri", id.toSpotifyUri());
if (metadata != null) {
if (metadata.track != null) obj.add("track", ProtobufToJson.convert(metadata.track));
Expand Down Expand Up @@ -138,6 +139,14 @@ public void onPanicState(@NotNull Player player) {
dispatch(obj);
}

@Override
public void onStartedLoading(@NotNull Player player) {
}

@Override
public void onFinishedLoading(@NotNull Player player) {
}

@Override
public void onSessionCleared(@NotNull Session old) {
old.removeReconnectionListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package xyz.gianlu.librespot.api.handlers;

import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.gianlu.librespot.api.ApiServer;
Expand Down Expand Up @@ -55,6 +58,16 @@ private static String getAction(@NotNull HttpServerExchange exchange) throws IOE
return action;
}

private static String getInstanceInfo(@NotNull Session session) throws JsonSyntaxException {
JsonObject infoObj = new JsonObject();
infoObj.addProperty("device_id", session.deviceId());
infoObj.addProperty("device_name", session.deviceName());
infoObj.addProperty("device_type", session.deviceType().toString());
infoObj.addProperty("country_code", session.countryCode());
infoObj.addProperty("preferred_locale", session.preferredLocale());
return infoObj.toString();
}

private static class SessionHandler extends AbsSessionHandler {
private final ApiServer server;

Expand All @@ -71,19 +84,31 @@ protected void handleRequest(@NotNull HttpServerExchange exchange, @NotNull Sess
return;
}

String action = getAction(exchange);
if (action == null) return;

switch (action) {
case "terminate":
exchange.endExchange();
new Thread(server::stop).start();
break;
case "close":
session.close();
String requestMethod = exchange.getRequestMethod().toString();
switch(requestMethod) {
case "GET":
String info = getInstanceInfo(session);
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json");
exchange.getResponseSender().send(info);
return;
case "POST":
String action = getAction(exchange);
if (action == null) return;

switch (action) {
case "terminate":
exchange.endExchange();
new Thread(server::stop).start();
break;
case "close":
session.close();
break;
default:
Utils.methodNotAllowed(exchange);
break;
}
break;
default:
Utils.invalidParameter(exchange, "action");
break;
}
}
Expand All @@ -105,20 +130,31 @@ protected void handleRequest(@NotNull HttpServerExchange exchange, @NotNull Sess
return;
}

String action = getAction(exchange);
if (action == null) return;

switch (action) {
case "terminate":
exchange.endExchange();
new Thread(server::stop).start();
break;
case "close":
player.close();
session.close();
String requestMethod = exchange.getRequestMethod().toString();
switch(requestMethod) {
case "GET":
String info = getInstanceInfo(session);
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json");
exchange.getResponseSender().send(info);
return;
case "POST":
String action = getAction(exchange);
if (action == null) return;

switch (action) {
case "terminate":
exchange.endExchange();
new Thread(server::stop).start();
break;
case "close":
session.close();
break;
default:
Utils.methodNotAllowed(exchange);
break;
}
break;
default:
Utils.invalidParameter(exchange, "action");
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion dacp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>xyz.gianlu.librespot</groupId>
<artifactId>librespot-java</artifactId>
<version>1.6.1-SNAPSHOT</version>
<version>1.6.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion decoder-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>xyz.gianlu.librespot</groupId>
<artifactId>librespot-java</artifactId>
<version>1.6.1-SNAPSHOT</version>
<version>1.6.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
6 changes: 3 additions & 3 deletions lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>xyz.gianlu.librespot</groupId>
<artifactId>librespot-java</artifactId>
<version>1.6.1-SNAPSHOT</version>
<version>1.6.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -116,14 +116,14 @@
<dependency>
<groupId>xyz.gianlu.zeroconf</groupId>
<artifactId>zeroconf</artifactId>
<version>1.2.1</version>
<version>1.3.2</version>
</dependency>

<!-- HTTP -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.1</version>
<version>4.9.3</version>
</dependency>

<!-- Commons Net (NTP) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

import static xyz.gianlu.librespot.audio.storage.ChannelManager.CHUNK_SIZE;
Expand All @@ -55,7 +54,7 @@ public class CacheManager implements Closeable {
private static final int HEADER_HASH = 253;
private final File parent;
private final CacheJournal journal;
private final Map<String, Handler> fileHandlers = new ConcurrentHashMap<>();
private final Map<String, Handler> fileHandlers = Collections.synchronizedMap(new HashMap<>());

public CacheManager(@NotNull Session.Configuration conf) throws IOException {
if (!conf.cacheEnabled) {
Expand Down
21 changes: 15 additions & 6 deletions lib/src/main/java/xyz/gianlu/librespot/common/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,23 @@ public static String artistsToString(List<Metadata.Artist> artists) {
}

@NotNull
public static String toBase64(@NotNull byte[] bytes, boolean padding) {
public static String toBase64(@NotNull byte[] bytes, boolean url, boolean padding) {
byte[] encodedBytes;
try {
Class<?> clazz = Class.forName(JAVA_UTIL_BASE_64);
final Method getEncoder = clazz.getDeclaredMethod("getEncoder");

Method getEncoder;
if (url) getEncoder = clazz.getDeclaredMethod("getUrlEncoder");
else getEncoder = clazz.getDeclaredMethod("getEncoder");

Class<?> encoderClazz = Class.forName("java.util.Base64$Encoder");
Object encoder = getEncoder.invoke(null);
final Method withoutPadding = encoderClazz.getDeclaredMethod("withoutPadding");
if (!padding)

if (!padding) {
Method withoutPadding = encoderClazz.getDeclaredMethod("withoutPadding");
encoder = withoutPadding.invoke(encoder);
}

final Method encode = encoderClazz.getDeclaredMethod("encode", byte[].class);
encodedBytes = (byte[]) encode.invoke(encoder, bytes);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
Expand All @@ -334,6 +341,8 @@ public static String toBase64(@NotNull byte[] bytes, boolean padding) {
int flags = 2; // Base64.NO_WRAP
if (!padding)
flags |= 1; // Base64.NO_PADDING
if (url)
flags |= 8; // Base64.URL_SAFE
encodedBytes = (byte[]) encode.invoke(null, bytes, flags); // Base64.NO_WRAP | Base64.NO_PADDING
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored2) {
throw new NoClassDefFoundError("Base64 not available");
Expand All @@ -345,12 +354,12 @@ public static String toBase64(@NotNull byte[] bytes, boolean padding) {

@NotNull
public static String toBase64NoPadding(@NotNull byte[] bytes) {
return toBase64(bytes, false);
return toBase64(bytes, false, false);
}

@NotNull
public static String toBase64(@NotNull byte[] bytes) {
return toBase64(bytes, true);
return toBase64(bytes,false, true);
}

@NotNull
Expand Down
Loading