Skip to content

Commit

Permalink
Added media().getCoverArtUrl() method
Browse files Browse the repository at this point in the history
  • Loading branch information
calne-ca committed Sep 26, 2021
1 parent 781869c commit 2923027
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.3.0] - 2021-09-26

### Added

- New method *subsonic.media().getCoverArtUrl(songId)* that returns a URL without reading from it.

## [0.2.0] - 2021-04-08

### Added
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.beardbot</groupId>
<artifactId>subsonic-client</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.0-SNAPSHOT</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Java client for the Subsonic API</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,20 @@ public InputStream getCoverArt(String id){

@SneakyThrows
public InputStream getCoverArt(String id, CoverArtParams coverArtParams){
var params = coverArtParams.getParamMap();
params.put("id",Collections.singletonList(id));
var url = getCoverArtUrl(id, coverArtParams);
log.debug("Fetching cover art with params '{}'.", coverArtParams);
return safeOpenStream(url);
}

log.debug("Downloading cover art with params '{}'.", params);
public URL getCoverArtUrl(String id){
return getCoverArtUrl(id, CoverArtParams.create());
}

var url = subsonic.createUrl("getCoverArt", params);
public URL getCoverArtUrl(String id, CoverArtParams coverArtParams){
var params = coverArtParams.getParamMap();
params.put("id",Collections.singletonList(id));

return safeOpenStream(url);
return subsonic.createUrl("getCoverArt", params);
}

public InputStream getAvatar(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ void download_error(@WiremockResolver.Wiremock WireMockServer server, @WiremockU

@Test
void getCoverArt(@WiremockResolver.Wiremock WireMockServer server, @WiremockUri String uri) {
var inputStream = subsonic(uri).media().getCoverArt("20958");
assertThat(toByteArray(inputStream)).containsSequence(0x4A, 0x46, 0x49, 0x46);
}

@Test
void getCoverArt_withParams(@WiremockResolver.Wiremock WireMockServer server, @WiremockUri String uri) {
var inputStream = subsonic(uri).media().getCoverArt("20959", CoverArtParams.create().size(500));
assertThat(toByteArray(inputStream)).containsSequence(0x4A, 0x46, 0x49, 0x46);
}
Expand All @@ -74,6 +80,19 @@ void getCoverArt_error(@WiremockResolver.Wiremock WireMockServer server, @Wiremo
assertSubsonicError(()->subsonic(uri).media().getCoverArt("999999999999"), subsonicError());
}

@Test
void getCoverArtUrl(@WiremockResolver.Wiremock WireMockServer server, @WiremockUri String uri) throws IOException {
var url = subsonic(uri).media().getCoverArtUrl("20958");
assertThat(toByteArray(url.openStream())).containsSequence(0x4A, 0x46, 0x49, 0x46);
}

@Test
void getCoverArtUrl_withParams(@WiremockResolver.Wiremock WireMockServer server, @WiremockUri String uri) throws IOException {
var url = subsonic(uri).media().getCoverArtUrl("20959", CoverArtParams.create().size(500));
assertThat(url.getQuery()).contains("size=500");
assertThat(toByteArray(url.openStream())).containsSequence(0x4A, 0x46, 0x49, 0x46);
}

@Test
void getAvatar(@WiremockResolver.Wiremock WireMockServer server, @WiremockUri String uri) {
var inputStream = subsonic(uri).media().getAvatar();
Expand Down
5 changes: 1 addition & 4 deletions src/test/resources/mappings/media/getCoverArt.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
"equalTo" : "testClient"
},
"id" : {
"equalTo" : "20959"
},
"size" : {
"equalTo" : "500"
"equalTo" : "20958"
}
}
},
Expand Down
39 changes: 39 additions & 0 deletions src/test/resources/mappings/media/getCoverArt_withParams.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"request": {
"method": "GET",
"urlPath": "/rest/getCoverArt",
"queryParameters" : {
"u" : {
"equalTo" : "testUser"
},
"s" : {
"matches" : "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
},
"t" : {
"matches" : "^[a-f0-9]{32}$"
},
"v" : {
"equalTo" : "1.15.0"
},
"f" : {
"equalTo" : "xml"
},
"c" : {
"equalTo" : "testClient"
},
"id" : {
"equalTo" : "20959"
},
"size" : {
"equalTo" : "500"
}
}
},
"response": {
"status": 200,
"bodyFileName": "media/small.jpg",
"headers": {
"Content-Type": "image/jpeg"
}
}
}

0 comments on commit 2923027

Please sign in to comment.