First API implementation

This commit is contained in:
CappielloAntonio 2021-07-24 19:57:53 +02:00
parent 24ca36197c
commit 768ec981f3
11 changed files with 604 additions and 45 deletions

View file

@ -0,0 +1,81 @@
package com.cappielloantonio.play.subsonic.api.albumsonglist;
import android.util.Log;
import com.cappielloantonio.play.subsonic.Subsonic;
import com.cappielloantonio.play.subsonic.api.browsing.BrowsingService;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class AlbumSongListClient {
private static final String TAG = "BrowsingClient";
private Subsonic subsonic;
private Retrofit retrofit;
private AlbumSongListService albumSongListService;
public AlbumSongListClient(Subsonic subsonic) {
this.subsonic = subsonic;
this.retrofit = new Retrofit.Builder()
.baseUrl(subsonic.getUrl())
.addConverterFactory(GsonConverterFactory.create())
.client(getOkHttpClient())
.build();
this.albumSongListService = retrofit.create(AlbumSongListService.class);
}
public Call<SubsonicResponse> getAlbumList() {
Log.d(TAG, "getAlbumList()");
return albumSongListService.getAlbumList(subsonic.getParams());
}
public Call<SubsonicResponse> getAlbumList2() {
Log.d(TAG, "getAlbumList2()");
return albumSongListService.getAlbumList2(subsonic.getParams());
}
public Call<SubsonicResponse> getRandomSongs(int size) {
Log.d(TAG, "getRandomSongs()");
return albumSongListService.getRandomSongs(subsonic.getParams(), size);
}
public Call<SubsonicResponse> getSongsByGenre(String genre, int count) {
Log.d(TAG, "getSongsByGenre()");
return albumSongListService.getSongsByGenre(subsonic.getParams(), genre, count);
}
public Call<SubsonicResponse> getNowPlaying() {
Log.d(TAG, "getNowPlaying()");
return albumSongListService.getNowPlaying(subsonic.getParams());
}
public Call<SubsonicResponse> getStarred() {
Log.d(TAG, "getStarred()");
return albumSongListService.getStarred(subsonic.getParams());
}
public Call<SubsonicResponse> getStarred2() {
Log.d(TAG, "getStarred2()");
return albumSongListService.getStarred2(subsonic.getParams());
}
private OkHttpClient getOkHttpClient() {
return new OkHttpClient.Builder()
.addInterceptor(getHttpLoggingInterceptor())
.build();
}
private HttpLoggingInterceptor getHttpLoggingInterceptor() {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
return loggingInterceptor;
}
}

View file

@ -0,0 +1,32 @@
package com.cappielloantonio.play.subsonic.api.albumsonglist;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import java.util.Map;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;
public interface AlbumSongListService {
@GET("getAlbumList?type=random")
Call<SubsonicResponse> getAlbumList(@QueryMap Map<String, String> params);
@GET("getAlbumList2?type=random")
Call<SubsonicResponse> getAlbumList2(@QueryMap Map<String, String> params);
@GET("getRandomSongs?size={size}")
Call<SubsonicResponse> getRandomSongs(@QueryMap Map<String, String> params, int size);
@GET("getSongsByGenre?genre={genre}?count={count}")
Call<SubsonicResponse> getSongsByGenre(@QueryMap Map<String, String> params, String genre, int count);
@GET("getNowPlaying")
Call<SubsonicResponse> getNowPlaying(@QueryMap Map<String, String> params);
@GET("getStarred")
Call<SubsonicResponse> getStarred(@QueryMap Map<String, String> params);
@GET("getStarred2")
Call<SubsonicResponse> getStarred2(@QueryMap Map<String, String> params);
}

View file

