mirror of
https://github.com/LukeHagar/plexjava.git
synced 2025-12-06 12:37:47 +00:00
1671 lines
70 KiB
Java
1671 lines
70 KiB
Java
/*
|
|
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
*/
|
|
|
|
package dev.plexapi.sdk;
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import dev.plexapi.sdk.models.errors.AddPlaylistContentsBadRequest;
|
|
import dev.plexapi.sdk.models.errors.AddPlaylistContentsUnauthorized;
|
|
import dev.plexapi.sdk.models.errors.ClearPlaylistContentsBadRequest;
|
|
import dev.plexapi.sdk.models.errors.ClearPlaylistContentsUnauthorized;
|
|
import dev.plexapi.sdk.models.errors.CreatePlaylistBadRequest;
|
|
import dev.plexapi.sdk.models.errors.CreatePlaylistUnauthorized;
|
|
import dev.plexapi.sdk.models.errors.DeletePlaylistBadRequest;
|
|
import dev.plexapi.sdk.models.errors.DeletePlaylistUnauthorized;
|
|
import dev.plexapi.sdk.models.errors.GetPlaylistBadRequest;
|
|
import dev.plexapi.sdk.models.errors.GetPlaylistContentsBadRequest;
|
|
import dev.plexapi.sdk.models.errors.GetPlaylistContentsUnauthorized;
|
|
import dev.plexapi.sdk.models.errors.GetPlaylistUnauthorized;
|
|
import dev.plexapi.sdk.models.errors.GetPlaylistsBadRequest;
|
|
import dev.plexapi.sdk.models.errors.GetPlaylistsUnauthorized;
|
|
import dev.plexapi.sdk.models.errors.SDKError;
|
|
import dev.plexapi.sdk.models.errors.UpdatePlaylistBadRequest;
|
|
import dev.plexapi.sdk.models.errors.UpdatePlaylistUnauthorized;
|
|
import dev.plexapi.sdk.models.errors.UploadPlaylistBadRequest;
|
|
import dev.plexapi.sdk.models.errors.UploadPlaylistUnauthorized;
|
|
import dev.plexapi.sdk.models.operations.AddPlaylistContentsRequest;
|
|
import dev.plexapi.sdk.models.operations.AddPlaylistContentsRequestBuilder;
|
|
import dev.plexapi.sdk.models.operations.AddPlaylistContentsResponse;
|
|
import dev.plexapi.sdk.models.operations.AddPlaylistContentsResponseBody;
|
|
import dev.plexapi.sdk.models.operations.ClearPlaylistContentsRequest;
|
|
import dev.plexapi.sdk.models.operations.ClearPlaylistContentsRequestBuilder;
|
|
import dev.plexapi.sdk.models.operations.ClearPlaylistContentsResponse;
|
|
import dev.plexapi.sdk.models.operations.CreatePlaylistRequest;
|
|
import dev.plexapi.sdk.models.operations.CreatePlaylistRequestBuilder;
|
|
import dev.plexapi.sdk.models.operations.CreatePlaylistResponse;
|
|
import dev.plexapi.sdk.models.operations.CreatePlaylistResponseBody;
|
|
import dev.plexapi.sdk.models.operations.DeletePlaylistRequest;
|
|
import dev.plexapi.sdk.models.operations.DeletePlaylistRequestBuilder;
|
|
import dev.plexapi.sdk.models.operations.DeletePlaylistResponse;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistContentsQueryParamType;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistContentsRequest;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistContentsRequestBuilder;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistContentsResponse;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistContentsResponseBody;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistRequest;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistRequestBuilder;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistResponse;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistResponseBody;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistsRequest;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistsRequestBuilder;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistsResponse;
|
|
import dev.plexapi.sdk.models.operations.GetPlaylistsResponseBody;
|
|
import dev.plexapi.sdk.models.operations.PlaylistType;
|
|
import dev.plexapi.sdk.models.operations.QueryParamForce;
|
|
import dev.plexapi.sdk.models.operations.QueryParamSmart;
|
|
import dev.plexapi.sdk.models.operations.SDKMethodInterfaces.*;
|
|
import dev.plexapi.sdk.models.operations.UpdatePlaylistRequest;
|
|
import dev.plexapi.sdk.models.operations.UpdatePlaylistRequestBuilder;
|
|
import dev.plexapi.sdk.models.operations.UpdatePlaylistResponse;
|
|
import dev.plexapi.sdk.models.operations.UploadPlaylistRequest;
|
|
import dev.plexapi.sdk.models.operations.UploadPlaylistRequestBuilder;
|
|
import dev.plexapi.sdk.models.operations.UploadPlaylistResponse;
|
|
import dev.plexapi.sdk.utils.HTTPClient;
|
|
import dev.plexapi.sdk.utils.HTTPRequest;
|
|
import dev.plexapi.sdk.utils.Hook.AfterErrorContextImpl;
|
|
import dev.plexapi.sdk.utils.Hook.AfterSuccessContextImpl;
|
|
import dev.plexapi.sdk.utils.Hook.BeforeRequestContextImpl;
|
|
import dev.plexapi.sdk.utils.Utils;
|
|
import java.io.InputStream;
|
|
import java.lang.Double;
|
|
import java.lang.Exception;
|
|
import java.lang.String;
|
|
import java.net.http.HttpRequest;
|
|
import java.net.http.HttpResponse;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
/**
|
|
* Playlists are ordered collections of media. They can be dumb (just a list of media) or smart (based on a media query, such as "all albums from 2017").
|
|
* They can be organized in (optionally nesting) folders.
|
|
* Retrieving a playlist, or its items, will trigger a refresh of its metadata.
|
|
* This may cause the duration and number of items to change.
|
|
*
|
|
*/
|
|
public class Playlists implements
|
|
MethodCallCreatePlaylist,
|
|
MethodCallGetPlaylists,
|
|
MethodCallGetPlaylist,
|
|
MethodCallDeletePlaylist,
|
|
MethodCallUpdatePlaylist,
|
|
MethodCallGetPlaylistContents,
|
|
MethodCallClearPlaylistContents,
|
|
MethodCallAddPlaylistContents,
|
|
MethodCallUploadPlaylist {
|
|
|
|
private final SDKConfiguration sdkConfiguration;
|
|
|
|
Playlists(SDKConfiguration sdkConfiguration) {
|
|
this.sdkConfiguration = sdkConfiguration;
|
|
}
|
|
|
|
|
|
/**
|
|
* Create a Playlist
|
|
* Create a new playlist. By default the playlist is blank. To create a playlist along with a first item, pass:
|
|
* - `uri` - The content URI for what we're playing (e.g. `server://1234/com.plexapp.plugins.library/library/metadata/1`).
|
|
* - `playQueueID` - To create a playlist from an existing play queue.
|
|
*
|
|
* @return The call builder
|
|
*/
|
|
public CreatePlaylistRequestBuilder createPlaylist() {
|
|
return new CreatePlaylistRequestBuilder(this);
|
|
}
|
|
|
|
/**
|
|
* Create a Playlist
|
|
* Create a new playlist. By default the playlist is blank. To create a playlist along with a first item, pass:
|
|
* - `uri` - The content URI for what we're playing (e.g. `server://1234/com.plexapp.plugins.library/library/metadata/1`).
|
|
* - `playQueueID` - To create a playlist from an existing play queue.
|
|
*
|
|
* @param request The request object containing all of the parameters for the API call.
|
|
* @return The response from the API call
|
|
* @throws Exception if the API call fails
|
|
*/
|
|
public CreatePlaylistResponse createPlaylist(
|
|
CreatePlaylistRequest request) throws Exception {
|
|
String _baseUrl = Utils.templateUrl(
|
|
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
|
|
String _url = Utils.generateURL(
|
|
_baseUrl,
|
|
"/playlists");
|
|
|
|
HTTPRequest _req = new HTTPRequest(_url, "POST");
|
|
_req.addHeader("Accept", "application/json")
|
|
.addHeader("user-agent",
|
|
SDKConfiguration.USER_AGENT);
|
|
|
|
_req.addQueryParams(Utils.getQueryParams(
|
|
CreatePlaylistRequest.class,
|
|
request,
|
|
null));
|
|
|
|
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
|
|
Utils.configureSecurity(_req,
|
|
this.sdkConfiguration.securitySource.getSecurity());
|
|
HTTPClient _client = this.sdkConfiguration.defaultClient;
|
|
HttpRequest _r =
|
|
sdkConfiguration.hooks()
|
|
.beforeRequest(
|
|
new BeforeRequestContextImpl(
|
|
"createPlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_req.build());
|
|
HttpResponse<InputStream> _httpRes;
|
|
try {
|
|
_httpRes = _client.send(_r);
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"createPlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.of(_httpRes),
|
|
Optional.empty());
|
|
} else {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterSuccess(
|
|
new AfterSuccessContextImpl(
|
|
"createPlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_httpRes);
|
|
}
|
|
} catch (Exception _e) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"createPlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.empty(),
|
|
Optional.of(_e));
|
|
}
|
|
String _contentType = _httpRes
|
|
.headers()
|
|
.firstValue("Content-Type")
|
|
.orElse("application/octet-stream");
|
|
CreatePlaylistResponse.Builder _resBuilder =
|
|
CreatePlaylistResponse
|
|
.builder()
|
|
.contentType(_contentType)
|
|
.statusCode(_httpRes.statusCode())
|
|
.rawResponse(_httpRes);
|
|
|
|
CreatePlaylistResponse _res = _resBuilder.build();
|
|
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
CreatePlaylistResponseBody _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<CreatePlaylistResponseBody>() {});
|
|
_res.withObject(Optional.ofNullable(_out));
|
|
return _res;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
CreatePlaylistBadRequest _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<CreatePlaylistBadRequest>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
CreatePlaylistUnauthorized _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<CreatePlaylistUnauthorized>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected status code received: " + _httpRes.statusCode(),
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Get All Playlists
|
|
* Get All Playlists given the specified filters.
|
|
* @return The call builder
|
|
*/
|
|
public GetPlaylistsRequestBuilder getPlaylists() {
|
|
return new GetPlaylistsRequestBuilder(this);
|
|
}
|
|
|
|
/**
|
|
* Get All Playlists
|
|
* Get All Playlists given the specified filters.
|
|
* @return The response from the API call
|
|
* @throws Exception if the API call fails
|
|
*/
|
|
public GetPlaylistsResponse getPlaylistsDirect() throws Exception {
|
|
return getPlaylists(Optional.empty(), Optional.empty());
|
|
}
|
|
|
|
/**
|
|
* Get All Playlists
|
|
* Get All Playlists given the specified filters.
|
|
* @param playlistType limit to a type of playlist.
|
|
* @param smart type of playlists to return (default is all).
|
|
* @return The response from the API call
|
|
* @throws Exception if the API call fails
|
|
*/
|
|
public GetPlaylistsResponse getPlaylists(
|
|
Optional<? extends PlaylistType> playlistType,
|
|
Optional<? extends QueryParamSmart> smart) throws Exception {
|
|
GetPlaylistsRequest request =
|
|
GetPlaylistsRequest
|
|
.builder()
|
|
.playlistType(playlistType)
|
|
.smart(smart)
|
|
.build();
|
|
|
|
String _baseUrl = Utils.templateUrl(
|
|
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
|
|
String _url = Utils.generateURL(
|
|
_baseUrl,
|
|
"/playlists");
|
|
|
|
HTTPRequest _req = new HTTPRequest(_url, "GET");
|
|
_req.addHeader("Accept", "application/json")
|
|
.addHeader("user-agent",
|
|
SDKConfiguration.USER_AGENT);
|
|
|
|
_req.addQueryParams(Utils.getQueryParams(
|
|
GetPlaylistsRequest.class,
|
|
request,
|
|
null));
|
|
|
|
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
|
|
Utils.configureSecurity(_req,
|
|
this.sdkConfiguration.securitySource.getSecurity());
|
|
HTTPClient _client = this.sdkConfiguration.defaultClient;
|
|
HttpRequest _r =
|
|
sdkConfiguration.hooks()
|
|
.beforeRequest(
|
|
new BeforeRequestContextImpl(
|
|
"getPlaylists",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_req.build());
|
|
HttpResponse<InputStream> _httpRes;
|
|
try {
|
|
_httpRes = _client.send(_r);
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"getPlaylists",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.of(_httpRes),
|
|
Optional.empty());
|
|
} else {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterSuccess(
|
|
new AfterSuccessContextImpl(
|
|
"getPlaylists",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_httpRes);
|
|
}
|
|
} catch (Exception _e) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"getPlaylists",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.empty(),
|
|
Optional.of(_e));
|
|
}
|
|
String _contentType = _httpRes
|
|
.headers()
|
|
.firstValue("Content-Type")
|
|
.orElse("application/octet-stream");
|
|
GetPlaylistsResponse.Builder _resBuilder =
|
|
GetPlaylistsResponse
|
|
.builder()
|
|
.contentType(_contentType)
|
|
.statusCode(_httpRes.statusCode())
|
|
.rawResponse(_httpRes);
|
|
|
|
GetPlaylistsResponse _res = _resBuilder.build();
|
|
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
GetPlaylistsResponseBody _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<GetPlaylistsResponseBody>() {});
|
|
_res.withObject(Optional.ofNullable(_out));
|
|
return _res;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
GetPlaylistsBadRequest _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<GetPlaylistsBadRequest>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
GetPlaylistsUnauthorized _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<GetPlaylistsUnauthorized>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected status code received: " + _httpRes.statusCode(),
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Retrieve Playlist
|
|
* Gets detailed metadata for a playlist. A playlist for many purposes (rating, editing metadata, tagging), can be treated like a regular metadata item:
|
|
* Smart playlist details contain the `content` attribute. This is the content URI for the generator. This can then be parsed by a client to provide smart playlist editing.
|
|
*
|
|
* @return The call builder
|
|
*/
|
|
public GetPlaylistRequestBuilder getPlaylist() {
|
|
return new GetPlaylistRequestBuilder(this);
|
|
}
|
|
|
|
/**
|
|
* Retrieve Playlist
|
|
* Gets detailed metadata for a playlist. A playlist for many purposes (rating, editing metadata, tagging), can be treated like a regular metadata item:
|
|
* Smart playlist details contain the `content` attribute. This is the content URI for the generator. This can then be parsed by a client to provide smart playlist editing.
|
|
*
|
|
* @param playlistID the ID of the playlist
|
|
* @return The response from the API call
|
|
* @throws Exception if the API call fails
|
|
*/
|
|
public GetPlaylistResponse getPlaylist(
|
|
double playlistID) throws Exception {
|
|
GetPlaylistRequest request =
|
|
GetPlaylistRequest
|
|
.builder()
|
|
.playlistID(playlistID)
|
|
.build();
|
|
|
|
String _baseUrl = Utils.templateUrl(
|
|
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
|
|
String _url = Utils.generateURL(
|
|
GetPlaylistRequest.class,
|
|
_baseUrl,
|
|
"/playlists/{playlistID}",
|
|
request, null);
|
|
|
|
HTTPRequest _req = new HTTPRequest(_url, "GET");
|
|
_req.addHeader("Accept", "application/json")
|
|
.addHeader("user-agent",
|
|
SDKConfiguration.USER_AGENT);
|
|
|
|
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
|
|
Utils.configureSecurity(_req,
|
|
this.sdkConfiguration.securitySource.getSecurity());
|
|
HTTPClient _client = this.sdkConfiguration.defaultClient;
|
|
HttpRequest _r =
|
|
sdkConfiguration.hooks()
|
|
.beforeRequest(
|
|
new BeforeRequestContextImpl(
|
|
"getPlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_req.build());
|
|
HttpResponse<InputStream> _httpRes;
|
|
try {
|
|
_httpRes = _client.send(_r);
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"getPlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.of(_httpRes),
|
|
Optional.empty());
|
|
} else {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterSuccess(
|
|
new AfterSuccessContextImpl(
|
|
"getPlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_httpRes);
|
|
}
|
|
} catch (Exception _e) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"getPlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.empty(),
|
|
Optional.of(_e));
|
|
}
|
|
String _contentType = _httpRes
|
|
.headers()
|
|
.firstValue("Content-Type")
|
|
.orElse("application/octet-stream");
|
|
GetPlaylistResponse.Builder _resBuilder =
|
|
GetPlaylistResponse
|
|
.builder()
|
|
.contentType(_contentType)
|
|
.statusCode(_httpRes.statusCode())
|
|
.rawResponse(_httpRes);
|
|
|
|
GetPlaylistResponse _res = _resBuilder.build();
|
|
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
GetPlaylistResponseBody _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<GetPlaylistResponseBody>() {});
|
|
_res.withObject(Optional.ofNullable(_out));
|
|
return _res;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
GetPlaylistBadRequest _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<GetPlaylistBadRequest>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
GetPlaylistUnauthorized _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<GetPlaylistUnauthorized>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected status code received: " + _httpRes.statusCode(),
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Deletes a Playlist
|
|
* This endpoint will delete a playlist
|
|
*
|
|
* @return The call builder
|
|
*/
|
|
public DeletePlaylistRequestBuilder deletePlaylist() {
|
|
return new DeletePlaylistRequestBuilder(this);
|
|
}
|
|
|
|
/**
|
|
* Deletes a Playlist
|
|
* This endpoint will delete a playlist
|
|
*
|
|
* @param playlistID the ID of the playlist
|
|
* @return The response from the API call
|
|
* @throws Exception if the API call fails
|
|
*/
|
|
public DeletePlaylistResponse deletePlaylist(
|
|
double playlistID) throws Exception {
|
|
DeletePlaylistRequest request =
|
|
DeletePlaylistRequest
|
|
.builder()
|
|
.playlistID(playlistID)
|
|
.build();
|
|
|
|
String _baseUrl = Utils.templateUrl(
|
|
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
|
|
String _url = Utils.generateURL(
|
|
DeletePlaylistRequest.class,
|
|
_baseUrl,
|
|
"/playlists/{playlistID}",
|
|
request, null);
|
|
|
|
HTTPRequest _req = new HTTPRequest(_url, "DELETE");
|
|
_req.addHeader("Accept", "application/json")
|
|
.addHeader("user-agent",
|
|
SDKConfiguration.USER_AGENT);
|
|
|
|
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
|
|
Utils.configureSecurity(_req,
|
|
this.sdkConfiguration.securitySource.getSecurity());
|
|
HTTPClient _client = this.sdkConfiguration.defaultClient;
|
|
HttpRequest _r =
|
|
sdkConfiguration.hooks()
|
|
.beforeRequest(
|
|
new BeforeRequestContextImpl(
|
|
"deletePlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_req.build());
|
|
HttpResponse<InputStream> _httpRes;
|
|
try {
|
|
_httpRes = _client.send(_r);
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"deletePlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.of(_httpRes),
|
|
Optional.empty());
|
|
} else {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterSuccess(
|
|
new AfterSuccessContextImpl(
|
|
"deletePlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_httpRes);
|
|
}
|
|
} catch (Exception _e) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"deletePlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.empty(),
|
|
Optional.of(_e));
|
|
}
|
|
String _contentType = _httpRes
|
|
.headers()
|
|
.firstValue("Content-Type")
|
|
.orElse("application/octet-stream");
|
|
DeletePlaylistResponse.Builder _resBuilder =
|
|
DeletePlaylistResponse
|
|
.builder()
|
|
.contentType(_contentType)
|
|
.statusCode(_httpRes.statusCode())
|
|
.rawResponse(_httpRes);
|
|
|
|
DeletePlaylistResponse _res = _resBuilder.build();
|
|
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "204")) {
|
|
// no content
|
|
return _res;
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
DeletePlaylistBadRequest _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<DeletePlaylistBadRequest>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
DeletePlaylistUnauthorized _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<DeletePlaylistUnauthorized>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected status code received: " + _httpRes.statusCode(),
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Update a Playlist
|
|
* From PMS version 1.9.1 clients can also edit playlist metadata using this endpoint as they would via `PUT /library/metadata/{playlistID}`
|
|
*
|
|
* @return The call builder
|
|
*/
|
|
public UpdatePlaylistRequestBuilder updatePlaylist() {
|
|
return new UpdatePlaylistRequestBuilder(this);
|
|
}
|
|
|
|
/**
|
|
* Update a Playlist
|
|
* From PMS version 1.9.1 clients can also edit playlist metadata using this endpoint as they would via `PUT /library/metadata/{playlistID}`
|
|
*
|
|
* @param playlistID the ID of the playlist
|
|
* @return The response from the API call
|
|
* @throws Exception if the API call fails
|
|
*/
|
|
public UpdatePlaylistResponse updatePlaylist(
|
|
double playlistID) throws Exception {
|
|
return updatePlaylist(playlistID, Optional.empty(), Optional.empty());
|
|
}
|
|
|
|
/**
|
|
* Update a Playlist
|
|
* From PMS version 1.9.1 clients can also edit playlist metadata using this endpoint as they would via `PUT /library/metadata/{playlistID}`
|
|
*
|
|
* @param playlistID the ID of the playlist
|
|
* @param title name of the playlist
|
|
* @param summary summary description of the playlist
|
|
* @return The response from the API call
|
|
* @throws Exception if the API call fails
|
|
*/
|
|
public UpdatePlaylistResponse updatePlaylist(
|
|
double playlistID,
|
|
Optional<String> title,
|
|
Optional<String> summary) throws Exception {
|
|
UpdatePlaylistRequest request =
|
|
UpdatePlaylistRequest
|
|
.builder()
|
|
.playlistID(playlistID)
|
|
.title(title)
|
|
.summary(summary)
|
|
.build();
|
|
|
|
String _baseUrl = Utils.templateUrl(
|
|
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
|
|
String _url = Utils.generateURL(
|
|
UpdatePlaylistRequest.class,
|
|
_baseUrl,
|
|
"/playlists/{playlistID}",
|
|
request, null);
|
|
|
|
HTTPRequest _req = new HTTPRequest(_url, "PUT");
|
|
_req.addHeader("Accept", "application/json")
|
|
.addHeader("user-agent",
|
|
SDKConfiguration.USER_AGENT);
|
|
|
|
_req.addQueryParams(Utils.getQueryParams(
|
|
UpdatePlaylistRequest.class,
|
|
request,
|
|
null));
|
|
|
|
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
|
|
Utils.configureSecurity(_req,
|
|
this.sdkConfiguration.securitySource.getSecurity());
|
|
HTTPClient _client = this.sdkConfiguration.defaultClient;
|
|
HttpRequest _r =
|
|
sdkConfiguration.hooks()
|
|
.beforeRequest(
|
|
new BeforeRequestContextImpl(
|
|
"updatePlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_req.build());
|
|
HttpResponse<InputStream> _httpRes;
|
|
try {
|
|
_httpRes = _client.send(_r);
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"updatePlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.of(_httpRes),
|
|
Optional.empty());
|
|
} else {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterSuccess(
|
|
new AfterSuccessContextImpl(
|
|
"updatePlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_httpRes);
|
|
}
|
|
} catch (Exception _e) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"updatePlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.empty(),
|
|
Optional.of(_e));
|
|
}
|
|
String _contentType = _httpRes
|
|
.headers()
|
|
.firstValue("Content-Type")
|
|
.orElse("application/octet-stream");
|
|
UpdatePlaylistResponse.Builder _resBuilder =
|
|
UpdatePlaylistResponse
|
|
.builder()
|
|
.contentType(_contentType)
|
|
.statusCode(_httpRes.statusCode())
|
|
.rawResponse(_httpRes);
|
|
|
|
UpdatePlaylistResponse _res = _resBuilder.build();
|
|
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
|
|
// no content
|
|
return _res;
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
UpdatePlaylistBadRequest _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<UpdatePlaylistBadRequest>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
UpdatePlaylistUnauthorized _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<UpdatePlaylistUnauthorized>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected status code received: " + _httpRes.statusCode(),
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Retrieve Playlist Contents
|
|
* Gets the contents of a playlist. Should be paged by clients via standard mechanisms.
|
|
* By default leaves are returned (e.g. episodes, movies). In order to return other types you can use the `type` parameter.
|
|
* For example, you could use this to display a list of recently added albums vis a smart playlist.
|
|
* Note that for dumb playlists, items have a `playlistItemID` attribute which is used for deleting or moving items.
|
|
*
|
|
* @return The call builder
|
|
*/
|
|
public GetPlaylistContentsRequestBuilder getPlaylistContents() {
|
|
return new GetPlaylistContentsRequestBuilder(this);
|
|
}
|
|
|
|
/**
|
|
* Retrieve Playlist Contents
|
|
* Gets the contents of a playlist. Should be paged by clients via standard mechanisms.
|
|
* By default leaves are returned (e.g. episodes, movies). In order to return other types you can use the `type` parameter.
|
|
* For example, you could use this to display a list of recently added albums vis a smart playlist.
|
|
* Note that for dumb playlists, items have a `playlistItemID` attribute which is used for deleting or moving items.
|
|
*
|
|
* @param playlistID the ID of the playlist
|
|
* @param type The type of media to retrieve.
|
|
1 = movie
|
|
2 = show
|
|
3 = season
|
|
4 = episode
|
|
E.g. A movie library will not return anything with type 3 as there are no seasons for movie libraries
|
|
|
|
* @return The response from the API call
|
|
* @throws Exception if the API call fails
|
|
*/
|
|
public GetPlaylistContentsResponse getPlaylistContents(
|
|
double playlistID,
|
|
GetPlaylistContentsQueryParamType type) throws Exception {
|
|
GetPlaylistContentsRequest request =
|
|
GetPlaylistContentsRequest
|
|
.builder()
|
|
.playlistID(playlistID)
|
|
.type(type)
|
|
.build();
|
|
|
|
String _baseUrl = Utils.templateUrl(
|
|
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
|
|
String _url = Utils.generateURL(
|
|
GetPlaylistContentsRequest.class,
|
|
_baseUrl,
|
|
"/playlists/{playlistID}/items",
|
|
request, null);
|
|
|
|
HTTPRequest _req = new HTTPRequest(_url, "GET");
|
|
_req.addHeader("Accept", "application/json")
|
|
.addHeader("user-agent",
|
|
SDKConfiguration.USER_AGENT);
|
|
|
|
_req.addQueryParams(Utils.getQueryParams(
|
|
GetPlaylistContentsRequest.class,
|
|
request,
|
|
null));
|
|
|
|
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
|
|
Utils.configureSecurity(_req,
|
|
this.sdkConfiguration.securitySource.getSecurity());
|
|
HTTPClient _client = this.sdkConfiguration.defaultClient;
|
|
HttpRequest _r =
|
|
sdkConfiguration.hooks()
|
|
.beforeRequest(
|
|
new BeforeRequestContextImpl(
|
|
"getPlaylistContents",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_req.build());
|
|
HttpResponse<InputStream> _httpRes;
|
|
try {
|
|
_httpRes = _client.send(_r);
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"getPlaylistContents",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.of(_httpRes),
|
|
Optional.empty());
|
|
} else {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterSuccess(
|
|
new AfterSuccessContextImpl(
|
|
"getPlaylistContents",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_httpRes);
|
|
}
|
|
} catch (Exception _e) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"getPlaylistContents",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.empty(),
|
|
Optional.of(_e));
|
|
}
|
|
String _contentType = _httpRes
|
|
.headers()
|
|
.firstValue("Content-Type")
|
|
.orElse("application/octet-stream");
|
|
GetPlaylistContentsResponse.Builder _resBuilder =
|
|
GetPlaylistContentsResponse
|
|
.builder()
|
|
.contentType(_contentType)
|
|
.statusCode(_httpRes.statusCode())
|
|
.rawResponse(_httpRes);
|
|
|
|
GetPlaylistContentsResponse _res = _resBuilder.build();
|
|
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
GetPlaylistContentsResponseBody _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<GetPlaylistContentsResponseBody>() {});
|
|
_res.withObject(Optional.ofNullable(_out));
|
|
return _res;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
GetPlaylistContentsBadRequest _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<GetPlaylistContentsBadRequest>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
GetPlaylistContentsUnauthorized _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<GetPlaylistContentsUnauthorized>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected status code received: " + _httpRes.statusCode(),
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Delete Playlist Contents
|
|
* Clears a playlist, only works with dumb playlists. Returns the playlist.
|
|
*
|
|
* @return The call builder
|
|
*/
|
|
public ClearPlaylistContentsRequestBuilder clearPlaylistContents() {
|
|
return new ClearPlaylistContentsRequestBuilder(this);
|
|
}
|
|
|
|
/**
|
|
* Delete Playlist Contents
|
|
* Clears a playlist, only works with dumb playlists. Returns the playlist.
|
|
*
|
|
* @param playlistID the ID of the playlist
|
|
* @return The response from the API call
|
|
* @throws Exception if the API call fails
|
|
*/
|
|
public ClearPlaylistContentsResponse clearPlaylistContents(
|
|
double playlistID) throws Exception {
|
|
ClearPlaylistContentsRequest request =
|
|
ClearPlaylistContentsRequest
|
|
.builder()
|
|
.playlistID(playlistID)
|
|
.build();
|
|
|
|
String _baseUrl = Utils.templateUrl(
|
|
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
|
|
String _url = Utils.generateURL(
|
|
ClearPlaylistContentsRequest.class,
|
|
_baseUrl,
|
|
"/playlists/{playlistID}/items",
|
|
request, null);
|
|
|
|
HTTPRequest _req = new HTTPRequest(_url, "DELETE");
|
|
_req.addHeader("Accept", "application/json")
|
|
.addHeader("user-agent",
|
|
SDKConfiguration.USER_AGENT);
|
|
|
|
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
|
|
Utils.configureSecurity(_req,
|
|
this.sdkConfiguration.securitySource.getSecurity());
|
|
HTTPClient _client = this.sdkConfiguration.defaultClient;
|
|
HttpRequest _r =
|
|
sdkConfiguration.hooks()
|
|
.beforeRequest(
|
|
new BeforeRequestContextImpl(
|
|
"clearPlaylistContents",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_req.build());
|
|
HttpResponse<InputStream> _httpRes;
|
|
try {
|
|
_httpRes = _client.send(_r);
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"clearPlaylistContents",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.of(_httpRes),
|
|
Optional.empty());
|
|
} else {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterSuccess(
|
|
new AfterSuccessContextImpl(
|
|
"clearPlaylistContents",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_httpRes);
|
|
}
|
|
} catch (Exception _e) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"clearPlaylistContents",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.empty(),
|
|
Optional.of(_e));
|
|
}
|
|
String _contentType = _httpRes
|
|
.headers()
|
|
.firstValue("Content-Type")
|
|
.orElse("application/octet-stream");
|
|
ClearPlaylistContentsResponse.Builder _resBuilder =
|
|
ClearPlaylistContentsResponse
|
|
.builder()
|
|
.contentType(_contentType)
|
|
.statusCode(_httpRes.statusCode())
|
|
.rawResponse(_httpRes);
|
|
|
|
ClearPlaylistContentsResponse _res = _resBuilder.build();
|
|
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
|
|
// no content
|
|
return _res;
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
ClearPlaylistContentsBadRequest _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<ClearPlaylistContentsBadRequest>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
ClearPlaylistContentsUnauthorized _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<ClearPlaylistContentsUnauthorized>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected status code received: " + _httpRes.statusCode(),
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Adding to a Playlist
|
|
* Adds a generator to a playlist, same parameters as the POST to create. With a dumb playlist, this adds the specified items to the playlist.
|
|
* With a smart playlist, passing a new `uri` parameter replaces the rules for the playlist. Returns the playlist.
|
|
*
|
|
* @return The call builder
|
|
*/
|
|
public AddPlaylistContentsRequestBuilder addPlaylistContents() {
|
|
return new AddPlaylistContentsRequestBuilder(this);
|
|
}
|
|
|
|
/**
|
|
* Adding to a Playlist
|
|
* Adds a generator to a playlist, same parameters as the POST to create. With a dumb playlist, this adds the specified items to the playlist.
|
|
* With a smart playlist, passing a new `uri` parameter replaces the rules for the playlist. Returns the playlist.
|
|
*
|
|
* @param playlistID the ID of the playlist
|
|
* @param uri the content URI for the playlist
|
|
* @return The response from the API call
|
|
* @throws Exception if the API call fails
|
|
*/
|
|
public AddPlaylistContentsResponse addPlaylistContents(
|
|
double playlistID,
|
|
String uri) throws Exception {
|
|
return addPlaylistContents(playlistID, uri, Optional.empty());
|
|
}
|
|
|
|
/**
|
|
* Adding to a Playlist
|
|
* Adds a generator to a playlist, same parameters as the POST to create. With a dumb playlist, this adds the specified items to the playlist.
|
|
* With a smart playlist, passing a new `uri` parameter replaces the rules for the playlist. Returns the playlist.
|
|
*
|
|
* @param playlistID the ID of the playlist
|
|
* @param uri the content URI for the playlist
|
|
* @param playQueueID the play queue to add to a playlist
|
|
* @return The response from the API call
|
|
* @throws Exception if the API call fails
|
|
*/
|
|
public AddPlaylistContentsResponse addPlaylistContents(
|
|
double playlistID,
|
|
String uri,
|
|
Optional<Double> playQueueID) throws Exception {
|
|
AddPlaylistContentsRequest request =
|
|
AddPlaylistContentsRequest
|
|
.builder()
|
|
.playlistID(playlistID)
|
|
.uri(uri)
|
|
.playQueueID(playQueueID)
|
|
.build();
|
|
|
|
String _baseUrl = Utils.templateUrl(
|
|
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
|
|
String _url = Utils.generateURL(
|
|
AddPlaylistContentsRequest.class,
|
|
_baseUrl,
|
|
"/playlists/{playlistID}/items",
|
|
request, null);
|
|
|
|
HTTPRequest _req = new HTTPRequest(_url, "PUT");
|
|
_req.addHeader("Accept", "application/json")
|
|
.addHeader("user-agent",
|
|
SDKConfiguration.USER_AGENT);
|
|
|
|
_req.addQueryParams(Utils.getQueryParams(
|
|
AddPlaylistContentsRequest.class,
|
|
request,
|
|
null));
|
|
|
|
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
|
|
Utils.configureSecurity(_req,
|
|
this.sdkConfiguration.securitySource.getSecurity());
|
|
HTTPClient _client = this.sdkConfiguration.defaultClient;
|
|
HttpRequest _r =
|
|
sdkConfiguration.hooks()
|
|
.beforeRequest(
|
|
new BeforeRequestContextImpl(
|
|
"addPlaylistContents",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_req.build());
|
|
HttpResponse<InputStream> _httpRes;
|
|
try {
|
|
_httpRes = _client.send(_r);
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"addPlaylistContents",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.of(_httpRes),
|
|
Optional.empty());
|
|
} else {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterSuccess(
|
|
new AfterSuccessContextImpl(
|
|
"addPlaylistContents",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_httpRes);
|
|
}
|
|
} catch (Exception _e) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"addPlaylistContents",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.empty(),
|
|
Optional.of(_e));
|
|
}
|
|
String _contentType = _httpRes
|
|
.headers()
|
|
.firstValue("Content-Type")
|
|
.orElse("application/octet-stream");
|
|
AddPlaylistContentsResponse.Builder _resBuilder =
|
|
AddPlaylistContentsResponse
|
|
.builder()
|
|
.contentType(_contentType)
|
|
.statusCode(_httpRes.statusCode())
|
|
.rawResponse(_httpRes);
|
|
|
|
AddPlaylistContentsResponse _res = _resBuilder.build();
|
|
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
AddPlaylistContentsResponseBody _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<AddPlaylistContentsResponseBody>() {});
|
|
_res.withObject(Optional.ofNullable(_out));
|
|
return _res;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
AddPlaylistContentsBadRequest _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<AddPlaylistContentsBadRequest>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
AddPlaylistContentsUnauthorized _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<AddPlaylistContentsUnauthorized>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected status code received: " + _httpRes.statusCode(),
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Upload Playlist
|
|
* Imports m3u playlists by passing a path on the server to scan for m3u-formatted playlist files, or a path to a single playlist file.
|
|
*
|
|
* @return The call builder
|
|
*/
|
|
public UploadPlaylistRequestBuilder uploadPlaylist() {
|
|
return new UploadPlaylistRequestBuilder(this);
|
|
}
|
|
|
|
/**
|
|
* Upload Playlist
|
|
* Imports m3u playlists by passing a path on the server to scan for m3u-formatted playlist files, or a path to a single playlist file.
|
|
*
|
|
* @param path absolute path to a directory on the server where m3u files are stored, or the absolute path to a playlist file on the server.
|
|
If the `path` argument is a directory, that path will be scanned for playlist files to be processed.
|
|
Each file in that directory creates a separate playlist, with a name based on the filename of the file that created it.
|
|
The GUID of each playlist is based on the filename.
|
|
If the `path` argument is a file, that file will be used to create a new playlist, with the name based on the filename of the file that created it.
|
|
The GUID of each playlist is based on the filename.
|
|
|
|
* @param force Force overwriting of duplicate playlists.
|
|
By default, a playlist file uploaded with the same path will overwrite the existing playlist.
|
|
The `force` argument is used to disable overwriting.
|
|
If the `force` argument is set to 0, a new playlist will be created suffixed with the date and time that the duplicate was uploaded.
|
|
|
|
* @param sectionID Possibly the section ID to upload the playlist to, we are not certain.
|
|
* @return The response from the API call
|
|
* @throws Exception if the API call fails
|
|
*/
|
|
public UploadPlaylistResponse uploadPlaylist(
|
|
String path,
|
|
QueryParamForce force,
|
|
long sectionID) throws Exception {
|
|
UploadPlaylistRequest request =
|
|
UploadPlaylistRequest
|
|
.builder()
|
|
.path(path)
|
|
.force(force)
|
|
.sectionID(sectionID)
|
|
.build();
|
|
|
|
String _baseUrl = Utils.templateUrl(
|
|
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
|
|
String _url = Utils.generateURL(
|
|
_baseUrl,
|
|
"/playlists/upload");
|
|
|
|
HTTPRequest _req = new HTTPRequest(_url, "POST");
|
|
_req.addHeader("Accept", "application/json")
|
|
.addHeader("user-agent",
|
|
SDKConfiguration.USER_AGENT);
|
|
|
|
_req.addQueryParams(Utils.getQueryParams(
|
|
UploadPlaylistRequest.class,
|
|
request,
|
|
null));
|
|
|
|
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
|
|
Utils.configureSecurity(_req,
|
|
this.sdkConfiguration.securitySource.getSecurity());
|
|
HTTPClient _client = this.sdkConfiguration.defaultClient;
|
|
HttpRequest _r =
|
|
sdkConfiguration.hooks()
|
|
.beforeRequest(
|
|
new BeforeRequestContextImpl(
|
|
"uploadPlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_req.build());
|
|
HttpResponse<InputStream> _httpRes;
|
|
try {
|
|
_httpRes = _client.send(_r);
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"uploadPlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.of(_httpRes),
|
|
Optional.empty());
|
|
} else {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterSuccess(
|
|
new AfterSuccessContextImpl(
|
|
"uploadPlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
_httpRes);
|
|
}
|
|
} catch (Exception _e) {
|
|
_httpRes = sdkConfiguration.hooks()
|
|
.afterError(
|
|
new AfterErrorContextImpl(
|
|
"uploadPlaylist",
|
|
Optional.of(List.of()),
|
|
_hookSecuritySource),
|
|
Optional.empty(),
|
|
Optional.of(_e));
|
|
}
|
|
String _contentType = _httpRes
|
|
.headers()
|
|
.firstValue("Content-Type")
|
|
.orElse("application/octet-stream");
|
|
UploadPlaylistResponse.Builder _resBuilder =
|
|
UploadPlaylistResponse
|
|
.builder()
|
|
.contentType(_contentType)
|
|
.statusCode(_httpRes.statusCode())
|
|
.rawResponse(_httpRes);
|
|
|
|
UploadPlaylistResponse _res = _resBuilder.build();
|
|
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
|
|
// no content
|
|
return _res;
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
UploadPlaylistBadRequest _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<UploadPlaylistBadRequest>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
|
|
if (Utils.contentTypeMatches(_contentType, "application/json")) {
|
|
UploadPlaylistUnauthorized _out = Utils.mapper().readValue(
|
|
Utils.toUtf8AndClose(_httpRes.body()),
|
|
new TypeReference<UploadPlaylistUnauthorized>() {});
|
|
_out.withRawResponse(Optional.ofNullable(_httpRes));
|
|
|
|
throw _out;
|
|
} else {
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected content-type received: " + _contentType,
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
|
|
// no content
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"API error occurred",
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
throw new SDKError(
|
|
_httpRes,
|
|
_httpRes.statusCode(),
|
|
"Unexpected status code received: " + _httpRes.statusCode(),
|
|
Utils.extractByteArrayFromBody(_httpRes));
|
|
}
|
|
|
|
}
|