mirror of
https://github.com/LukeHagar/plexgo.git
synced 2025-12-06 04:20:46 +00:00
461 lines
15 KiB
Go
461 lines
15 KiB
Go
/*
|
|
Plex-API
|
|
|
|
An Open API Spec for interacting with Plex.tv and Plex Servers
|
|
|
|
API version: 0.0.3
|
|
Contact: Lukeslakemail@gmail.com
|
|
*/
|
|
|
|
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
|
|
|
|
package pms
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
|
|
// SearchApiService SearchApi service
|
|
type SearchApiService service
|
|
|
|
type ApiGetSearchResultsRequest struct {
|
|
ctx context.Context
|
|
ApiService *SearchApiService
|
|
query *interface{}
|
|
}
|
|
|
|
// The search query string to use
|
|
func (r ApiGetSearchResultsRequest) Query(query interface{}) ApiGetSearchResultsRequest {
|
|
r.query = &query
|
|
return r
|
|
}
|
|
|
|
func (r ApiGetSearchResultsRequest) Execute() (*GetSearchResults200Response, *http.Response, error) {
|
|
return r.ApiService.GetSearchResultsExecute(r)
|
|
}
|
|
|
|
/*
|
|
GetSearchResults Get Search Results
|
|
|
|
This will search the database for the string provided.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return ApiGetSearchResultsRequest
|
|
*/
|
|
func (a *SearchApiService) GetSearchResults(ctx context.Context) ApiGetSearchResultsRequest {
|
|
return ApiGetSearchResultsRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
// @return GetSearchResults200Response
|
|
func (a *SearchApiService) GetSearchResultsExecute(r ApiGetSearchResultsRequest) (*GetSearchResults200Response, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *GetSearchResults200Response
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "SearchApiService.GetSearchResults")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/search"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
if r.query == nil {
|
|
return localVarReturnValue, nil, reportError("query is required and must be specified")
|
|
}
|
|
|
|
parameterAddToQuery(localVarQueryParams, "query", r.query, "")
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
if r.ctx != nil {
|
|
// API Key Authentication
|
|
if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
|
|
if apiKey, ok := auth["accessToken"]; ok {
|
|
var key string
|
|
if apiKey.Prefix != "" {
|
|
key = apiKey.Prefix + " " + apiKey.Key
|
|
} else {
|
|
key = apiKey.Key
|
|
}
|
|
localVarHeaderParams["X-Plex-Token"] = key
|
|
}
|
|
}
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := ioutil.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = ioutil.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
if localVarHTTPResponse.StatusCode == 401 {
|
|
var v GetServerCapabilities401Response
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|
|
|
|
type ApiPerformSearchRequest struct {
|
|
ctx context.Context
|
|
ApiService *SearchApiService
|
|
query *interface{}
|
|
sectionId *interface{}
|
|
limit *interface{}
|
|
}
|
|
|
|
// The query term
|
|
func (r ApiPerformSearchRequest) Query(query interface{}) ApiPerformSearchRequest {
|
|
r.query = &query
|
|
return r
|
|
}
|
|
|
|
// This gives context to the search, and can result in re-ordering of search result hubs
|
|
func (r ApiPerformSearchRequest) SectionId(sectionId interface{}) ApiPerformSearchRequest {
|
|
r.sectionId = §ionId
|
|
return r
|
|
}
|
|
|
|
// The number of items to return per hub
|
|
func (r ApiPerformSearchRequest) Limit(limit interface{}) ApiPerformSearchRequest {
|
|
r.limit = &limit
|
|
return r
|
|
}
|
|
|
|
func (r ApiPerformSearchRequest) Execute() (*http.Response, error) {
|
|
return r.ApiService.PerformSearchExecute(r)
|
|
}
|
|
|
|
/*
|
|
PerformSearch Perform a search
|
|
|
|
This endpoint performs a search across all library sections, or a single section, and returns matches as hubs, split up by type. It performs spell checking, looks for partial matches, and orders the hubs based on quality of results. In addition, based on matches, it will return other related matches (e.g. for a genre match, it may return movies in that genre, or for an actor match, movies with that actor).
|
|
|
|
In the response's items, the following extra attributes are returned to further describe or disambiguate the result:
|
|
|
|
- `reason`: The reason for the result, if not because of a direct search term match; can be either:
|
|
- `section`: There are multiple identical results from different sections.
|
|
- `originalTitle`: There was a search term match from the original title field (sometimes those can be very different or in a foreign language).
|
|
- `<hub identifier>`: If the reason for the result is due to a result in another hub, the source hub identifier is returned. For example, if the search is for "dylan" then Bob Dylan may be returned as an artist result, an a few of his albums returned as album results with a reason code of `artist` (the identifier of that particular hub). Or if the search is for "arnold", there might be movie results returned with a reason of `actor`
|
|
- `reasonTitle`: The string associated with the reason code. For a section reason, it'll be the section name; For a hub identifier, it'll be a string associated with the match (e.g. `Arnold Schwarzenegger` for movies which were returned because the search was for "arnold").
|
|
- `reasonID`: The ID of the item associated with the reason for the result. This might be a section ID, a tag ID, an artist ID, or a show ID.
|
|
|
|
This request is intended to be very fast, and called as the user types.
|
|
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return ApiPerformSearchRequest
|
|
*/
|
|
func (a *SearchApiService) PerformSearch(ctx context.Context) ApiPerformSearchRequest {
|
|
return ApiPerformSearchRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
func (a *SearchApiService) PerformSearchExecute(r ApiPerformSearchRequest) (*http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "SearchApiService.PerformSearch")
|
|
if err != nil {
|
|
return nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/hubs/search"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
if r.query == nil {
|
|
return nil, reportError("query is required and must be specified")
|
|
}
|
|
|
|
parameterAddToQuery(localVarQueryParams, "query", r.query, "")
|
|
if r.sectionId != nil {
|
|
parameterAddToQuery(localVarQueryParams, "sectionId", r.sectionId, "")
|
|
}
|
|
if r.limit != nil {
|
|
parameterAddToQuery(localVarQueryParams, "limit", r.limit, "")
|
|
}
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
if r.ctx != nil {
|
|
// API Key Authentication
|
|
if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
|
|
if apiKey, ok := auth["accessToken"]; ok {
|
|
var key string
|
|
if apiKey.Prefix != "" {
|
|
key = apiKey.Prefix + " " + apiKey.Key
|
|
} else {
|
|
key = apiKey.Key
|
|
}
|
|
localVarHeaderParams["X-Plex-Token"] = key
|
|
}
|
|
}
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := ioutil.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = ioutil.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
if localVarHTTPResponse.StatusCode == 401 {
|
|
var v GetServerCapabilities401Response
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
}
|
|
return localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarHTTPResponse, nil
|
|
}
|
|
|
|
type ApiPerformVoiceSearchRequest struct {
|
|
ctx context.Context
|
|
ApiService *SearchApiService
|
|
query *interface{}
|
|
sectionId *interface{}
|
|
limit *interface{}
|
|
}
|
|
|
|
// The query term
|
|
func (r ApiPerformVoiceSearchRequest) Query(query interface{}) ApiPerformVoiceSearchRequest {
|
|
r.query = &query
|
|
return r
|
|
}
|
|
|
|
// This gives context to the search, and can result in re-ordering of search result hubs
|
|
func (r ApiPerformVoiceSearchRequest) SectionId(sectionId interface{}) ApiPerformVoiceSearchRequest {
|
|
r.sectionId = §ionId
|
|
return r
|
|
}
|
|
|
|
// The number of items to return per hub
|
|
func (r ApiPerformVoiceSearchRequest) Limit(limit interface{}) ApiPerformVoiceSearchRequest {
|
|
r.limit = &limit
|
|
return r
|
|
}
|
|
|
|
func (r ApiPerformVoiceSearchRequest) Execute() (*http.Response, error) {
|
|
return r.ApiService.PerformVoiceSearchExecute(r)
|
|
}
|
|
|
|
/*
|
|
PerformVoiceSearch Perform a voice search
|
|
|
|
This endpoint performs a search specifically tailored towards voice or other imprecise input which may work badly with the substring and spell-checking heuristics used by the `/hubs/search` endpoint.
|
|
It uses a [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) heuristic to search titles, and as such is much slower than the other search endpoint.
|
|
Whenever possible, clients should limit the search to the appropriate type.
|
|
Results, as well as their containing per-type hubs, contain a `distance` attribute which can be used to judge result quality.
|
|
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return ApiPerformVoiceSearchRequest
|
|
*/
|
|
func (a *SearchApiService) PerformVoiceSearch(ctx context.Context) ApiPerformVoiceSearchRequest {
|
|
return ApiPerformVoiceSearchRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
func (a *SearchApiService) PerformVoiceSearchExecute(r ApiPerformVoiceSearchRequest) (*http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "SearchApiService.PerformVoiceSearch")
|
|
if err != nil {
|
|
return nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/hubs/search/voice"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
if r.query == nil {
|
|
return nil, reportError("query is required and must be specified")
|
|
}
|
|
|
|
parameterAddToQuery(localVarQueryParams, "query", r.query, "")
|
|
if r.sectionId != nil {
|
|
parameterAddToQuery(localVarQueryParams, "sectionId", r.sectionId, "")
|
|
}
|
|
if r.limit != nil {
|
|
parameterAddToQuery(localVarQueryParams, "limit", r.limit, "")
|
|
}
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
if r.ctx != nil {
|
|
// API Key Authentication
|
|
if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
|
|
if apiKey, ok := auth["accessToken"]; ok {
|
|
var key string
|
|
if apiKey.Prefix != "" {
|
|
key = apiKey.Prefix + " " + apiKey.Key
|
|
} else {
|
|
key = apiKey.Key
|
|
}
|
|
localVarHeaderParams["X-Plex-Token"] = key
|
|
}
|
|
}
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := ioutil.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = ioutil.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
if localVarHTTPResponse.StatusCode == 401 {
|
|
var v GetServerCapabilities401Response
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
}
|
|
return localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarHTTPResponse, nil
|
|
}
|