@ -0,0 +1,130 @@
package com.cappielloantonio.play.subsonic.api.browsing;
import android.util.Log;
import com.cappielloantonio.play.subsonic.Subsonic;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class BrowsingClient {
private static final String TAG = "BrowsingClient";
private Subsonic subsonic;
private Retrofit retrofit;
private BrowsingService browsingService;
public BrowsingClient(Subsonic subsonic) {
this.subsonic = subsonic;
this.retrofit = new Retrofit.Builder()
.baseUrl(subsonic.getUrl())
.addConverterFactory(GsonConverterFactory.create())
.client(getOkHttpClient())
.build();
this.browsingService = retrofit.create(BrowsingService.class);
}
public Call<SubsonicResponse> getMusicFolders() {
Log.d(TAG, "getMusicFolders()");
return browsingService.getMusicFolders(subsonic.getParams());
}
public Call<SubsonicResponse> getIndexes() {
Log.d(TAG, "getIndexes()");
return browsingService.getIndexes(subsonic.getParams());
}
public Call<SubsonicResponse> getMusicDirectory(String id) {
Log.d(TAG, "getMusicDirectory()");
return browsingService.getMusicDirectory(subsonic.getParams(), id);
}
public Call<SubsonicResponse> getGenres() {
Log.d(TAG, "getGenres()");
return browsingService.getGenres(subsonic.getParams());
}
public Call<SubsonicResponse> getArtists() {
Log.d(TAG, "getArtists()");
return browsingService.getArtists(subsonic.getParams());
}
public Call<SubsonicResponse> getArtist(String id) {
Log.d(TAG, "getArtist()");
return browsingService.getArtist(subsonic.getParams(), id);
}
public Call<SubsonicResponse> getAlbum(String id) {
Log.d(TAG, "getAlbum()");
return browsingService.getAlbum(subsonic.getParams(), id);
}
public Call<SubsonicResponse> getSong(String id) {
Log.d(TAG, "getSong()");
return browsingService.getSong(subsonic.getParams(), id);
}
public Call<SubsonicResponse> getVideos() {
Log.d(TAG, "getVideos()");
return browsingService.getVideos(subsonic.getParams());
}
public Call<SubsonicResponse> getVideoInfo(String id) {
Log.d(TAG, "getVideoInfo()");
return browsingService.getVideoInfo(subsonic.getParams(), id);
}
public Call<SubsonicResponse> getArtistInfo(String id) {
Log.d(TAG, "getArtistInfo()");
return browsingService.getArtistInfo(subsonic.getParams(), id);
}
public Call<SubsonicResponse> getArtistInfo2(String id) {
Log.d(TAG, "getArtistInfo2()");
return browsingService.getArtistInfo2(subsonic.getParams(), id);
}
public Call<SubsonicResponse> getAlbumInfo(String id) {
Log.d(TAG, "getAlbumInfo()");
return browsingService.getAlbumInfo(subsonic.getParams(), id);
}
public Call<SubsonicResponse> getAlbumInfo2(String id) {
Log.d(TAG, "getAlbumInfo2()");
return browsingService.getAlbumInfo2(subsonic.getParams(), id);
}
public Call<SubsonicResponse> getSimilarSongs(String id, int count) {
Log.d(TAG, "getSimilarSongs()");
return browsingService.getSimilarSongs(subsonic.getParams(), id, count);
}
public Call<SubsonicResponse> getSimilarSongs2(String id, int limit) {
Log.d(TAG, "getSimilarSongs2()");
return browsingService.getSimilarSongs2(subsonic.getParams(), id, limit);
}
public Call<SubsonicResponse> getTopSongs(String id, int count) {
Log.d(TAG, "getTopSongs()");
return browsingService.getTopSongs(subsonic.getParams(), id, count);
}
private OkHttpClient getOkHttpClient() {
return new OkHttpClient.Builder()
.addInterceptor(getHttpLoggingInterceptor())
.build();
}
private HttpLoggingInterceptor getHttpLoggingInterceptor() {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
return loggingInterceptor;
}
}

View file

