Skip to content

Commit

Permalink
Issue/5 (#6)
Browse files Browse the repository at this point in the history
* Added getArtistInfo2

* Added getArtistInfo

* Added getAlbumInfo,getAlbumInfo2

* Added setRating

* Added getAlbumList,getAlbumList2

* Added license header
  • Loading branch information
calne-ca authored Aug 23, 2024
1 parent a14888e commit e920d7a
Show file tree
Hide file tree
Showing 40 changed files with 1,143 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ public interface AnnotationClient {

@RequestLine("GET /rest/unstar?artistId={artistId}")
SubsonicResponse unstarByArtistId(@Param("artistId") String artistId);

@RequestLine("GET /rest/setRating?id={id}&rating={rating}")
SubsonicResponse setRating(@Param("id") String id, @Param("rating") int rating);
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,11 @@ public void unstarArtistID3(String artistId){
var response = annotationClient.unstarByArtistId(artistId);
handleError(response);
}

public void setRating(String id, int rating){
log.debug("Setting rating '{}' for item with id '{}'.", id, rating);

var response = annotationClient.setRating(id, rating);
handleError(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2020 Joscha Düringer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.beardbot.subsonic.client.api.browsing;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import net.beardbot.subsonic.client.base.ApiParams;

import java.util.List;
import java.util.Map;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
class ArtistInfoParams extends ApiParams {
public static ArtistInfoParams create(){
return new ArtistInfoParams();
}

public ArtistInfoParams count(int count) {
setParam("count", String.valueOf(count));
return this;
}

public ArtistInfoParams includeNotPresent(boolean includeNotPresent) {
setParam("includeNotPresent", String.valueOf(includeNotPresent));
return this;
}

@Override
protected Map<String, List<String>> defaultParams() {
return Map.of("count", List.of("20"),
"includeNotPresent", List.of("false"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ public interface BrowsingClient {

@RequestLine("GET /rest/getSong?id={id}")
SubsonicResponse getSong(@Param("id") String id);

@RequestLine("GET /rest/getArtistInfo")
SubsonicResponse getArtistInfo(@QueryMap Map<String,List<String>> params);

@RequestLine("GET /rest/getArtistInfo2")
SubsonicResponse getArtistInfo2(@QueryMap Map<String,List<String>> params);

@RequestLine("GET /rest/getAlbumInfo?id={id}")
SubsonicResponse getAlbumInfo(@Param("id") String id);

@RequestLine("GET /rest/getAlbumInfo2?id={id}")
SubsonicResponse getAlbumInfo2(@Param("id") String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,54 @@ public Child getSong(String id){

return response.getSong();
}

public ArtistInfo getArtistInfo(String id){
return getArtistInfo(id, ArtistInfoParams.create().count(20).includeNotPresent(false));
}

public ArtistInfo getArtistInfo(String id, ArtistInfoParams artistInfoParams){
log.debug("Fetching artist info for id '{}' and params {}.", id, artistInfoParams.getParamMapForLogging());

var params = artistInfoParams.getParamMap();
params.put("id", List.of(id));

var response = browsingClient.getArtistInfo(params);
handleError(response);

return response.getArtistInfo();
}

public ArtistInfo2 getArtistInfo2(String id){
return getArtistInfo2(id, ArtistInfoParams.create().count(20).includeNotPresent(false));
}

public ArtistInfo2 getArtistInfo2(String id, ArtistInfoParams artistInfoParams){
log.debug("Fetching artist info for id '{}' and params {}.", id, artistInfoParams.getParamMapForLogging());

var params = artistInfoParams.getParamMap();
params.put("id", List.of(id));

var response = browsingClient.getArtistInfo2(params);
handleError(response);

return response.getArtistInfo2();
}

public AlbumInfo getAlbumInfo(String id){
log.debug("Fetching album info for id '{}'.", id);

var response = browsingClient.getAlbumInfo(id);
handleError(response);

return response.getAlbumInfo();
}

public AlbumInfo getAlbumInfo2(String id){
log.debug("Fetching album info for id '{}'.", id);

var response = browsingClient.getAlbumInfo2(id);
handleError(response);

return response.getAlbumInfo();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2020 Joscha Düringer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.beardbot.subsonic.client.api.lists;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import net.beardbot.subsonic.client.base.ApiParams;

import java.util.List;
import java.util.Map;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
class AlbumListParams extends ApiParams {
public static AlbumListParams create(){
return new AlbumListParams();
}

public AlbumListParams type(AlbumListType type) {
setParam("type", type.getValue());
return this;
}

public AlbumListParams size(int size) {
setParam("size", String.valueOf(size));
return this;
}

public AlbumListParams offset(int offset) {
setParam("offset", String.valueOf(offset));
return this;
}

public AlbumListParams fromYear(int fromYear) {
setParam("fromYear", String.valueOf(fromYear));
return this;
}

public AlbumListParams toYear(int toYear) {
setParam("toYear", String.valueOf(toYear));
return this;
}

public AlbumListParams genre(String genre) {
setParam("genre", genre);
return this;
}

public AlbumListParams musicFolderId(int musicFolderId) {
setParam("musicFolderId", String.valueOf(musicFolderId));
return this;
}

@Override
protected Map<String, List<String>> defaultParams() {
return Map.of(
"type", List.of(AlbumListType.RANDOM.getValue()),
"size", List.of("10"),
"offset", List.of("0"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2020 Joscha Düringer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.beardbot.subsonic.client.api.lists;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public enum AlbumListType {
RANDOM("random"),
NEWEST("newest"),
HIGHEST("highest"),
FREQUENT("frequent"),
RECENT("recent"),
ALPHABETICAL_BY_NAME("alphabeticalByName"),
ALPHABETICAL_BY_ARTIST("alphabeticalByArtist"),
STARRED("starred"),
BY_YEAR("byYear"),
BY_GENRE("byGenre");
private final String value;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
*/
package net.beardbot.subsonic.client.api.lists;

import feign.QueryMap;
import feign.RequestLine;
import org.subsonic.restapi.SubsonicResponse;

import java.util.List;
import java.util.Map;

public interface ListsClient {
@RequestLine("GET /rest/getNowPlaying")
SubsonicResponse getNowPlaying();
Expand All @@ -28,4 +32,10 @@ public interface ListsClient {

@RequestLine("GET /rest/getStarred2")
SubsonicResponse getStarred2();

@RequestLine("GET /rest/getAlbumList")
SubsonicResponse getAlbumList(@QueryMap Map<String, List<String>> params);

@RequestLine("GET /rest/getAlbumList2")
SubsonicResponse getAlbumList2(@QueryMap Map<String,List<String>> params);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
import lombok.extern.slf4j.Slf4j;
import net.beardbot.subsonic.client.Subsonic;
import net.beardbot.subsonic.client.base.SubsonicClient;
import org.subsonic.restapi.NowPlayingEntry;
import org.subsonic.restapi.Starred;
import org.subsonic.restapi.Starred2;
import org.subsonic.restapi.*;

import java.util.List;

Expand Down Expand Up @@ -64,4 +62,30 @@ public Starred2 getStarred2(){

return response.getStarred2();
}

public AlbumList getAlbumList(){
return getAlbumList(AlbumListParams.create());
}

public AlbumList getAlbumList(AlbumListParams albumListParams){
log.debug("Fetching album list with params {}", albumListParams.getParamMapForLogging());

var response = listsClient.getAlbumList(albumListParams.getParamMap());
handleError(response);

return response.getAlbumList();
}

public AlbumList2 getAlbumList2(){
return getAlbumList2(AlbumListParams.create());
}

public AlbumList2 getAlbumList2(AlbumListParams albumListParams){
log.debug("Fetching album list with params {}", albumListParams.getParamMapForLogging());

var response = listsClient.getAlbumList2(albumListParams.getParamMap());
handleError(response);

return response.getAlbumList2();
}
}
15 changes: 14 additions & 1 deletion src/main/java/net/beardbot/subsonic/client/base/ApiParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,25 @@ protected void setSecretParam(String name, String value){
}

public Map<String,List<String>> getParamMap(){
return new HashMap<>(paramMap);
var params = new HashMap<>(paramMap);
var defaultParams = defaultParams();

for (String key : defaultParams.keySet()) {
if(!params.containsKey(key)) {
params.put(key, defaultParams.get(key));
}
}

return params;
}

public Map<String,List<String>> getParamMapForLogging(){
var params = getParamMap();
secretParamNames.forEach(s->params.put(s,Collections.singletonList("*****")));
return params;
}

protected Map<String,List<String>> defaultParams() {
return Collections.emptyMap();
}
}
Loading

0 comments on commit e920d7a

Please sign in to comment.