@ -0,0 +1,62 @@
package com.cappielloantonio.play.subsonic.api.browsing;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import java.util.Map;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;
public interface BrowsingService {
@GET("getMusicFolders")
Call<SubsonicResponse> getMusicFolders(@QueryMap Map<String, String> params);
@GET("getIndexes")
Call<SubsonicResponse> getIndexes(@QueryMap Map<String, String> params);
@GET("getMusicDirectory?id={id}")
Call<SubsonicResponse> getMusicDirectory(@QueryMap Map<String, String> params, String id);
@GET("getGenres")
Call<SubsonicResponse> getGenres(@QueryMap Map<String, String> params);
@GET("getArtists")
Call<SubsonicResponse> getArtists(@QueryMap Map<String, String> params);
@GET("getArtist?id={id}")
Call<SubsonicResponse> getArtist(@QueryMap Map<String, String> params, String id);
@GET("getAlbum?id={id}")
Call<SubsonicResponse> getAlbum(@QueryMap Map<String, String> params, String id);
@GET("getSong?id={id}")
Call<SubsonicResponse> getSong(@QueryMap Map<String, String> params, String id);
@GET("getVideos")
Call<SubsonicResponse> getVideos(@QueryMap Map<String, String> params);
@GET("getVideoInfo?id={id}")
Call<SubsonicResponse> getVideoInfo(@QueryMap Map<String, String> params, String id);
@GET("getArtistInfo?id={id}")
Call<SubsonicResponse> getArtistInfo(@QueryMap Map<String, String> params, String id);
@GET("getArtistInfo2?id={id}")
Call<SubsonicResponse> getArtistInfo2(@QueryMap Map<String, String> params, String id);
@GET("getAlbumInfo?id={id}")
Call<SubsonicResponse> getAlbumInfo(@QueryMap Map<String, String> params, String id);
@GET("getAlbumInfo2?id={id}")
Call<SubsonicResponse> getAlbumInfo2(@QueryMap Map<String, String> params, String id);
@GET("getSimilarSongs?id={id}?count={count}")
Call<SubsonicResponse> getSimilarSongs(@QueryMap Map<String, String> params, String id, int count);
@GET("getSimilarSongs2?id={id}?count={count}")
Call<SubsonicResponse> getSimilarSongs2(@QueryMap Map<String, String> params, String id, int count);
@GET("getTopSongs?id={id}?count={count}")
Call<SubsonicResponse> getTopSongs(@QueryMap Map<String, String> params, String id, int count);
}

View file

@ -0,0 +1,56 @@
package com.cappielloantonio.play.subsonic.api.mediaretrieval;
import android.util.Log;
import com.cappielloantonio.play.subsonic.Subsonic;
import com.cappielloantonio.play.subsonic.api.playlist.PlaylistService;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class MediaRetrievalClient {
private static final String TAG = "BrowsingClient";
private Subsonic subsonic;
private Retrofit retrofit;
private MediaRetrievalService mediaRetrievalService;
public MediaRetrievalClient(Subsonic subsonic) {
this.subsonic = subsonic;
this.retrofit = new Retrofit.Builder()
.baseUrl(subsonic.getUrl())
.addConverterFactory(GsonConverterFactory.create())
.client(getOkHttpClient())
.build();
this.mediaRetrievalService = retrofit.create(MediaRetrievalService.class);
}
public Call<SubsonicResponse> stream(String id, int maxBitRate, String format) {
Log.d(TAG, "stream()");
return mediaRetrievalService.stream(subsonic.getParams(), id, maxBitRate, format);
}
public Call<SubsonicResponse> download(String id) {
Log.d(TAG, "download()");
return mediaRetrievalService.download(subsonic.getParams(), id);
}
private OkHttpClient getOkHttpClient() {
return new OkHttpClient.Builder()
.addInterceptor(getHttpLoggingInterceptor())
.build();
}
private HttpLoggingInterceptor getHttpLoggingInterceptor() {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
return loggingInterceptor;
}
}

View file

@ -0,0 +1,17 @@
package com.cappielloantonio.play.subsonic.api.mediaretrieval;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import java.util.Map;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;
public interface MediaRetrievalService {
@GET("stream?id={id}?maxBitRate={maxBitRate}?format={format}")
Call<SubsonicResponse> stream(@QueryMap Map<String, String> params, String id, int maxBitRate, String format);
@GET("download?id={id}")
Call<SubsonicResponse> download(@QueryMap Map<String, String> params, String id);
}

View file

@ -0,0 +1,56 @@
package com.cappielloantonio.play.subsonic.api.playlist;
import android.util.Log;
import com.cappielloantonio.play.subsonic.Subsonic;
import com.cappielloantonio.play.subsonic.api.albumsonglist.AlbumSongListService;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class PlaylistClient {
private static final String TAG = "BrowsingClient";
private Subsonic subsonic;
private Retrofit retrofit;
private PlaylistService playlistService;
public PlaylistClient(Subsonic subsonic) {
this.subsonic = subsonic;
this.retrofit = new Retrofit.Builder()
.baseUrl(subsonic.getUrl())
.addConverterFactory(GsonConverterFactory.create())
.client(getOkHttpClient())
.build();
this.playlistService = retrofit.create(PlaylistService.class);
}
public Call<SubsonicResponse> getPlaylists() {
Log.d(TAG, "getPlaylists()");
return playlistService.getPlaylists(subsonic.getParams());
}
public Call<SubsonicResponse> getPlaylist(String id) {
Log.d(TAG, "getPlaylist()");
return playlistService.getPlaylist(subsonic.getParams(), id);
}
private OkHttpClient getOkHttpClient() {
return new OkHttpClient.Builder()
.addInterceptor(getHttpLoggingInterceptor())
.build();
}
private HttpLoggingInterceptor getHttpLoggingInterceptor() {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
return loggingInterceptor;
}
}

View file

@ -0,0 +1,17 @@
package com.cappielloantonio.play.subsonic.api.playlist;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import java.util.Map;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;
public interface PlaylistService {
@GET("getPlaylists")
Call<SubsonicResponse> getPlaylists(@QueryMap Map<String, String> params);
@GET("getPlaylist?id={id}")
Call<SubsonicResponse> getPlaylist(@QueryMap Map<String, String> params, String id);
}

View file

@ -0,0 +1,55 @@
package com.cappielloantonio.play.subsonic.api.searching;
import android.util.Log;
import com.cappielloantonio.play.subsonic.Subsonic;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class SearchingClient {
private static final String TAG = "BrowsingClient";
private Subsonic subsonic;
private Retrofit retrofit;
private SearchingService searchingService;
public SearchingClient(Subsonic subsonic) {
this.subsonic = subsonic;
this.retrofit = new Retrofit.Builder()
.baseUrl(subsonic.getUrl())
.addConverterFactory(GsonConverterFactory.create())
.client(getOkHttpClient())
.build();
this.searchingService = retrofit.create(SearchingService.class);
}
public Call<SubsonicResponse> search2(String query) {
Log.d(TAG, "search2()");
return searchingService.search2(subsonic.getParams(), query);
}
public Call<SubsonicResponse> search3(String query) {
Log.d(TAG, "search3()");
return searchingService.search3(subsonic.getParams(), query);
}
private OkHttpClient getOkHttpClient() {
return new OkHttpClient.Builder()
.addInterceptor(getHttpLoggingInterceptor())
.build();
}
private HttpLoggingInterceptor getHttpLoggingInterceptor() {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
return loggingInterceptor;
}
}

View file

@ -0,0 +1,17 @@
package com.cappielloantonio.play.subsonic.api.searching;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import java.util.Map;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;
public interface SearchingService {
@GET("search2?query={query}")
Call<SubsonicResponse> search2(@QueryMap Map<String, String> params, String query);
@GET("search3?query={query}")
Call<SubsonicResponse> search3(@QueryMap Map<String, String> params, String query);
}

View file

@ -1,52 +1,67 @@
package com.cappielloantonio.play.subsonic.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class SubsonicResponse {
protected Error error;
protected ScanStatus scanStatus;
protected TopSongs topSongs;
protected SimilarSongs2 similarSongs2;
protected SimilarSongs similarSongs;
protected ArtistInfo2 artistInfo2;
protected ArtistInfo artistInfo;
protected AlbumInfo albumInfo;
protected Starred2 starred2;
protected Starred starred;
protected Shares shares;
protected PlayQueue playQueue;
protected Bookmarks bookmarks;
protected InternetRadioStations internetRadioStations;
protected NewestPodcasts newestPodcasts;
protected Podcasts podcasts;
protected Lyrics lyrics;
protected Songs songsByGenre;
protected Songs randomSongs;
protected AlbumList2 albumList2;
protected AlbumList albumList;
protected ChatMessages chatMessages;
protected User user;
protected Users users;
protected License license;
protected JukeboxPlaylist jukeboxPlaylist;
protected JukeboxStatus jukeboxStatus;
protected PlaylistWithSongs playlist;
protected Playlists playlists;
protected SearchResult3 searchResult3;
protected SearchResult2 searchResult2;
protected SearchResult searchResult;
protected NowPlaying nowPlaying;
protected VideoInfo videoInfo;
protected Videos videos;
protected Child song;
protected AlbumWithSongsID3 album;
protected ArtistWithAlbumsID3 artist;
protected ArtistsID3 artists;
protected Genres genres;
protected Directory directory;
protected Indexes indexes;
protected MusicFolders musicFolders;
protected ResponseStatus status;
protected String version;
@SerializedName("error")
@Expose
public Error error;
public ScanStatus scanStatus;
public TopSongs topSongs;
public SimilarSongs2 similarSongs2;
public SimilarSongs similarSongs;
public ArtistInfo2 artistInfo2;
public ArtistInfo artistInfo;
public AlbumInfo albumInfo;
public Starred2 starred2;
public Starred starred;
public Shares shares;
public PlayQueue playQueue;
public Bookmarks bookmarks;
public InternetRadioStations internetRadioStations;
public NewestPodcasts newestPodcasts;
public Podcasts podcasts;
public Lyrics lyrics;
public Songs songsByGenre;
public Songs randomSongs;
public AlbumList2 albumList2;
public AlbumList albumList;
public ChatMessages chatMessages;
public User user;
public Users users;
public License license;
public JukeboxPlaylist jukeboxPlaylist;
public JukeboxStatus jukeboxStatus;
public PlaylistWithSongs playlist;
public Playlists playlists;
public SearchResult3 searchResult3;
public SearchResult2 searchResult2;
public SearchResult searchResult;
public NowPlaying nowPlaying;
public VideoInfo videoInfo;
public Videos videos;
public Child song;
public AlbumWithSongsID3 album;
public ArtistWithAlbumsID3 artist;
public ArtistsID3 artists;
public Genres genres;
public Directory directory;
public Indexes indexes;
public MusicFolders musicFolders;
@SerializedName("status")
@Expose
public ResponseStatus status;
@SerializedName("version")
@Expose
public String version;
@SerializedName("type")
@Expose
public String type;
/**
* Gets the value of the error property.
@ -947,4 +962,25 @@ public class SubsonicResponse {
public void setVersion(String value) {
this.version = value;
}
/**
* Gets the value of the type property.
*
* @return possible object is
* {@link String }
*/
public String getType() {
return type;
}
/**
* Sets the value of the type property.
*
* @param value allowed object is
* {@link String }
*/
public void setType(String value) {
this.type = value;
}
}