diff --git a/src/BaseService.ts b/src/BaseService.ts deleted file mode 100644 index ec5b52ad..00000000 --- a/src/BaseService.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Environment } from './http/Environment'; -import HTTPLibrary from './http/HTTPLibrary'; -import { Headers } from './http/HTTPClient'; - -export default class BaseService { - public baseUrl: string = Environment.DEFAULT; - - public httpClient = new HTTPLibrary(); - - private apiKey: string = ''; - - private apiKeyHeader: string = 'X-Plex-Token'; - - setApiKey(key: string, header: string = 'X-Plex-Token'): void { - this.apiKey = key; - this.apiKeyHeader = header; - } - - getAuthorizationHeader(): Headers { - const apiKeyAuth = { [this.apiKeyHeader]: this.apiKey }; - - return { ...apiKeyAuth }; - } - - setBaseUrl(url: string): void { - this.baseUrl = url; - } - - constructor(apiKey: string = '', apiKeyHeader: string = 'X-Plex-Token') { - this.setApiKey(apiKey, apiKeyHeader); - } - - static patternMatching(value: string, pattern: string, variableName: string): string { - if (!value) { - throw new Error(`${variableName} cannot be null or undefined`); - } - if (!value.match(new RegExp(pattern))) { - throw new Error(`Invalid value for ${variableName}: must match ${pattern}`); - } - return value; - } - - static urlEncode = (input: { [key: string]: any }): string => - Object.keys(input) - .map((key) => `${key}=${encodeURIComponent(input[key])}`) - .join('&'); -} diff --git a/src/hooks/Hook.ts b/src/hooks/Hook.ts deleted file mode 100644 index 443030be..00000000 --- a/src/hooks/Hook.ts +++ /dev/null @@ -1,28 +0,0 @@ -export interface Request { - method: string; - url: string; - input?: object; - headers: object; -} - -export interface Response { - data: object; - headers: object; - status: number; -} - -export interface Exception extends Error { - title: string; - type?: string; - detail?: string; - instance?: string; - statusCode: number; -} - -export interface Hook { - beforeRequest(request: Request): Promise; - - afterResponse(request: Request, response: Response): Promise; - - onError(error: Exception): Promise; -} diff --git a/src/http/Environment.ts b/src/http/Environment.ts deleted file mode 100644 index b6836fdb..00000000 --- a/src/http/Environment.ts +++ /dev/null @@ -1,3 +0,0 @@ -export enum Environment { - DEFAULT = 'http://10.10.10.47:32400', -} diff --git a/src/http/HTTPClient.ts b/src/http/HTTPClient.ts deleted file mode 100644 index 2a37df8e..00000000 --- a/src/http/HTTPClient.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface Headers extends Record {} - -/** - * Defines the basic operations for an HTTP client. - */ -export default interface HTTPClient { - get(url: string, input: any, headers: Headers, retry?: boolean): Promise; - post(url: string, input: any, headers: Headers, retry?: boolean): Promise; - delete(url: string, input: any, headers: Headers, retry?: boolean): Promise; - put(url: string, input: any, headers: Headers, retry?: boolean): Promise; - patch(url: string, input: any, headers: Headers, retry?: boolean): Promise; -} diff --git a/src/http/HTTPLibrary.ts b/src/http/HTTPLibrary.ts deleted file mode 100644 index 121a7c60..00000000 --- a/src/http/HTTPLibrary.ts +++ /dev/null @@ -1,161 +0,0 @@ -import axios, { AxiosError } from 'axios'; - -import HTTPClient, { Headers } from './HTTPClient'; -import throwHttpError from './httpExceptions'; - -export default class HTTPLibrary implements HTTPClient { - readonly userAgentHeader: Headers = { - 'User-Agent': 'liblab/0.1.25 PlexSDK/0.0.1 typescript/5.2.2', - }; - - readonly retryAttempts: number = 3; - - readonly retryDelayMs: number = 150; - - private static readonly responseMapper: Map = new Map([ - ['type', 'type_'], - ['default', 'default_'], - ]); - - private readonly requestMapper: Map = new Map([ - ['type_', 'type'], - ['default_', 'default'], - ]); - - async get(url: string, input: any, headers: Headers, retry: boolean = false): Promise { - const request = () => - axios.get(url, { - headers: { ...headers, ...this.getUserAgentHeader() }, - data: - Object.keys(input).length > 0 - ? HTTPLibrary.convertKeysWithMapper(input, this.requestMapper) - : undefined, - }); - - const response = retry - ? await this.retry(this.retryAttempts, request, this.retryDelayMs) - : await request(); - return HTTPLibrary.handleResponse(response); - } - - async post(url: string, input: any, headers: Headers, retry: boolean = false): Promise { - const request = () => - axios.post(url, HTTPLibrary.convertKeysWithMapper(input, this.requestMapper), { - headers: { ...headers, ...this.getUserAgentHeader() }, - }); - - const response = retry - ? await this.retry(this.retryAttempts, request, this.retryDelayMs) - : await request(); - - return HTTPLibrary.handleResponse(response); - } - - async delete(url: string, input: any, headers: Headers, retry: boolean = false): Promise { - const request = () => - axios.delete(url, { - headers: { ...headers, ...this.getUserAgentHeader() }, - data: HTTPLibrary.convertKeysWithMapper(input, this.requestMapper), - }); - - const response = retry - ? await this.retry(this.retryAttempts, request, this.retryDelayMs) - : await request(); - - return HTTPLibrary.handleResponse(response); - } - - async put(url: string, input: any, headers: Headers, retry: boolean = false): Promise { - const request = () => - axios.put(url, HTTPLibrary.convertKeysWithMapper(input, this.requestMapper), { - headers: { ...headers, ...this.getUserAgentHeader() }, - }); - - const response = retry - ? await this.retry(this.retryAttempts, request, this.retryDelayMs) - : await request(); - - return HTTPLibrary.handleResponse(response); - } - - async patch(url: string, input: any, headers: Headers, retry: boolean = false): Promise { - const request = () => - axios.patch(url, HTTPLibrary.convertKeysWithMapper(input, this.requestMapper), { - headers: { ...headers, ...this.getUserAgentHeader() }, - }); - - const response = retry - ? await this.retry(this.retryAttempts, request, this.retryDelayMs) - : await request(); - - return HTTPLibrary.handleResponse(response); - } - - async retry(retries: number, callbackFn: () => any, delay: number): Promise { - let result: any; - - try { - result = await callbackFn(); - } catch (e: any) { - if ((e as AxiosError).isAxiosError) { - if (e.response) { - if (![500, 503, 504].includes(e.response.status)) { - return e.response; - } - } - } - if (retries > 1) { - // eslint-disable-next-line no-promise-executor-return - await new Promise((resolve) => setTimeout(resolve, delay)); - result = await this.retry(retries - 1, callbackFn, delay * 2); - } else { - throw e; - } - } - - return result; - } - - private static handleResponse(response: any) { - if (response.status >= 400) { - throwHttpError(response); - } - - response.data = HTTPLibrary.convertKeysWithMapper(response.data, this.responseMapper); - - return response; - } - - private getUserAgentHeader(): Headers { - if (typeof window !== 'undefined') { - return {}; - } - return this.userAgentHeader; - } - - /** - *Converts keys in an object using a provided JSON mapper. - * @param {any} obj - The object to convert keys for. - * @param {Object} jsonMapper - The JSON mapper containing key mappings. - * @returns {any} - The object with converted keys. - */ - private static convertKeysWithMapper(obj: T, jsonMapper: Map): any { - if (!obj || typeof obj !== 'object') { - return obj; - } - - if (Array.isArray(obj)) { - return obj.map((item) => HTTPLibrary.convertKeysWithMapper(item, jsonMapper)); - } - - const convertedObj: Record = {}; - Object.entries(obj).forEach(([key, value]) => { - if (value !== undefined) { - const convertedKey = jsonMapper.get(key) || key; - convertedObj[convertedKey] = HTTPLibrary.convertKeysWithMapper(value, jsonMapper); - } - }); - - return convertedObj; - } -} diff --git a/src/http/QuerySerializer.ts b/src/http/QuerySerializer.ts deleted file mode 100644 index 7803158f..00000000 --- a/src/http/QuerySerializer.ts +++ /dev/null @@ -1,82 +0,0 @@ -export type Explode = boolean; -export type QueryStyles = 'form' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject'; -export type PathStyles = 'simple' | 'label' | 'matrix'; - -const styleMethods: Record = { - simple: (value: unknown, explode: boolean) => { - // Check if the value is an array - if (Array.isArray(value)) { - return explode ? value.join(',') : value.join(); - } - - // Check if the value is an object - if (typeof value === 'object' && value !== null) { - if (explode) { - // Serialize object with exploded format: "key=value,key2=value2" - return Object.entries(value) - .map(([parameterName, parameterValue]) => `${parameterName}=${parameterValue}`) - .join(','); - } - // Serialize object with non-exploded format: "key,value,key2,value2" - return Object.entries(value) - .flatMap(([parameterName, parameterValue]) => [parameterName, parameterValue]) - .join(','); - } - - // For primitive values - return String(value); - }, - - form: (parameterName: string, parameterValue: unknown, explode: boolean) => { - // Check if the parameterValue is an array - if (Array.isArray(parameterValue)) { - return explode - ? parameterValue.map((value) => `${parameterName}=${value}`).join('&') - : `${parameterName}=${parameterValue.join(',')}`; - } - - // Check if the parameterValue is an object - if (typeof parameterValue === 'object' && parameterValue !== null) { - if (explode) { - // Serialize object with exploded format: "key1=value1&key2=value2" - return Object.entries(parameterValue) - .map(([name, value]) => `${name}=${value}`) - .join('&'); - } - // Serialize object with non-exploded format: "key=key1,value1,key2,value2" - return `${parameterName}=${Object.entries(parameterValue) - .flatMap(([name, value]) => [name, value]) - .join(',')}`; - } - - // For primitive values - return `${parameterName}=${parameterValue}`; - }, -}; - -export function serializeQuery( - style: QueryStyles, - explode: Explode, - key: string, - value: unknown, -): string { - const method = styleMethods[style]; - if (!method) return ''; - return method(key, value, explode); -} - -export function serializePath( - style: PathStyles, - explode: Explode, - value: unknown, - key?: string, -): string { - const method = styleMethods[style]; - if (!method) return ''; - // The `simple` and `label` styles do not require a `key` - if (!key) { - return method(value, explode); - } else { - return method(key, value, explode); - } -} diff --git a/src/http/Response.ts b/src/http/Response.ts deleted file mode 100644 index 37be3fda..00000000 --- a/src/http/Response.ts +++ /dev/null @@ -1,4 +0,0 @@ -export default interface Response { - data: T; - headers: Record; -} diff --git a/src/http/errors/BadGateway.ts b/src/http/errors/BadGateway.ts deleted file mode 100644 index 9c6d289c..00000000 --- a/src/http/errors/BadGateway.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class BadGateway extends BaseHTTPError { - statusCode = 502; - - title = 'Bad Gateway'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/BadRequest.ts b/src/http/errors/BadRequest.ts deleted file mode 100644 index 7df6dd0e..00000000 --- a/src/http/errors/BadRequest.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class BadRequest extends BaseHTTPError { - statusCode = 400; - - title = 'Bad Request'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/Conflict.ts b/src/http/errors/Conflict.ts deleted file mode 100644 index 9f5a7508..00000000 --- a/src/http/errors/Conflict.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class Conflict extends BaseHTTPError { - statusCode = 409; - - title = 'Conflict'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/ExpectationFailed.ts b/src/http/errors/ExpectationFailed.ts deleted file mode 100644 index 22299f5b..00000000 --- a/src/http/errors/ExpectationFailed.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class ExpectationFailed extends BaseHTTPError { - statusCode = 417; - - title = 'Expectation Failed'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/FailedDependency.ts b/src/http/errors/FailedDependency.ts deleted file mode 100644 index ea99d2ca..00000000 --- a/src/http/errors/FailedDependency.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class FailedDependency extends BaseHTTPError { - statusCode = 424; - - title = 'Failed Dependency'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/Forbidden.ts b/src/http/errors/Forbidden.ts deleted file mode 100644 index 82ee9347..00000000 --- a/src/http/errors/Forbidden.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class Forbidden extends BaseHTTPError { - statusCode = 403; - - title = 'Forbidden'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/GatewayTimeout.ts b/src/http/errors/GatewayTimeout.ts deleted file mode 100644 index daa7af67..00000000 --- a/src/http/errors/GatewayTimeout.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class GatewayTimeout extends BaseHTTPError { - statusCode = 504; - - title = 'Gateway Timeout'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/Gone.ts b/src/http/errors/Gone.ts deleted file mode 100644 index a113c4d3..00000000 --- a/src/http/errors/Gone.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class Gone extends BaseHTTPError { - statusCode = 410; - - title = 'Gone'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/HttpVersionNotSupported.ts b/src/http/errors/HttpVersionNotSupported.ts deleted file mode 100644 index 4fb6f468..00000000 --- a/src/http/errors/HttpVersionNotSupported.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class HttpVersionNotSupported extends BaseHTTPError { - statusCode = 505; - - title = 'HTTP Version Not Supported'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/InternalServerError.ts b/src/http/errors/InternalServerError.ts deleted file mode 100644 index a06205a7..00000000 --- a/src/http/errors/InternalServerError.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class InternalServerError extends BaseHTTPError { - statusCode = 500; - - title = 'Internal Server Error'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/LengthRequired.ts b/src/http/errors/LengthRequired.ts deleted file mode 100644 index 5fe59484..00000000 --- a/src/http/errors/LengthRequired.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class LengthRequired extends BaseHTTPError { - statusCode = 411; - - title = 'LengthRequired'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/Locked.ts b/src/http/errors/Locked.ts deleted file mode 100644 index 7ef8fd9a..00000000 --- a/src/http/errors/Locked.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class Locked extends BaseHTTPError { - statusCode = 423; - - title = 'Locked'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/LoopDetected.ts b/src/http/errors/LoopDetected.ts deleted file mode 100644 index dfb598a8..00000000 --- a/src/http/errors/LoopDetected.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class LoopDetected extends BaseHTTPError { - statusCode = 508; - - title = 'Loop Detected'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/MethodNotAllowed.ts b/src/http/errors/MethodNotAllowed.ts deleted file mode 100644 index 870e5c32..00000000 --- a/src/http/errors/MethodNotAllowed.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class MethodNotAllowed extends BaseHTTPError { - statusCode = 405; - - title = 'Method Not Allowed'; - - allow?: string[]; - - constructor(detail: string = '', allow?: string[]) { - super(detail); - this.allow = allow; - } -} diff --git a/src/http/errors/MisdirectedRequest.ts b/src/http/errors/MisdirectedRequest.ts deleted file mode 100644 index f00f2124..00000000 --- a/src/http/errors/MisdirectedRequest.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class MisdirectedRequest extends BaseHTTPError { - statusCode = 421; - - title = 'Misdirected Request'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/NetworkAuthenticationRequired.ts b/src/http/errors/NetworkAuthenticationRequired.ts deleted file mode 100644 index 29267f39..00000000 --- a/src/http/errors/NetworkAuthenticationRequired.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class NetworkAuthenticationRequired extends BaseHTTPError { - statusCode = 511; - - title = 'Network Authentication Required'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/NotAcceptable.ts b/src/http/errors/NotAcceptable.ts deleted file mode 100644 index c2ad2e27..00000000 --- a/src/http/errors/NotAcceptable.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class NotAcceptable extends BaseHTTPError { - statusCode = 406; - - title = 'Not Acceptable'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/NotExtended.ts b/src/http/errors/NotExtended.ts deleted file mode 100644 index a1378340..00000000 --- a/src/http/errors/NotExtended.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class NotExtended extends BaseHTTPError { - statusCode = 510; - - title = 'Not Extended'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/NotFound.ts b/src/http/errors/NotFound.ts deleted file mode 100644 index 0df322b8..00000000 --- a/src/http/errors/NotFound.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class NotFound extends BaseHTTPError { - statusCode = 404; - - title = 'Not Found'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/NotImplemented.ts b/src/http/errors/NotImplemented.ts deleted file mode 100644 index 0e9e9e96..00000000 --- a/src/http/errors/NotImplemented.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class NotImplemented extends BaseHTTPError { - statusCode = 501; - - title = 'Not Implemented'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/PayloadTooLarge.ts b/src/http/errors/PayloadTooLarge.ts deleted file mode 100644 index ca40131e..00000000 --- a/src/http/errors/PayloadTooLarge.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class PayloadTooLarge extends BaseHTTPError { - statusCode = 413; - - title = 'Payload Too Large'; - - retryAfter: number | null; - - constructor(detail: string = '', retryAfter: number | null = null) { - super(detail); - this.retryAfter = retryAfter; - } -} diff --git a/src/http/errors/PaymentRequired.ts b/src/http/errors/PaymentRequired.ts deleted file mode 100644 index abbabbb8..00000000 --- a/src/http/errors/PaymentRequired.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class PaymentRequired extends BaseHTTPError { - statusCode = 402; - - title = 'Payment Required'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/PreconditionFailed.ts b/src/http/errors/PreconditionFailed.ts deleted file mode 100644 index 2e0b8f95..00000000 --- a/src/http/errors/PreconditionFailed.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class PreconditionFailed extends BaseHTTPError { - statusCode = 412; - - title = 'PreconditionFailed'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/PreconditionRequired.ts b/src/http/errors/PreconditionRequired.ts deleted file mode 100644 index 9d7b83ee..00000000 --- a/src/http/errors/PreconditionRequired.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class PreconditionRequired extends BaseHTTPError { - statusCode = 428; - - title = 'Precondition Required'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/ProxyAuthenticationRequired.ts b/src/http/errors/ProxyAuthenticationRequired.ts deleted file mode 100644 index 26e1bd51..00000000 --- a/src/http/errors/ProxyAuthenticationRequired.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { AuthenticateChallenge, BaseHTTPError } from './base'; - -export default class ProxyAuthenticationRequired extends BaseHTTPError { - statusCode = 407; - - title = 'Proxy Authentication Required'; - - proxyAuthenticate?: AuthenticateChallenge; - - constructor(detail: string = '', proxyAuthenticate?: AuthenticateChallenge) { - super(detail); - this.proxyAuthenticate = proxyAuthenticate; - } -} diff --git a/src/http/errors/RangeNotSatisfiable.ts b/src/http/errors/RangeNotSatisfiable.ts deleted file mode 100644 index 704e4ec0..00000000 --- a/src/http/errors/RangeNotSatisfiable.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class RangeNotSatisfiable extends BaseHTTPError { - statusCode = 416; - - title = 'Range Not Satisfiable'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/RequestHeaderFieldsTooLarge.ts b/src/http/errors/RequestHeaderFieldsTooLarge.ts deleted file mode 100644 index 4a34fb08..00000000 --- a/src/http/errors/RequestHeaderFieldsTooLarge.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class RequestHeaderFieldsTooLarge extends BaseHTTPError { - statusCode = 431; - - title = 'Request Header Fields Too Large'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/RequestTimeout.ts b/src/http/errors/RequestTimeout.ts deleted file mode 100644 index ba1a5c3a..00000000 --- a/src/http/errors/RequestTimeout.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class RequestTimeout extends BaseHTTPError { - statusCode = 408; - - title = 'Request Timeout'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/ServiceUnavailable.ts b/src/http/errors/ServiceUnavailable.ts deleted file mode 100644 index 8cd62e80..00000000 --- a/src/http/errors/ServiceUnavailable.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class ServiceUnavailable extends BaseHTTPError { - statusCode = 503; - - title = 'Service Unavailable'; - - retryAfter: number | null; - - constructor(detail: string = '', retryAfter: number | null = null) { - super(detail); - this.retryAfter = retryAfter; - } -} diff --git a/src/http/errors/TooEarly.ts b/src/http/errors/TooEarly.ts deleted file mode 100644 index b7f99c63..00000000 --- a/src/http/errors/TooEarly.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class TooEarly extends BaseHTTPError { - statusCode = 425; - - title = 'Too Early'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/TooManyRequests.ts b/src/http/errors/TooManyRequests.ts deleted file mode 100644 index eb5280d5..00000000 --- a/src/http/errors/TooManyRequests.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class TooManyRequests extends BaseHTTPError { - statusCode = 429; - - title = 'Too Many Requests'; - - retryAfter: number | null; - - constructor(detail: string = '', retryAfter: number | null = null) { - super(detail); - this.retryAfter = retryAfter; - } -} diff --git a/src/http/errors/Unauthorized.ts b/src/http/errors/Unauthorized.ts deleted file mode 100644 index 15da735b..00000000 --- a/src/http/errors/Unauthorized.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { AuthenticateChallenge, BaseHTTPError } from './base'; - -export default class Unauthorized extends BaseHTTPError { - statusCode = 401; - - title = 'Unauthorized'; - - wwwAuthenticate?: AuthenticateChallenge; - - constructor(detail: string = '', wwwAuthenticate?: AuthenticateChallenge) { - super(detail); - this.wwwAuthenticate = wwwAuthenticate; - } -} diff --git a/src/http/errors/UnavailableForLegalReasons.ts b/src/http/errors/UnavailableForLegalReasons.ts deleted file mode 100644 index 70e6d073..00000000 --- a/src/http/errors/UnavailableForLegalReasons.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class UnavailableForLegalReasons extends BaseHTTPError { - statusCode = 451; - - title = 'Unavailable For Legal Reasons'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/UnprocessableEntity.ts b/src/http/errors/UnprocessableEntity.ts deleted file mode 100644 index 70000c19..00000000 --- a/src/http/errors/UnprocessableEntity.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class UnprocessableEntity extends BaseHTTPError { - statusCode = 422; - - title = 'Unprocessable Entity'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/UnsufficientStorage.ts b/src/http/errors/UnsufficientStorage.ts deleted file mode 100644 index e61e12c3..00000000 --- a/src/http/errors/UnsufficientStorage.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class UnsufficientStorage extends BaseHTTPError { - statusCode = 507; - - title = 'Unsufficient Storage'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/UnsupportedMediaType.ts b/src/http/errors/UnsupportedMediaType.ts deleted file mode 100644 index a27f2428..00000000 --- a/src/http/errors/UnsupportedMediaType.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class UnsupportedMediaType extends BaseHTTPError { - statusCode = 415; - - title = 'Unsupported Media Type'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/UpgradeRequired.ts b/src/http/errors/UpgradeRequired.ts deleted file mode 100644 index 0ac17436..00000000 --- a/src/http/errors/UpgradeRequired.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class UpgradeRequired extends BaseHTTPError { - statusCode = 426; - - title = 'Upgrade Required'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/UriTooLong.ts b/src/http/errors/UriTooLong.ts deleted file mode 100644 index 56eca8b7..00000000 --- a/src/http/errors/UriTooLong.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class UriTooLong extends BaseHTTPError { - statusCode = 414; - - title = 'URI Too Long'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/VariantAlsoNegotiates.ts b/src/http/errors/VariantAlsoNegotiates.ts deleted file mode 100644 index 079df291..00000000 --- a/src/http/errors/VariantAlsoNegotiates.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class VariantAlsoNegotiates extends BaseHTTPError { - statusCode = 506; - - title = 'Variant Also Negotiates'; - - constructor(detail: string = '') { - super(detail); - } -} diff --git a/src/http/errors/base.ts b/src/http/errors/base.ts deleted file mode 100644 index f5ebd46f..00000000 --- a/src/http/errors/base.ts +++ /dev/null @@ -1,52 +0,0 @@ -export interface IHTTPError extends Error { - statusCode: number; -} - -export interface IHTTPErrorDescription extends IHTTPError { - type?: string; - title: string; - detail?: string; - instance?: string; -} - -export function isHTTPError(error: unknown): error is IHTTPError { - if (!error) { - return false; - } - return Number.isInteger((error as IHTTPError).statusCode); -} - -export function isHTTPIssue(error: unknown): error is IHTTPErrorDescription { - if (!error) { - return false; - } - return (error as IHTTPErrorDescription).title !== undefined && isHTTPError(error); -} - -export class BaseHTTPError extends Error implements IHTTPError { - public type?: string; - - public title: string = 'Internal Server Error'; - - public detail?: string; - - public instance?: string; - - public statusCode: number = 500; - - constructor(detail: string = '') { - super(detail || 'An Unknown HTTP Error Occurred'); - this.detail = detail; - this.stack = (new Error()).stack; - } -} - -export function isClientError(error: Error): boolean { - return isHTTPError(error); -} - -export function isServerError(e: Error): boolean { - return isHTTPError(e) && e.statusCode >= 500 && e.statusCode <= 599; -} - -export type AuthenticateChallenge = string | string[]; diff --git a/src/http/errors/index.ts b/src/http/errors/index.ts deleted file mode 100644 index 0f98f742..00000000 --- a/src/http/errors/index.ts +++ /dev/null @@ -1,83 +0,0 @@ -import BadRequest from './BadRequest'; -import Unauthorized from './Unauthorized'; -import PaymentRequired from './PaymentRequired'; -import Forbidden from './Forbidden'; -import NotFound from './NotFound'; -import MethodNotAllowed from './MethodNotAllowed'; -import NotAcceptable from './NotAcceptable'; -import ProxyAuthenticationRequired from './ProxyAuthenticationRequired'; -import RequestTimeout from './RequestTimeout'; -import Conflict from './Conflict'; -import Gone from './Gone'; -import LengthRequired from './LengthRequired'; -import PreconditionFailed from './PreconditionFailed'; -import PayloadTooLarge from './PayloadTooLarge'; -import UriTooLong from './UriTooLong'; -import UnsupportedMediaType from './UnsupportedMediaType'; -import RangeNotSatisfiable from './RangeNotSatisfiable'; -import ExpectationFailed from './ExpectationFailed'; -import MisdirectedRequest from './MisdirectedRequest'; -import UnprocessableEntity from './UnprocessableEntity'; -import Locked from './Locked'; -import FailedDependency from './FailedDependency'; -import TooEarly from './TooEarly'; -import UpgradeRequired from './UpgradeRequired'; -import PreconditionRequired from './PreconditionRequired'; -import TooManyRequests from './TooManyRequests'; -import RequestHeaderFieldsTooLarge from './RequestHeaderFieldsTooLarge'; -import UnavailableForLegalReasons from './UnavailableForLegalReasons'; -import InternalServerError from './InternalServerError'; -import NotImplemented from './NotImplemented'; -import BadGateway from './BadGateway'; -import ServiceUnavailable from './ServiceUnavailable'; -import GatewayTimeout from './GatewayTimeout'; -import HttpVersionNotSupported from './HttpVersionNotSupported'; -import VariantAlsoNegotiates from './VariantAlsoNegotiates'; -import UnsufficientStorage from './UnsufficientStorage'; -import LoopDetected from './LoopDetected'; -import NotExtended from './NotExtended'; -import NetworkAuthenticationRequired from './NetworkAuthenticationRequired'; -import { BaseHTTPError } from './base'; - -export { - BaseHTTPError, - BadRequest, - Unauthorized, - PaymentRequired, - Forbidden, - NotFound, - MethodNotAllowed, - NotAcceptable, - ProxyAuthenticationRequired, - RequestTimeout, - Conflict, - Gone, - LengthRequired, - PreconditionFailed, - PayloadTooLarge, - UriTooLong, - UnsupportedMediaType, - RangeNotSatisfiable, - ExpectationFailed, - MisdirectedRequest, - UnprocessableEntity, - Locked, - FailedDependency, - TooEarly, - UpgradeRequired, - PreconditionRequired, - TooManyRequests, - RequestHeaderFieldsTooLarge, - UnavailableForLegalReasons, - InternalServerError, - NotImplemented, - BadGateway, - ServiceUnavailable, - GatewayTimeout, - HttpVersionNotSupported, - VariantAlsoNegotiates, - UnsufficientStorage, - LoopDetected, - NotExtended, - NetworkAuthenticationRequired, -}; diff --git a/src/http/httpExceptions.ts b/src/http/httpExceptions.ts deleted file mode 100644 index 45c8fe16..00000000 --- a/src/http/httpExceptions.ts +++ /dev/null @@ -1,132 +0,0 @@ -import { - BaseHTTPError, - BadRequest, - Unauthorized, - PaymentRequired, - Forbidden, - NotFound, - MethodNotAllowed, - NotAcceptable, - ProxyAuthenticationRequired, - RequestTimeout, - Conflict, - Gone, - LengthRequired, - PreconditionFailed, - PayloadTooLarge, - UriTooLong, - UnsupportedMediaType, - RangeNotSatisfiable, - ExpectationFailed, - MisdirectedRequest, - UnprocessableEntity, - Locked, - FailedDependency, - TooEarly, - UpgradeRequired, - PreconditionRequired, - TooManyRequests, - RequestHeaderFieldsTooLarge, - UnavailableForLegalReasons, - InternalServerError, - NotImplemented, - BadGateway, - ServiceUnavailable, - GatewayTimeout, - HttpVersionNotSupported, - VariantAlsoNegotiates, - UnsufficientStorage, - LoopDetected, - NotExtended, - NetworkAuthenticationRequired, -} from './errors'; - -interface HttpResponseWithError { - status: number; - headers: any; - data?: any; -} - -interface NumberToClass { - [key: number]: any; -} - -const statusCodeToErrorFunction: NumberToClass = { - 400: BadRequest, - 401: Unauthorized, - 402: PaymentRequired, - 403: Forbidden, - 404: NotFound, - 405: MethodNotAllowed, - 406: NotAcceptable, - 407: ProxyAuthenticationRequired, - 408: RequestTimeout, - 409: Conflict, - 410: Gone, - 411: LengthRequired, - 412: PreconditionFailed, - 413: PayloadTooLarge, - 414: UriTooLong, - 415: UnsupportedMediaType, - 416: RangeNotSatisfiable, - 417: ExpectationFailed, - 421: MisdirectedRequest, - 422: UnprocessableEntity, - 423: Locked, - 424: FailedDependency, - 425: TooEarly, - 426: UpgradeRequired, - 428: PreconditionRequired, - 429: TooManyRequests, - 431: RequestHeaderFieldsTooLarge, - 451: UnavailableForLegalReasons, - 500: InternalServerError, - 501: NotImplemented, - 502: BadGateway, - 503: ServiceUnavailable, - 504: GatewayTimeout, - 505: HttpVersionNotSupported, - 506: VariantAlsoNegotiates, - 507: UnsufficientStorage, - 508: LoopDetected, - 510: NotExtended, - 511: NetworkAuthenticationRequired, -}; - -/** - * @summary This function will throw an error. - * - * @param {HttpResponseWithError} response - the response from a request, must contain a status and data fields - * @throws {Error} - an http error - */ -export default function throwHttpError(response: HttpResponseWithError): never { - let error: BaseHTTPError = new BaseHTTPError(response.data); - switch (response.status) { - case 401: - error = new Unauthorized(response.data, response.headers['WWW-Authenticate']); - case 405: - // this indicates a bug in the spec if it allows a method that the server rejects - error = new MethodNotAllowed(response.data, response.headers.allowed); - case 407: - error = new ProxyAuthenticationRequired( - response.data, - response.headers['Proxy-Authenticate'], - ); - case 413: - error = new PayloadTooLarge(response.data, response.headers['Retry-After']); - case 429: - error = new TooManyRequests(response.data, response.headers['Retry-After']); - case 503: - error = new ServiceUnavailable(response.data, response.headers['Retry-After']); - default: - if (response.status in statusCodeToErrorFunction) { - error = new statusCodeToErrorFunction[response.status](response.data); - } else { - const error = new BaseHTTPError(response.data); - error.statusCode = response.status; - error.title = 'unknown error'; - } - } - - throw error; -} diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index 6a37e864..00000000 --- a/src/index.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { ActivitiesService } from './services/activities/Activities'; -import { ButlerService } from './services/butler/Butler'; -import { HubsService } from './services/hubs/Hubs'; -import { LibraryService } from './services/library/Library'; -import { LogService } from './services/log/Log'; -import { MediaService } from './services/media/Media'; -import { PlaylistsService } from './services/playlists/Playlists'; -import { SearchService } from './services/search/Search'; -import { SecurityService } from './services/security/Security'; -import { ServerService } from './services/server/Server'; -import { SessionsService } from './services/sessions/Sessions'; -import { UpdaterService } from './services/updater/Updater'; -import { VideoService } from './services/video/Video'; - -export * from './models'; - -export * as ActivitiesModels from './services/activities'; -export * as ButlerModels from './services/butler'; -export * as HubsModels from './services/hubs'; -export * as LibraryModels from './services/library'; -export * as LogModels from './services/log'; -export * as PlaylistsModels from './services/playlists'; -export * as SearchModels from './services/search'; -export * as SecurityModels from './services/security'; -export * as ServerModels from './services/server'; -export * as SessionsModels from './services/sessions'; -export * as UpdaterModels from './services/updater'; -export * as VideoModels from './services/video'; - -type Config = { - apiKey?: string; - apiKeyHeader?: string; -}; - -export * from './http/errors'; - -export class PlexSDK { - public activities: ActivitiesService; - public butler: ButlerService; - public hubs: HubsService; - public library: LibraryService; - public log: LogService; - public media: MediaService; - public playlists: PlaylistsService; - public search: SearchService; - public security: SecurityService; - public server: ServerService; - public sessions: SessionsService; - public updater: UpdaterService; - public video: VideoService; - - constructor({ apiKey = '', apiKeyHeader = 'X-Plex-Token' }: Config) { - this.activities = new ActivitiesService(apiKey, apiKeyHeader); - this.butler = new ButlerService(apiKey, apiKeyHeader); - this.hubs = new HubsService(apiKey, apiKeyHeader); - this.library = new LibraryService(apiKey, apiKeyHeader); - this.log = new LogService(apiKey, apiKeyHeader); - this.media = new MediaService(apiKey, apiKeyHeader); - this.playlists = new PlaylistsService(apiKey, apiKeyHeader); - this.search = new SearchService(apiKey, apiKeyHeader); - this.security = new SecurityService(apiKey, apiKeyHeader); - this.server = new ServerService(apiKey, apiKeyHeader); - this.sessions = new SessionsService(apiKey, apiKeyHeader); - this.updater = new UpdaterService(apiKey, apiKeyHeader); - this.video = new VideoService(apiKey, apiKeyHeader); - } - - setBaseUrl(url: string): void { - this.activities.setBaseUrl(url); - this.butler.setBaseUrl(url); - this.hubs.setBaseUrl(url); - this.library.setBaseUrl(url); - this.log.setBaseUrl(url); - this.media.setBaseUrl(url); - this.playlists.setBaseUrl(url); - this.search.setBaseUrl(url); - this.security.setBaseUrl(url); - this.server.setBaseUrl(url); - this.sessions.setBaseUrl(url); - this.updater.setBaseUrl(url); - this.video.setBaseUrl(url); - } - - setApiKey(key: string, header: string = 'X-Plex-Token') { - this.activities.setApiKey(key, header); - this.butler.setApiKey(key, header); - this.hubs.setApiKey(key, header); - this.library.setApiKey(key, header); - this.log.setApiKey(key, header); - this.media.setApiKey(key, header); - this.playlists.setApiKey(key, header); - this.search.setApiKey(key, header); - this.security.setApiKey(key, header); - this.server.setApiKey(key, header); - this.sessions.setApiKey(key, header); - this.updater.setApiKey(key, header); - this.video.setApiKey(key, header); - } -} diff --git a/src/models.ts b/src/models.ts deleted file mode 100644 index 5957fb27..00000000 --- a/src/models.ts +++ /dev/null @@ -1,28 +0,0 @@ -export type { Download } from './services/updater/models/Download'; -export type { Force } from './services/playlists/models/Force'; -export type { GetAvailableClientsResponse } from './services/server/models/GetAvailableClientsResponse'; -export type { GetButlerTasksResponse } from './services/butler/models/GetButlerTasksResponse'; -export type { GetDevicesResponse } from './services/server/models/GetDevicesResponse'; -export type { GetMyPlexAccountResponse } from './services/server/models/GetMyPlexAccountResponse'; -export type { GetOnDeckResponse } from './services/library/models/GetOnDeckResponse'; -export type { GetRecentlyAddedResponse } from './services/library/models/GetRecentlyAddedResponse'; -export type { GetSearchResultsResponse } from './services/search/models/GetSearchResultsResponse'; -export type { GetServerActivitiesResponse } from './services/activities/models/GetServerActivitiesResponse'; -export type { GetServerCapabilitiesResponse } from './services/server/models/GetServerCapabilitiesResponse'; -export type { GetServerIdentityResponse } from './services/server/models/GetServerIdentityResponse'; -export type { GetServerListResponse } from './services/server/models/GetServerListResponse'; -export type { GetTranscodeSessionsResponse } from './services/sessions/models/GetTranscodeSessionsResponse'; -export type { IncludeDetails } from './services/library/models/IncludeDetails'; -export type { Level } from './services/log/models/Level'; -export type { MinSize } from './services/server/models/MinSize'; -export type { OnlyTransient } from './services/hubs/models/OnlyTransient'; -export type { PlaylistType } from './services/playlists/models/PlaylistType'; -export type { Scope } from './services/security/models/Scope'; -export type { SecurityType } from './services/security/models/SecurityType'; -export type { Skip } from './services/updater/models/Skip'; -export type { Smart } from './services/playlists/models/Smart'; -export type { State } from './services/video/models/State'; -export type { TaskName } from './services/butler/models/TaskName'; -export type { Tonight } from './services/updater/models/Tonight'; -export type { Type } from './services/playlists/models/Type'; -export type { Upscale } from './services/server/models/Upscale'; diff --git a/src/services/README.md b/src/services/README.md deleted file mode 100644 index 17ce2b00..00000000 --- a/src/services/README.md +++ /dev/null @@ -1,1977 +0,0 @@ -# PlexSDK Services -A list of all services and services methods. -- Services - - - [Server](#server) - - - [Media](#media) - - - [Activities](#activities) - - - [Butler](#butler) - - - [Hubs](#hubs) - - - [Search](#search) - - - [Library](#library) - - - [Log](#log) - - - [Playlists](#playlists) - - - [Security](#security) - - - [Sessions](#sessions) - - - [Updater](#updater) - - - [Video](#video) -- [All Methods](#all-methods) - - -## Server - -| Method | Description| -| :-------- | :----------| -| [getServerCapabilities](#getservercapabilities) | Server Capabilities | -| [getServerPreferences](#getserverpreferences) | Get Server Preferences | -| [getAvailableClients](#getavailableclients) | Get Available Clients | -| [getDevices](#getdevices) | Get Devices | -| [getServerIdentity](#getserveridentity) | Get Server Identity | -| [getMyPlexAccount](#getmyplexaccount) | Get MyPlex Account | -| [getResizedPhoto](#getresizedphoto) | Get a Resized Photo | -| [getServerList](#getserverlist) | Get Server List | - - -## Media - -| Method | Description| -| :-------- | :----------| -| [markPlayed](#markplayed) | Mark Media Played | -| [markUnplayed](#markunplayed) | Mark Media Unplayed | -| [updatePlayProgress](#updateplayprogress) | Update Media Play Progress | - - -## Activities - -| Method | Description| -| :-------- | :----------| -| [getServerActivities](#getserveractivities) | Get Server Activities | -| [cancelServerActivities](#cancelserveractivities) | Cancel Server Activities | - - -## Butler - -| Method | Description| -| :-------- | :----------| -| [startAllTasks](#startalltasks) | Start all Butler tasks | -| [getButlerTasks](#getbutlertasks) | Get Butler tasks | -| [stopAllTasks](#stopalltasks) | Stop all Butler tasks | -| [startTask](#starttask) | Start a single Butler task | -| [stopTask](#stoptask) | Stop a single Butler task | - - -## Hubs - -| Method | Description| -| :-------- | :----------| -| [getGlobalHubs](#getglobalhubs) | Get Global Hubs | -| [getLibraryHubs](#getlibraryhubs) | Get library specific hubs | - - -## Search - -| Method | Description| -| :-------- | :----------| -| [performSearch](#performsearch) | Perform a search | -| [performVoiceSearch](#performvoicesearch) | Perform a voice search | -| [getSearchResults](#getsearchresults) | Get Search Results | - - -## Library - -| Method | Description| -| :-------- | :----------| -| [getFileHash](#getfilehash) | Get Hash Value | -| [getRecentlyAdded](#getrecentlyadded) | Get Recently Added | -| [getLibraries](#getlibraries) | Get All Libraries | -| [getLibrary](#getlibrary) | Get Library Details | -| [deleteLibrary](#deletelibrary) | Delete Library Section | -| [getLibraryItems](#getlibraryitems) | Get Library Items | -| [refreshLibrary](#refreshlibrary) | Refresh Library | -| [getLatestLibraryItems](#getlatestlibraryitems) | Get Latest Library Items | -| [getCommonLibraryItems](#getcommonlibraryitems) | Get Common Library Items | -| [getMetadata](#getmetadata) | Get Items Metadata | -| [getMetadataChildren](#getmetadatachildren) | Get Items Children | -| [getOnDeck](#getondeck) | Get On Deck | - - -## Log - -| Method | Description| -| :-------- | :----------| -| [logMultiLine](#logmultiline) | Logging a multi-line message | -| [logLine](#logline) | Logging a single line message. | -| [enablePaperTrail](#enablepapertrail) | Enabling Papertrail | - - -## Playlists - -| Method | Description| -| :-------- | :----------| -| [createPlaylist](#createplaylist) | Create a Playlist | -| [getPlaylists](#getplaylists) | Get All Playlists | -| [getPlaylist](#getplaylist) | Retrieve Playlist | -| [deletePlaylist](#deleteplaylist) | Deletes a Playlist | -| [updatePlaylist](#updateplaylist) | Update a Playlist | -| [getPlaylistContents](#getplaylistcontents) | Retrieve Playlist Contents | -| [clearPlaylistContents](#clearplaylistcontents) | Delete Playlist Contents | -| [addPlaylistContents](#addplaylistcontents) | Adding to a Playlist | -| [uploadPlaylist](#uploadplaylist) | Upload Playlist | - - -## Security - -| Method | Description| -| :-------- | :----------| -| [getTransientToken](#gettransienttoken) | Get a Transient Token. | -| [getSourceConnectionInformation](#getsourceconnectioninformation) | Get Source Connection Information | - - -## Sessions - -| Method | Description| -| :-------- | :----------| -| [getSessions](#getsessions) | Get Active Sessions | -| [getSessionHistory](#getsessionhistory) | Get Session History | -| [getTranscodeSessions](#gettranscodesessions) | Get Transcode Sessions | -| [stopTranscodeSession](#stoptranscodesession) | Stop a Transcode Session | - - -## Updater - -| Method | Description| -| :-------- | :----------| -| [getUpdateStatus](#getupdatestatus) | Querying status of updates | -| [checkForUpdates](#checkforupdates) | Checking for updates | -| [applyUpdates](#applyupdates) | Apply Updates | - - -## Video - -| Method | Description| -| :-------- | :----------| -| [startUniversalTranscode](#startuniversaltranscode) | Start Universal Transcode | -| [getTimeline](#gettimeline) | Get the timeline for a media item | - - - - -## All Methods - - -### **getServerCapabilities** -Server Capabilities -- HTTP Method: GET -- Endpoint: / - - -**Return Type** - -GetServerCapabilitiesResponse - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.server.getServerCapabilities(); - console.log(result.data); -})(); - -``` - -### **getServerPreferences** -Get Server Preferences -- HTTP Method: GET -- Endpoint: /:/prefs - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.server.getServerPreferences(); - console.log(result.data); -})(); - -``` - -### **getAvailableClients** -Get Available Clients -- HTTP Method: GET -- Endpoint: /clients - - -**Return Type** - -GetAvailableClientsResponse - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.server.getAvailableClients(); - console.log(result.data); -})(); - -``` - -### **getDevices** -Get Devices -- HTTP Method: GET -- Endpoint: /devices - - -**Return Type** - -GetDevicesResponse - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.server.getDevices(); - console.log(result.data); -})(); - -``` - -### **getServerIdentity** -Get Server Identity -- HTTP Method: GET -- Endpoint: /identity - - -**Return Type** - -GetServerIdentityResponse - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.server.getServerIdentity(); - console.log(result.data); -})(); - -``` - -### **getMyPlexAccount** -Get MyPlex Account -- HTTP Method: GET -- Endpoint: /myplex/account - - -**Return Type** - -GetMyPlexAccountResponse - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.server.getMyPlexAccount(); - console.log(result.data); -})(); - -``` - -### **getResizedPhoto** -Get a Resized Photo -- HTTP Method: GET -- Endpoint: /photo/:/transcode - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| width | number | The width for the resized photo | -| height | number | The height for the resized photo | -| opacity | number | The opacity for the resized photo | -| blur | number | The width for the resized photo | -| minSize | [MinSize](/src/models/README.md#minsize) | images are always scaled proportionally. A value of '1' in minSize will make the smaller native dimension the dimension resized against. | -| upscale | [Upscale](/src/models/README.md#upscale) | allow images to be resized beyond native dimensions. | -| url | string | path to image within Plex | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.server.getResizedPhoto( - 110, - 165, - 100, - 4000, - 1, - 1, - '/library/metadata/49564/thumb/1654258204', - ); - console.log(result.data); -})(); - -``` - -### **getServerList** -Get Server List -- HTTP Method: GET -- Endpoint: /servers - - -**Return Type** - -GetServerListResponse - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.server.getServerList(); - console.log(result.data); -})(); - -``` - - -### **markPlayed** -Mark Media Played -- HTTP Method: GET -- Endpoint: /:/scrobble - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| key | number | The media key to mark as played | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.media.markPlayed(59398); - console.log(result.data); -})(); - -``` - -### **markUnplayed** -Mark Media Unplayed -- HTTP Method: GET -- Endpoint: /:/unscrobble - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| key | number | The media key to mark as Unplayed | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.media.markUnplayed(59398); - console.log(result.data); -})(); - -``` - -### **updatePlayProgress** -Update Media Play Progress -- HTTP Method: POST -- Endpoint: /:/progress - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| key | string | the media key | -| time | number | The time, in milliseconds, used to set the media playback progress. | -| state | string | The playback state of the media item. | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.media.updatePlayProgress('key', 90469787.90055934, 'state'); - console.log(result.data); -})(); - -``` - - -### **getServerActivities** -Get Server Activities -- HTTP Method: GET -- Endpoint: /activities - - -**Return Type** - -GetServerActivitiesResponse - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.activities.getServerActivities(); - console.log(result.data); -})(); - -``` - -### **cancelServerActivities** -Cancel Server Activities -- HTTP Method: DELETE -- Endpoint: /activities/{activityUUID} - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| activityUuid | string | The UUID of the activity to cancel. | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.activities.cancelServerActivities('activityUUID'); - console.log(result.data); -})(); - -``` - - -### **startAllTasks** -Start all Butler tasks -- HTTP Method: POST -- Endpoint: /butler - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.butler.startAllTasks(); - console.log(result.data); -})(); - -``` - -### **getButlerTasks** -Get Butler tasks -- HTTP Method: GET -- Endpoint: /butler - - -**Return Type** - -GetButlerTasksResponse - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.butler.getButlerTasks(); - console.log(result.data); -})(); - -``` - -### **stopAllTasks** -Stop all Butler tasks -- HTTP Method: DELETE -- Endpoint: /butler - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.butler.stopAllTasks(); - console.log(result.data); -})(); - -``` - -### **startTask** -Start a single Butler task -- HTTP Method: POST -- Endpoint: /butler/{taskName} - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| taskName | [TaskName](/src/models/README.md#taskname) | the name of the task to be started. | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.butler.startTask('GenerateChapterThumbs'); - console.log(result.data); -})(); - -``` - -### **stopTask** -Stop a single Butler task -- HTTP Method: DELETE -- Endpoint: /butler/{taskName} - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| taskName | [TaskName](/src/models/README.md#taskname) | The name of the task to be started. | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.butler.stopTask('DeepMediaAnalysis'); - console.log(result.data); -})(); - -``` - - -### **getGlobalHubs** -Get Global Hubs -- HTTP Method: GET -- Endpoint: /hubs - - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| count | number | The number of items to return with each hub. | -| onlyTransient | [OnlyTransient](/src/models/README.md#onlytransient) | Only return hubs which are "transient", meaning those which are prone to changing after media playback or addition (e.g. On Deck, or Recently Added). | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.hubs.getGlobalHubs({ count: 56455806.18512213, onlyTransient: 1 }); - console.log(result.data); -})(); - -``` - -### **getLibraryHubs** -Get library specific hubs -- HTTP Method: GET -- Endpoint: /hubs/sections/{sectionId} - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| sectionId | number | the Id of the library to query | - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| count | number | The number of items to return with each hub. | -| onlyTransient | [OnlyTransient](/src/models/README.md#onlytransient) | Only return hubs which are "transient", meaning those which are prone to changing after media playback or addition (e.g. On Deck, or Recently Added). | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.hubs.getLibraryHubs(14224427.485252097, { - count: 59167335.01182026, - onlyTransient: 1, - }); - console.log(result.data); -})(); - -``` - - -### **performSearch** -Perform a search -- HTTP Method: GET -- Endpoint: /hubs/search - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| query | string | The query term | - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| sectionId | number | This gives context to the search, and can result in re-ordering of search result hubs | -| limit | number | The number of items to return per hub | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.search.performSearch('arnold', { - sectionId: 23503236.39517291, - limit: 5, - }); - console.log(result.data); -})(); - -``` - -### **performVoiceSearch** -Perform a voice search -- HTTP Method: GET -- Endpoint: /hubs/search/voice - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| query | string | The query term | - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| sectionId | number | This gives context to the search, and can result in re-ordering of search result hubs | -| limit | number | The number of items to return per hub | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.search.performVoiceSearch('dead+poop', { - sectionId: 49725001.21318659, - limit: 5, - }); - console.log(result.data); -})(); - -``` - -### **getSearchResults** -Get Search Results -- HTTP Method: GET -- Endpoint: /search - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| query | string | The search query string to use | - - - -**Return Type** - -GetSearchResultsResponse - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.search.getSearchResults('110'); - console.log(result.data); -})(); - -``` - - -### **getFileHash** -Get Hash Value -- HTTP Method: GET -- Endpoint: /library/hashes - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| url | string | This is the path to the local file, must be prefixed by `file://` | - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| type | number | Item type | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.library.getFileHash('file://C:Image.png&type=13', { - type: 57131492.35348597, - }); - console.log(result.data); -})(); - -``` - -### **getRecentlyAdded** -Get Recently Added -- HTTP Method: GET -- Endpoint: /library/recentlyAdded - - -**Return Type** - -GetRecentlyAddedResponse - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.library.getRecentlyAdded(); - console.log(result.data); -})(); - -``` - -### **getLibraries** -Get All Libraries -- HTTP Method: GET -- Endpoint: /library/sections - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.library.getLibraries(); - console.log(result.data); -})(); - -``` - -### **getLibrary** -Get Library Details -- HTTP Method: GET -- Endpoint: /library/sections/{sectionId} - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| sectionId | number | the Id of the library to query | - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| includeDetails | [IncludeDetails](/src/models/README.md#includedetails) | Whether or not to include details for a section (types, filters, and sorts).
Only exists for backwards compatibility, media providers other than the server libraries have it on always.
| - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.library.getLibrary(1000, { includeDetails: 42 }); - console.log(result.data); -})(); - -``` - -### **deleteLibrary** -Delete Library Section -- HTTP Method: DELETE -- Endpoint: /library/sections/{sectionId} - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| sectionId | number | the Id of the library to query | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.library.deleteLibrary(1000); - console.log(result.data); -})(); - -``` - -### **getLibraryItems** -Get Library Items -- HTTP Method: GET -- Endpoint: /library/sections/{sectionId}/all - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| sectionId | number | the Id of the library to query | - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| type | number | item type | -| filter | string | the filter parameter | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.library.getLibraryItems(5918142.371238574, { - type: -7809061.492073655, - filter: 'filter', - }); - console.log(result.data); -})(); - -``` - -### **refreshLibrary** -Refresh Library -- HTTP Method: GET -- Endpoint: /library/sections/{sectionId}/refresh - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| sectionId | number | the Id of the library to refresh | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.library.refreshLibrary(96299696.9761284); - console.log(result.data); -})(); - -``` - -### **getLatestLibraryItems** -Get Latest Library Items -- HTTP Method: GET -- Endpoint: /library/sections/{sectionId}/latest - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| sectionId | number | the Id of the library to query | -| type | number | item type | - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| filter | string | the filter parameter | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.library.getLatestLibraryItems(92402469.6477915, -96400116.97826156, { - filter: 'filter', - }); - console.log(result.data); -})(); - -``` - -### **getCommonLibraryItems** -Get Common Library Items -- HTTP Method: GET -- Endpoint: /library/sections/{sectionId}/common - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| sectionId | number | the Id of the library to query | -| type | number | item type | - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| filter | string | the filter parameter | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.library.getCommonLibraryItems(10111915.895296082, 55224735.92815569, { - filter: 'filter', - }); - console.log(result.data); -})(); - -``` - -### **getMetadata** -Get Items Metadata -- HTTP Method: GET -- Endpoint: /library/metadata/{ratingKey} - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| ratingKey | number | the id of the library item to return the children of. | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.library.getMetadata(62182009.76385683); - console.log(result.data); -})(); - -``` - -### **getMetadataChildren** -Get Items Children -- HTTP Method: GET -- Endpoint: /library/metadata/{ratingKey}/children - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| ratingKey | number | the id of the library item to return the children of. | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.library.getMetadataChildren(11669243.106740937); - console.log(result.data); -})(); - -``` - -### **getOnDeck** -Get On Deck -- HTTP Method: GET -- Endpoint: /library/onDeck - - -**Return Type** - -GetOnDeckResponse - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.library.getOnDeck(); - console.log(result.data); -})(); - -``` - - -### **logMultiLine** -Logging a multi-line message -- HTTP Method: POST -- Endpoint: /log - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.log.logMultiLine(); - console.log(result.data); -})(); - -``` - -### **logLine** -Logging a single line message. -- HTTP Method: GET -- Endpoint: /log - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| level | [Level](/src/models/README.md#level) | An integer log level to write to the PMS log with.
0: Error
1: Warning
2: Info
3: Debug
4: Verbose
| -| message | string | The text of the message to write to the log. | -| source | string | a string indicating the source of the message. | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.log.logLine(2, 'message', 'source'); - console.log(result.data); -})(); - -``` - -### **enablePaperTrail** -Enabling Papertrail -- HTTP Method: GET -- Endpoint: /log/networked - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.log.enablePaperTrail(); - console.log(result.data); -})(); - -``` - - -### **createPlaylist** -Create a Playlist -- HTTP Method: POST -- Endpoint: /playlists - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| title | string | name of the playlist | -| type | [Type](/src/models/README.md#type) | type of playlist to create | -| smart | [Smart](/src/models/README.md#smart) | whether the playlist is smart or not | - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| uri | string | the content URI for the playlist | -| playQueueId | number | the play queue to copy to a playlist | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.playlists.createPlaylist('title', 'audio', 42, { - uri: 'uri', - playQueueID: -22282333.505305633, - }); - console.log(result.data); -})(); - -``` - -### **getPlaylists** -Get All Playlists -- HTTP Method: GET -- Endpoint: /playlists/all - - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| playlistType | [PlaylistType](/src/models/README.md#playlisttype) | limit to a type of playlist. | -| smart | [Smart](/src/models/README.md#smart) | type of playlists to return (default is all). | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.playlists.getPlaylists({ playlistType: 'photo', smart: 1 }); - console.log(result.data); -})(); - -``` - -### **getPlaylist** -Retrieve Playlist -- HTTP Method: GET -- Endpoint: /playlists/{playlistID} - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| playlistId | number | the ID of the playlist | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.playlists.getPlaylist(25521232.224839047); - console.log(result.data); -})(); - -``` - -### **deletePlaylist** -Deletes a Playlist -- HTTP Method: DELETE -- Endpoint: /playlists/{playlistID} - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| playlistId | number | the ID of the playlist | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.playlists.deletePlaylist(-60675901.030656695); - console.log(result.data); -})(); - -``` - -### **updatePlaylist** -Update a Playlist -- HTTP Method: PUT -- Endpoint: /playlists/{playlistID} - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| playlistId | number | the ID of the playlist | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.playlists.updatePlaylist(65200160.70787519); - console.log(result.data); -})(); - -``` - -### **getPlaylistContents** -Retrieve Playlist Contents -- HTTP Method: GET -- Endpoint: /playlists/{playlistID}/items - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| playlistId | number | the ID of the playlist | -| type | number | the metadata type of the item to return | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.playlists.getPlaylistContents(62167005.120096, 2249491.135525167); - console.log(result.data); -})(); - -``` - -### **clearPlaylistContents** -Delete Playlist Contents -- HTTP Method: DELETE -- Endpoint: /playlists/{playlistID}/items - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| playlistId | number | the ID of the playlist | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.playlists.clearPlaylistContents(24703702.974021226); - console.log(result.data); -})(); - -``` - -### **addPlaylistContents** -Adding to a Playlist -- HTTP Method: PUT -- Endpoint: /playlists/{playlistID}/items - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| playlistId | number | the ID of the playlist | -| uri | string | the content URI for the playlist | -| playQueueId | number | the play queue to add to a playlist | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.playlists.addPlaylistContents(-3444881.095142722, 'library://..', 123); - console.log(result.data); -})(); - -``` - -### **uploadPlaylist** -Upload Playlist -- HTTP Method: POST -- Endpoint: /playlists/upload - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| path | string | 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.
| -| force | [Force](/src/models/README.md#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.
| - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.playlists.uploadPlaylist('/home/barkley/playlist.m3u', 1); - console.log(result.data); -})(); - -``` - - -### **getTransientToken** -Get a Transient Token. -- HTTP Method: GET -- Endpoint: /security/token - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| type | [SecurityType](/src/models/README.md#securitytype) | `delegation` - This is the only supported `type` parameter. | -| scope | [Scope](/src/models/README.md#scope) | `all` - This is the only supported `scope` parameter. | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.security.getTransientToken('delegation', 'all'); - console.log(result.data); -})(); - -``` - -### **getSourceConnectionInformation** -Get Source Connection Information -- HTTP Method: GET -- Endpoint: /security/resources - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| source | string | The source identifier with an included prefix. | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.security.getSourceConnectionInformation( - 'provider://provider-identifier', - ); - console.log(result.data); -})(); - -``` - - -### **getSessions** -Get Active Sessions -- HTTP Method: GET -- Endpoint: /status/sessions - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.sessions.getSessions(); - console.log(result.data); -})(); - -``` - -### **getSessionHistory** -Get Session History -- HTTP Method: GET -- Endpoint: /status/sessions/history/all - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.sessions.getSessionHistory(); - console.log(result.data); -})(); - -``` - -### **getTranscodeSessions** -Get Transcode Sessions -- HTTP Method: GET -- Endpoint: /transcode/sessions - - -**Return Type** - -GetTranscodeSessionsResponse - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.sessions.getTranscodeSessions(); - console.log(result.data); -})(); - -``` - -### **stopTranscodeSession** -Stop a Transcode Session -- HTTP Method: DELETE -- Endpoint: /transcode/sessions/{sessionKey} - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| sessionKey | string | the Key of the transcode session to stop | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.sessions.stopTranscodeSession('zz7llzqlx8w9vnrsbnwhbmep'); - console.log(result.data); -})(); - -``` - - -### **getUpdateStatus** -Querying status of updates -- HTTP Method: GET -- Endpoint: /updater/status - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.updater.getUpdateStatus(); - console.log(result.data); -})(); - -``` - -### **checkForUpdates** -Checking for updates -- HTTP Method: PUT -- Endpoint: /updater/check - - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| download | [Download](/src/models/README.md#download) | Indicate that you want to start download any updates found. | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.updater.checkForUpdates({ download: 'foo' }); - console.log(result.data); -})(); - -``` - -### **applyUpdates** -Apply Updates -- HTTP Method: PUT -- Endpoint: /updater/apply - - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| tonight | [Tonight](/src/models/README.md#tonight) | Indicate that you want the update to run during the next Butler execution. Omitting this or setting it to false indicates that the update should install | -| skip | [Skip](/src/models/README.md#skip) | Indicate that the latest version should be marked as skipped. The entry for this version will have the `state` set to `skipped`. | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.updater.applyUpdates({ tonight: 'foo', skip: 1 }); - console.log(result.data); -})(); - -``` - - -### **startUniversalTranscode** -Start Universal Transcode -- HTTP Method: GET -- Endpoint: /video/:/transcode/universal/start.mpd - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| hasMde | number | Whether the media item has MDE | -| path | string | The path to the media item to transcode | -| mediaIndex | number | The index of the media item to transcode | -| partIndex | number | The index of the part to transcode | -| protocol | string | The protocol to use for the transcode session | - -**Optional Parameters** - -Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'} - -| Name | Type| Description | -| :-------- | :----------| :----------| -| fastSeek | number | Whether to use fast seek or not | -| directPlay | number | Whether to use direct play or not | -| directStream | number | Whether to use direct stream or not | -| subtitleSize | number | The size of the subtitles | -| subtites | string | The subtitles | -| audioBoost | number | The audio boost | -| location | string | The location of the transcode session | -| mediaBufferSize | number | The size of the media buffer | -| session | string | The session ID | -| addDebugOverlay | number | Whether to add a debug overlay or not | -| autoAdjustQuality | number | Whether to auto adjust quality or not | - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.video.startUniversalTranscode( - -87516165.31957072, - 'path', - -62877687.452249065, - -23076170.49337977, - 'protocol', - { - fastSeek: -68282427.87913167, - directPlay: -74000014.76895301, - directStream: 84943482.78212723, - subtitleSize: -55237723.44813809, - subtites: 'subtites', - audioBoost: 29945312.780143052, - location: 'location', - mediaBufferSize: -16516185.759793341, - session: 'session', - addDebugOverlay: -10261279.500832424, - autoAdjustQuality: 32480614.034784466, - }, - ); - console.log(result.data); -})(); - -``` - -### **getTimeline** -Get the timeline for a media item -- HTTP Method: GET -- Endpoint: /:/timeline - -**Required Parameters** - -| Name | Type| Description | -| :-------- | :----------| :----------| -| ratingKey | number | The rating key of the media item | -| key | string | The key of the media item to get the timeline for | -| state | [State](/src/models/README.md#state) | The state of the media item | -| hasMde | number | Whether the media item has MDE | -| time | number | The time of the media item | -| duration | number | The duration of the media item | -| context | string | The context of the media item | -| playQueueItemId | number | The play queue item ID of the media item | -| playBackTime | number | The playback time of the media item | -| row | number | The row of the media item | - - - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** -```Typescript -import { PlexSDK } from './src'; - -const sdk = new PlexSDK({ apiKey: process.env.PLEXSDK_API_KEY_TOKEN }); - -(async () => { - const result = await sdk.video.getTimeline( - -32608281.350922346, - 'key', - 'stopped', - -74699884.18136695, - -66756517.26572518, - -24893130.84645444, - 'context', - -75734154.35564606, - -89175857.3275879, - -15877259.38555336, - ); - console.log(result.data); -})(); - -``` - - - - diff --git a/src/services/activities/Activities.ts b/src/services/activities/Activities.ts deleted file mode 100644 index a41b2d7a..00000000 --- a/src/services/activities/Activities.ts +++ /dev/null @@ -1,67 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { GetServerActivitiesResponse } from './models/GetServerActivitiesResponse'; - -import { serializePath } from '../../http/QuerySerializer'; - -export class ActivitiesService extends BaseService { - /** - * @summary Get Server Activities - * @description Get Server Activities - - * @returns {Promise>} - The promise with the result - */ - async getServerActivities(): Promise> { - const urlEndpoint = '/activities'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Cancel Server Activities - * @description Cancel Server Activities - - * @param activityUUID The UUID of the activity to cancel. - * @returns {Promise} - The promise with the result - */ - async cancelServerActivities(activityUuid: string): Promise { - if (activityUuid === undefined) { - throw new Error( - 'The following parameter is required: activityUuid, cannot be empty or blank', - ); - } - let urlEndpoint = '/activities/{activityUUID}'; - urlEndpoint = urlEndpoint.replace( - '{activityUUID}', - encodeURIComponent(serializePath('simple', false, activityUuid, undefined)), - ); - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/activities/index.ts b/src/services/activities/index.ts deleted file mode 100644 index d67c1001..00000000 --- a/src/services/activities/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { GetServerActivitiesResponse } from './models/GetServerActivitiesResponse'; diff --git a/src/services/activities/models/GetServerActivitiesResponse.ts b/src/services/activities/models/GetServerActivitiesResponse.ts deleted file mode 100644 index d86e6f6e..00000000 --- a/src/services/activities/models/GetServerActivitiesResponse.ts +++ /dev/null @@ -1,19 +0,0 @@ -export interface GetServerActivitiesResponse { - MediaContainer?: MediaContainer; -} -interface MediaContainer { - size?: number; - Activity?: { - uuid?: string; - cancellable?: boolean; - userID?: number; - title?: string; - subtitle?: string; - progress?: number; - Context?: Context; - type_?: string; - }[]; -} -interface Context { - librarySectionID?: string; -} diff --git a/src/services/butler/Butler.ts b/src/services/butler/Butler.ts deleted file mode 100644 index a7179838..00000000 --- a/src/services/butler/Butler.ts +++ /dev/null @@ -1,158 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { GetButlerTasksResponse } from './models/GetButlerTasksResponse'; -import { TaskName } from './models/TaskName'; - -import { serializePath } from '../../http/QuerySerializer'; - -export class ButlerService extends BaseService { - /** - * @summary Get Butler tasks - * @description Returns a list of butler tasks - - * @returns {Promise>} - The promise with the result - */ - async getButlerTasks(): Promise> { - const urlEndpoint = '/butler'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Start all Butler tasks - * @description This endpoint will attempt to start all Butler tasks that are enabled in the settings. Butler tasks normally run automatically during a time window configured on the server's Settings page but can be manually started using this endpoint. Tasks will run with the following criteria: -1. Any tasks not scheduled to run on the current day will be skipped. -2. If a task is configured to run at a random time during the configured window and we are outside that window, the task will start immediately. -3. If a task is configured to run at a random time during the configured window and we are within that window, the task will be scheduled at a random time within the window. -4. If we are outside the configured window, the task will start immediately. - - - * @returns {Promise} - The promise with the result - */ - async startAllTasks(): Promise { - const urlEndpoint = '/butler'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.post( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Stop all Butler tasks - * @description This endpoint will stop all currently running tasks and remove any scheduled tasks from the queue. - - - * @returns {Promise} - The promise with the result - */ - async stopAllTasks(): Promise { - const urlEndpoint = '/butler'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Start a single Butler task - * @description This endpoint will attempt to start a single Butler task that is enabled in the settings. Butler tasks normally run automatically during a time window configured on the server's Settings page but can be manually started using this endpoint. Tasks will run with the following criteria: -1. Any tasks not scheduled to run on the current day will be skipped. -2. If a task is configured to run at a random time during the configured window and we are outside that window, the task will start immediately. -3. If a task is configured to run at a random time during the configured window and we are within that window, the task will be scheduled at a random time within the window. -4. If we are outside the configured window, the task will start immediately. - - - * @param taskName the name of the task to be started. - * @returns {Promise} - The promise with the result - */ - async startTask(taskName: TaskName): Promise { - if (taskName === undefined) { - throw new Error('The following parameter is required: taskName, cannot be empty or blank'); - } - let urlEndpoint = '/butler/{taskName}'; - urlEndpoint = urlEndpoint.replace( - '{taskName}', - encodeURIComponent(serializePath('simple', false, taskName, undefined)), - ); - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.post( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Stop a single Butler task - * @description This endpoint will stop a currently running task by name, or remove it from the list of scheduled tasks if it exists. See the section above for a list of task names for this endpoint. - - - * @param taskName The name of the task to be started. - * @returns {Promise} - The promise with the result - */ - async stopTask(taskName: TaskName): Promise { - if (taskName === undefined) { - throw new Error('The following parameter is required: taskName, cannot be empty or blank'); - } - let urlEndpoint = '/butler/{taskName}'; - urlEndpoint = urlEndpoint.replace( - '{taskName}', - encodeURIComponent(serializePath('simple', false, taskName, undefined)), - ); - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/butler/index.ts b/src/services/butler/index.ts deleted file mode 100644 index b9f1a580..00000000 --- a/src/services/butler/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export type { GetButlerTasksResponse } from './models/GetButlerTasksResponse'; -export type { TaskName } from './models/TaskName'; diff --git a/src/services/butler/models/GetButlerTasksResponse.ts b/src/services/butler/models/GetButlerTasksResponse.ts deleted file mode 100644 index dcc7fddd..00000000 --- a/src/services/butler/models/GetButlerTasksResponse.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface GetButlerTasksResponse { - ButlerTasks?: ButlerTasks; -} -interface ButlerTasks { - ButlerTask?: { - name?: string; - interval?: number; - scheduleRandomized?: boolean; - enabled?: boolean; - title?: string; - description?: string; - }[]; -} diff --git a/src/services/butler/models/TaskName.ts b/src/services/butler/models/TaskName.ts deleted file mode 100644 index 5d3a65b8..00000000 --- a/src/services/butler/models/TaskName.ts +++ /dev/null @@ -1,15 +0,0 @@ -export type TaskName = - | 'BackupDatabase' - | 'BuildGracenoteCollections' - | 'CheckForUpdates' - | 'CleanOldBundles' - | 'CleanOldCacheFiles' - | 'DeepMediaAnalysis' - | 'GenerateAutoTags' - | 'GenerateChapterThumbs' - | 'GenerateMediaIndexFiles' - | 'OptimizeDatabase' - | 'RefreshLibraries' - | 'RefreshLocalMedia' - | 'RefreshPeriodicMetadata' - | 'UpgradeMediaAnalysis'; diff --git a/src/services/hubs/Hubs.ts b/src/services/hubs/Hubs.ts deleted file mode 100644 index 8fdd10a3..00000000 --- a/src/services/hubs/Hubs.ts +++ /dev/null @@ -1,96 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { OnlyTransient } from './models/OnlyTransient'; - -import { serializeQuery, serializePath } from '../../http/QuerySerializer'; - -export class HubsService extends BaseService { - /** - * @summary Get Global Hubs - * @description Get Global Hubs filtered by the parameters provided. - - * @param optionalParams - Optional parameters - * @param optionalParams.count - The number of items to return with each hub. - * @param optionalParams.onlyTransient - Only return hubs which are "transient", meaning those which are prone to changing after media playback or addition (e.g. On Deck, or Recently Added). - * @returns {Promise} - The promise with the result - */ - async getGlobalHubs( - optionalParams: { count?: number; onlyTransient?: OnlyTransient } = {}, - ): Promise { - const { count, onlyTransient } = optionalParams; - - const queryParams: string[] = []; - if (count) { - queryParams.push(serializeQuery('form', true, 'count', count)); - } - if (onlyTransient) { - queryParams.push(serializeQuery('form', true, 'onlyTransient', onlyTransient)); - } - const urlEndpoint = '/hubs'; - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get library specific hubs - * @description This endpoint will return a list of library specific hubs - - - * @param sectionId the Id of the library to query - * @param optionalParams - Optional parameters - * @param optionalParams.count - The number of items to return with each hub. - * @param optionalParams.onlyTransient - Only return hubs which are "transient", meaning those which are prone to changing after media playback or addition (e.g. On Deck, or Recently Added). - * @returns {Promise} - The promise with the result - */ - async getLibraryHubs( - sectionId: number, - optionalParams: { count?: number; onlyTransient?: OnlyTransient } = {}, - ): Promise { - const { count, onlyTransient } = optionalParams; - if (sectionId === undefined) { - throw new Error('The following parameter is required: sectionId, cannot be empty or blank'); - } - const queryParams: string[] = []; - let urlEndpoint = '/hubs/sections/{sectionId}'; - urlEndpoint = urlEndpoint.replace( - '{sectionId}', - encodeURIComponent(serializePath('simple', false, sectionId, undefined)), - ); - if (count) { - queryParams.push(serializeQuery('form', true, 'count', count)); - } - if (onlyTransient) { - queryParams.push(serializeQuery('form', true, 'onlyTransient', onlyTransient)); - } - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/hubs/index.ts b/src/services/hubs/index.ts deleted file mode 100644 index 77fff8d2..00000000 --- a/src/services/hubs/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { OnlyTransient } from './models/OnlyTransient'; diff --git a/src/services/hubs/models/OnlyTransient.ts b/src/services/hubs/models/OnlyTransient.ts deleted file mode 100644 index ebc724f6..00000000 --- a/src/services/hubs/models/OnlyTransient.ts +++ /dev/null @@ -1 +0,0 @@ -export type OnlyTransient = 0 | 1; diff --git a/src/services/library/Library.ts b/src/services/library/Library.ts deleted file mode 100644 index b55e42ec..00000000 --- a/src/services/library/Library.ts +++ /dev/null @@ -1,475 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { GetRecentlyAddedResponse } from './models/GetRecentlyAddedResponse'; -import { IncludeDetails } from './models/IncludeDetails'; -import { GetOnDeckResponse } from './models/GetOnDeckResponse'; - -import { serializeQuery, serializePath } from '../../http/QuerySerializer'; - -export class LibraryService extends BaseService { - /** - * @summary Get Hash Value - * @description This resource returns hash values for local files - - * @param url This is the path to the local file, must be prefixed by `file://` - * @param optionalParams - Optional parameters - * @param optionalParams.type_ - Item type - * @returns {Promise} - The promise with the result - */ - async getFileHash(url: string, optionalParams: { type?: number } = {}): Promise { - const { type } = optionalParams; - if (url === undefined) { - throw new Error('The following parameter is required: url, cannot be empty or blank'); - } - const queryParams: string[] = []; - if (url) { - queryParams.push(serializeQuery('form', true, 'url', url)); - } - if (type) { - queryParams.push(serializeQuery('form', true, 'type_', type)); - } - const urlEndpoint = '/library/hashes'; - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Recently Added - * @description This endpoint will return the recently added content. - - - * @returns {Promise>} - The promise with the result - */ - async getRecentlyAdded(): Promise> { - const urlEndpoint = '/library/recentlyAdded'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get All Libraries - * @description A library section (commonly referred to as just a library) is a collection of media. -Libraries are typed, and depending on their type provide either a flat or a hierarchical view of the media. -For example, a music library has an artist > albums > tracks structure, whereas a movie library is flat. - -Libraries have features beyond just being a collection of media; for starters, they include information about supported types, filters and sorts. -This allows a client to provide a rich interface around the media (e.g. allow sorting movies by release year). - - - * @returns {Promise} - The promise with the result - */ - async getLibraries(): Promise { - const urlEndpoint = '/library/sections'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Library Details - * @description Returns details for the library. This can be thought of as an interstitial endpoint because it contains information about the library, rather than content itself. These details are: - -- A list of `Directory` objects: These used to be used by clients to build a menuing system. There are four flavors of directory found here: - - Primary: (e.g. all, On Deck) These are still used in some clients to provide "shortcuts" to subsets of media. However, with the exception of On Deck, all of them can be created by media queries, and the desire is to allow these to be customized by users. - - Secondary: These are marked with `secondary="1"` and were used by old clients to provide nested menus allowing for primative (but structured) navigation. - - Special: There is a By Folder entry which allows browsing the media by the underlying filesystem structure, and there's a completely obsolete entry marked `search="1"` which used to be used to allow clients to build search dialogs on the fly. -- A list of `Type` objects: These represent the types of things found in this library, and for each one, a list of `Filter` and `Sort` objects. These can be used to build rich controls around a grid of media to allow filtering and organizing. Note that these filters and sorts are optional, and without them, the client won't render any filtering controls. The `Type` object contains: - - `key`: This provides the root endpoint returning the actual media list for the type. - - `type`: This is the metadata type for the type (if a standard Plex type). - - `title`: The title for for the content of this type (e.g. "Movies"). -- Each `Filter` object contains a description of the filter. Note that it is not an exhaustive list of the full media query language, but an inportant subset useful for top-level API. - - `filter`: This represents the filter name used for the filter, which can be used to construct complex media queries with. - - `filterType`: This is either `string`, `integer`, or `boolean`, and describes the type of values used for the filter. - - `key`: This provides the endpoint where the possible range of values for the filter can be retrieved (e.g. for a "Genre" filter, it returns a list of all the genres in the library). This will include a `type` argument that matches the metadata type of the Type element. - - `title`: The title for the filter. -- Each `Sort` object contains a description of the sort field. - - `defaultDirection`: Can be either `asc` or `desc`, and specifies the default direction for the sort field (e.g. titles default to alphabetically ascending). - - `descKey` and `key`: Contains the parameters passed to the `sort=...` media query for each direction of the sort. - - `title`: The title of the field. - - - * @param sectionId the Id of the library to query - * @param optionalParams - Optional parameters - * @param optionalParams.includeDetails - Whether or not to include details for a section (types, filters, and sorts). -Only exists for backwards compatibility, media providers other than the server libraries have it on always. - - * @returns {Promise} - The promise with the result - */ - async getLibrary( - sectionId: number, - optionalParams: { includeDetails?: IncludeDetails } = {}, - ): Promise { - const { includeDetails } = optionalParams; - if (sectionId === undefined) { - throw new Error('The following parameter is required: sectionId, cannot be empty or blank'); - } - const queryParams: string[] = []; - let urlEndpoint = '/library/sections/{sectionId}'; - urlEndpoint = urlEndpoint.replace( - '{sectionId}', - encodeURIComponent(serializePath('simple', false, sectionId, undefined)), - ); - if (includeDetails) { - queryParams.push(serializeQuery('form', true, 'includeDetails', includeDetails)); - } - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Delete Library Section - * @description Delate a library using a specific section - - * @param sectionId the Id of the library to query - * @returns {Promise} - The promise with the result - */ - async deleteLibrary(sectionId: number): Promise { - if (sectionId === undefined) { - throw new Error('The following parameter is required: sectionId, cannot be empty or blank'); - } - let urlEndpoint = '/library/sections/{sectionId}'; - urlEndpoint = urlEndpoint.replace( - '{sectionId}', - encodeURIComponent(serializePath('simple', false, sectionId, undefined)), - ); - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Library Items - * @description This endpoint will return a list of library items filtered by the filter and type provided - - - * @param sectionId the Id of the library to query - * @param optionalParams - Optional parameters - * @param optionalParams.type_ - item type - * @param optionalParams.filter - the filter parameter - * @returns {Promise} - The promise with the result - */ - async getLibraryItems( - sectionId: number, - optionalParams: { type?: number; filter?: string } = {}, - ): Promise { - const { type, filter } = optionalParams; - if (sectionId === undefined) { - throw new Error('The following parameter is required: sectionId, cannot be empty or blank'); - } - const queryParams: string[] = []; - let urlEndpoint = '/library/sections/{sectionId}/all'; - urlEndpoint = urlEndpoint.replace( - '{sectionId}', - encodeURIComponent(serializePath('simple', false, sectionId, undefined)), - ); - if (type) { - queryParams.push(serializeQuery('form', true, 'type_', type)); - } - if (filter) { - queryParams.push(serializeQuery('form', true, 'filter', filter)); - } - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Refresh Library - * @description This endpoint Refreshes the library. - - - * @param sectionId the Id of the library to refresh - * @returns {Promise} - The promise with the result - */ - async refreshLibrary(sectionId: number): Promise { - if (sectionId === undefined) { - throw new Error('The following parameter is required: sectionId, cannot be empty or blank'); - } - let urlEndpoint = '/library/sections/{sectionId}/refresh'; - urlEndpoint = urlEndpoint.replace( - '{sectionId}', - encodeURIComponent(serializePath('simple', false, sectionId, undefined)), - ); - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Latest Library Items - * @description This endpoint will return a list of the latest library items filtered by the filter and type provided - - - * @param sectionId the Id of the library to query - * @param type_ item type - * @param optionalParams - Optional parameters - * @param optionalParams.filter - the filter parameter - * @returns {Promise} - The promise with the result - */ - async getLatestLibraryItems( - sectionId: number, - type: number, - optionalParams: { filter?: string } = {}, - ): Promise { - const { filter } = optionalParams; - if (sectionId === undefined || type === undefined) { - throw new Error( - 'The following are required parameters: sectionId,type, cannot be empty or blank', - ); - } - const queryParams: string[] = []; - let urlEndpoint = '/library/sections/{sectionId}/latest'; - urlEndpoint = urlEndpoint.replace( - '{sectionId}', - encodeURIComponent(serializePath('simple', false, sectionId, undefined)), - ); - if (type) { - queryParams.push(serializeQuery('form', true, 'type_', type)); - } - if (filter) { - queryParams.push(serializeQuery('form', true, 'filter', filter)); - } - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Common Library Items - * @description Represents a "Common" item. It contains only the common attributes of the items selected by the provided filter - - - * @param sectionId the Id of the library to query - * @param type_ item type - * @param optionalParams - Optional parameters - * @param optionalParams.filter - the filter parameter - * @returns {Promise} - The promise with the result - */ - async getCommonLibraryItems( - sectionId: number, - type: number, - optionalParams: { filter?: string } = {}, - ): Promise { - const { filter } = optionalParams; - if (sectionId === undefined || type === undefined) { - throw new Error( - 'The following are required parameters: sectionId,type, cannot be empty or blank', - ); - } - const queryParams: string[] = []; - let urlEndpoint = '/library/sections/{sectionId}/common'; - urlEndpoint = urlEndpoint.replace( - '{sectionId}', - encodeURIComponent(serializePath('simple', false, sectionId, undefined)), - ); - if (type) { - queryParams.push(serializeQuery('form', true, 'type_', type)); - } - if (filter) { - queryParams.push(serializeQuery('form', true, 'filter', filter)); - } - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Items Metadata - * @description This endpoint will return the metadata of a library item specified with the ratingKey. - - - * @param ratingKey the id of the library item to return the children of. - * @returns {Promise} - The promise with the result - */ - async getMetadata(ratingKey: number): Promise { - if (ratingKey === undefined) { - throw new Error('The following parameter is required: ratingKey, cannot be empty or blank'); - } - let urlEndpoint = '/library/metadata/{ratingKey}'; - urlEndpoint = urlEndpoint.replace( - '{ratingKey}', - encodeURIComponent(serializePath('simple', false, ratingKey, undefined)), - ); - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Items Children - * @description This endpoint will return the children of of a library item specified with the ratingKey. - - - * @param ratingKey the id of the library item to return the children of. - * @returns {Promise} - The promise with the result - */ - async getMetadataChildren(ratingKey: number): Promise { - if (ratingKey === undefined) { - throw new Error('The following parameter is required: ratingKey, cannot be empty or blank'); - } - let urlEndpoint = '/library/metadata/{ratingKey}/children'; - urlEndpoint = urlEndpoint.replace( - '{ratingKey}', - encodeURIComponent(serializePath('simple', false, ratingKey, undefined)), - ); - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get On Deck - * @description This endpoint will return the on deck content. - - - * @returns {Promise>} - The promise with the result - */ - async getOnDeck(): Promise> { - const urlEndpoint = '/library/onDeck'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/library/index.ts b/src/services/library/index.ts deleted file mode 100644 index da0110c3..00000000 --- a/src/services/library/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type { GetOnDeckResponse } from './models/GetOnDeckResponse'; -export type { GetRecentlyAddedResponse } from './models/GetRecentlyAddedResponse'; -export type { IncludeDetails } from './models/IncludeDetails'; diff --git a/src/services/library/models/GetOnDeckResponse.ts b/src/services/library/models/GetOnDeckResponse.ts deleted file mode 100644 index 33098097..00000000 --- a/src/services/library/models/GetOnDeckResponse.ts +++ /dev/null @@ -1,101 +0,0 @@ -export interface GetOnDeckResponse { - MediaContainer?: MediaContainer; -} -interface MediaContainer { - size?: number; - allowSync?: boolean; - identifier?: string; - mediaTagPrefix?: string; - mediaTagVersion?: number; - mixedParents?: boolean; - Metadata?: { - allowSync?: boolean; - librarySectionID?: number; - librarySectionTitle?: string; - librarySectionUUID?: string; - ratingKey?: number; - key?: string; - parentRatingKey?: number; - grandparentRatingKey?: number; - guid?: string; - parentGuid?: string; - grandparentGuid?: string; - title?: string; - grandparentKey?: string; - parentKey?: string; - librarySectionKey?: string; - grandparentTitle?: string; - parentTitle?: string; - contentRating?: string; - summary?: string; - index?: number; - parentIndex?: number; - lastViewedAt?: number; - year?: number; - thumb?: string; - art?: string; - parentThumb?: string; - grandparentThumb?: string; - grandparentArt?: string; - grandparentTheme?: string; - duration?: number; - originallyAvailableAt?: string; - addedAt?: number; - updatedAt?: number; - Media?: { - id?: number; - duration?: number; - bitrate?: number; - width?: number; - height?: number; - aspectRatio?: number; - audioChannels?: number; - audioCodec?: string; - videoCodec?: string; - videoResolution?: string; - container?: string; - videoFrameRate?: string; - audioProfile?: string; - videoProfile?: string; - Part?: { - id?: number; - key?: string; - duration?: number; - file?: string; - size?: number; - audioProfile?: string; - container?: string; - videoProfile?: string; - Stream?: { - id?: number; - streamType?: number; - codec?: string; - index?: number; - bitrate?: number; - language?: string; - languageTag?: string; - languageCode?: string; - bitDepth?: number; - chromaLocation?: string; - chromaSubsampling?: string; - codedHeight?: number; - codedWidth?: number; - colorRange?: string; - frameRate?: number; - height?: number; - level?: number; - profile?: string; - refFrames?: number; - width?: number; - displayTitle?: string; - extendedDisplayTitle?: string; - default_?: boolean; - }[]; - }[]; - }[]; - Guid?: { - id?: string; - }[]; - type_?: string; - }[]; -} diff --git a/src/services/library/models/GetRecentlyAddedResponse.ts b/src/services/library/models/GetRecentlyAddedResponse.ts deleted file mode 100644 index e4c38378..00000000 --- a/src/services/library/models/GetRecentlyAddedResponse.ts +++ /dev/null @@ -1,83 +0,0 @@ -export interface GetRecentlyAddedResponse { - MediaContainer?: MediaContainer; -} -interface MediaContainer { - size?: number; - allowSync?: boolean; - identifier?: string; - mediaTagPrefix?: string; - mediaTagVersion?: number; - mixedParents?: boolean; - Metadata?: { - allowSync?: boolean; - librarySectionID?: number; - librarySectionTitle?: string; - librarySectionUUID?: string; - ratingKey?: number; - key?: string; - guid?: string; - studio?: string; - title?: string; - contentRating?: string; - summary?: string; - rating?: number; - audienceRating?: number; - year?: number; - tagline?: string; - thumb?: string; - art?: string; - duration?: number; - originallyAvailableAt?: string; - addedAt?: number; - updatedAt?: number; - audienceRatingImage?: string; - chapterSource?: string; - primaryExtraKey?: string; - ratingImage?: string; - Media?: { - id?: number; - duration?: number; - bitrate?: number; - width?: number; - height?: number; - aspectRatio?: number; - audioChannels?: number; - audioCodec?: string; - videoCodec?: string; - videoResolution?: number; - container?: string; - videoFrameRate?: string; - optimizedForStreaming?: number; - has64bitOffsets?: boolean; - videoProfile?: string; - Part?: { - id?: number; - key?: string; - duration?: number; - file?: string; - size?: number; - container?: string; - has64bitOffsets?: boolean; - hasThumbnail?: number; - optimizedForStreaming?: boolean; - videoProfile?: string; - }[]; - }[]; - Genre?: { - tag?: string; - }[]; - Director?: { - tag?: string; - }[]; - Writer?: { - tag?: string; - }[]; - Country?: { - tag?: string; - }[]; - Role?: { - tag?: string; - }[]; - type_?: string; - }[]; -} diff --git a/src/services/library/models/IncludeDetails.ts b/src/services/library/models/IncludeDetails.ts deleted file mode 100644 index 51045cf7..00000000 --- a/src/services/library/models/IncludeDetails.ts +++ /dev/null @@ -1 +0,0 @@ -export type IncludeDetails = 0 | 1; diff --git a/src/services/log/Log.ts b/src/services/log/Log.ts deleted file mode 100644 index d08c267f..00000000 --- a/src/services/log/Log.ts +++ /dev/null @@ -1,108 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { Level } from './models/Level'; - -import { serializeQuery } from '../../http/QuerySerializer'; - -export class LogService extends BaseService { - /** - * @summary Logging a single line message. - * @description This endpoint will write a single-line log message, including a level and source to the main Plex Media Server log. - - - * @param level An integer log level to write to the PMS log with. -0: Error -1: Warning -2: Info -3: Debug -4: Verbose - - * @param message The text of the message to write to the log. - * @param source a string indicating the source of the message. - * @returns {Promise} - The promise with the result - */ - async logLine(level: Level, message: string, source: string): Promise { - if (level === undefined || message === undefined || source === undefined) { - throw new Error( - 'The following are required parameters: level,message,source, cannot be empty or blank', - ); - } - const queryParams: string[] = []; - if (level) { - queryParams.push(serializeQuery('form', true, 'level', level)); - } - if (message) { - queryParams.push(serializeQuery('form', true, 'message', message)); - } - if (source) { - queryParams.push(serializeQuery('form', true, 'source', source)); - } - const urlEndpoint = '/log'; - const finalUrl = `${this.baseUrl + urlEndpoint}?${encodeURI(queryParams.join('&'))}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Logging a multi-line message - * @description This endpoint will write multiple lines to the main Plex Media Server log in a single request. It takes a set of query strings as would normally sent to the above GET endpoint as a linefeed-separated block of POST data. The parameters for each query string match as above. - - - * @returns {Promise} - The promise with the result - */ - async logMultiLine(): Promise { - const urlEndpoint = '/log'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.post( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Enabling Papertrail - * @description This endpoint will enable all Plex Media Serverlogs to be sent to the Papertrail networked logging site for a period of time. - - - * @returns {Promise} - The promise with the result - */ - async enablePaperTrail(): Promise { - const urlEndpoint = '/log/networked'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/log/index.ts b/src/services/log/index.ts deleted file mode 100644 index 3db5021c..00000000 --- a/src/services/log/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { Level } from './models/Level'; diff --git a/src/services/log/models/Level.ts b/src/services/log/models/Level.ts deleted file mode 100644 index 3cedb749..00000000 --- a/src/services/log/models/Level.ts +++ /dev/null @@ -1 +0,0 @@ -export type Level = 0 | 1 | 2 | 3 | 4; diff --git a/src/services/media/Media.ts b/src/services/media/Media.ts deleted file mode 100644 index 7e9e5dd5..00000000 --- a/src/services/media/Media.ts +++ /dev/null @@ -1,114 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { serializeQuery } from '../../http/QuerySerializer'; - -export class MediaService extends BaseService { - /** - * @summary Mark Media Played - * @description This will mark the provided media key as Played. - - * @param key The media key to mark as played - * @returns {Promise} - The promise with the result - */ - async markPlayed(key: number): Promise { - if (key === undefined) { - throw new Error('The following parameter is required: key, cannot be empty or blank'); - } - const queryParams: string[] = []; - if (key) { - queryParams.push(serializeQuery('form', true, 'key', key)); - } - const urlEndpoint = '/:/scrobble'; - const finalUrl = `${this.baseUrl + urlEndpoint}?${encodeURI(queryParams.join('&'))}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Mark Media Unplayed - * @description This will mark the provided media key as Unplayed. - - * @param key The media key to mark as Unplayed - * @returns {Promise} - The promise with the result - */ - async markUnplayed(key: number): Promise { - if (key === undefined) { - throw new Error('The following parameter is required: key, cannot be empty or blank'); - } - const queryParams: string[] = []; - if (key) { - queryParams.push(serializeQuery('form', true, 'key', key)); - } - const urlEndpoint = '/:/unscrobble'; - const finalUrl = `${this.baseUrl + urlEndpoint}?${encodeURI(queryParams.join('&'))}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Update Media Play Progress - * @description This API command can be used to update the play progress of a media item. - - - * @param key the media key - * @param time The time, in milliseconds, used to set the media playback progress. - * @param state The playback state of the media item. - * @returns {Promise} - The promise with the result - */ - async updatePlayProgress(key: string, time: number, state: string): Promise { - if (key === undefined || time === undefined || state === undefined) { - throw new Error( - 'The following are required parameters: key,time,state, cannot be empty or blank', - ); - } - const queryParams: string[] = []; - if (key) { - queryParams.push(serializeQuery('form', true, 'key', key)); - } - if (time) { - queryParams.push(serializeQuery('form', true, 'time', time)); - } - if (state) { - queryParams.push(serializeQuery('form', true, 'state', state)); - } - const urlEndpoint = '/:/progress'; - const finalUrl = `${this.baseUrl + urlEndpoint}?${encodeURI(queryParams.join('&'))}`; - const response: any = await this.httpClient.post( - finalUrl, - { key, time, state }, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/playlists/Playlists.ts b/src/services/playlists/Playlists.ts deleted file mode 100644 index 6d47689a..00000000 --- a/src/services/playlists/Playlists.ts +++ /dev/null @@ -1,380 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { Type } from './models/Type'; -import { Smart } from './models/Smart'; -import { PlaylistType } from './models/PlaylistType'; -import { Force } from './models/Force'; - -import { serializeQuery, serializePath } from '../../http/QuerySerializer'; - -export class PlaylistsService extends BaseService { - /** - * @summary Create a Playlist - * @description 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. `library://...`). -- `playQueueID` - To create a playlist from an existing play queue. - - - * @param title name of the playlist - * @param type_ type of playlist to create - * @param smart whether the playlist is smart or not - * @param optionalParams - Optional parameters - * @param optionalParams.uri - the content URI for the playlist - * @param optionalParams.playQueueID - the play queue to copy to a playlist - * @returns {Promise} - The promise with the result - */ - async createPlaylist( - title: string, - type: Type, - smart: Smart, - optionalParams: { uri?: string; playQueueId?: number } = {}, - ): Promise { - const { uri, playQueueId } = optionalParams; - if (title === undefined || type === undefined || smart === undefined) { - throw new Error( - 'The following are required parameters: title,type,smart, cannot be empty or blank', - ); - } - const queryParams: string[] = []; - if (title) { - queryParams.push(serializeQuery('form', true, 'title', title)); - } - if (type) { - queryParams.push(serializeQuery('form', true, 'type_', type)); - } - if (smart) { - queryParams.push(serializeQuery('form', true, 'smart', smart)); - } - if (uri) { - queryParams.push(serializeQuery('form', true, 'uri', uri)); - } - if (playQueueId) { - queryParams.push(serializeQuery('form', true, 'playQueueID', playQueueId)); - } - const urlEndpoint = '/playlists'; - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.post( - finalUrl, - { title, type_: type, smart, uri, playQueueID: playQueueId }, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get All Playlists - * @description Get All Playlists given the specified filters. - - * @param optionalParams - Optional parameters - * @param optionalParams.playlistType - limit to a type of playlist. - * @param optionalParams.smart - type of playlists to return (default is all). - * @returns {Promise} - The promise with the result - */ - async getPlaylists( - optionalParams: { playlistType?: PlaylistType; smart?: Smart } = {}, - ): Promise { - const { playlistType, smart } = optionalParams; - - const queryParams: string[] = []; - if (playlistType) { - queryParams.push(serializeQuery('form', true, 'playlistType', playlistType)); - } - if (smart) { - queryParams.push(serializeQuery('form', true, 'smart', smart)); - } - const urlEndpoint = '/playlists/all'; - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Retrieve Playlist - * @description 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 - * @returns {Promise} - The promise with the result - */ - async getPlaylist(playlistId: number): Promise { - if (playlistId === undefined) { - throw new Error('The following parameter is required: playlistId, cannot be empty or blank'); - } - let urlEndpoint = '/playlists/{playlistID}'; - urlEndpoint = urlEndpoint.replace( - '{playlistID}', - encodeURIComponent(serializePath('simple', false, playlistId, undefined)), - ); - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Update a Playlist - * @description 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 - * @returns {Promise} - The promise with the result - */ - async updatePlaylist(playlistId: number): Promise { - if (playlistId === undefined) { - throw new Error('The following parameter is required: playlistId, cannot be empty or blank'); - } - let urlEndpoint = '/playlists/{playlistID}'; - urlEndpoint = urlEndpoint.replace( - '{playlistID}', - encodeURIComponent(serializePath('simple', false, playlistId, undefined)), - ); - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.put( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Deletes a Playlist - * @description This endpoint will delete a playlist - - - * @param playlistID the ID of the playlist - * @returns {Promise} - The promise with the result - */ - async deletePlaylist(playlistId: number): Promise { - if (playlistId === undefined) { - throw new Error('The following parameter is required: playlistId, cannot be empty or blank'); - } - let urlEndpoint = '/playlists/{playlistID}'; - urlEndpoint = urlEndpoint.replace( - '{playlistID}', - encodeURIComponent(serializePath('simple', false, playlistId, undefined)), - ); - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Retrieve Playlist Contents - * @description 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 metadata type of the item to return - * @returns {Promise} - The promise with the result - */ - async getPlaylistContents(playlistId: number, type: number): Promise { - if (playlistId === undefined || type === undefined) { - throw new Error( - 'The following are required parameters: playlistId,type, cannot be empty or blank', - ); - } - const queryParams: string[] = []; - let urlEndpoint = '/playlists/{playlistID}/items'; - urlEndpoint = urlEndpoint.replace( - '{playlistID}', - encodeURIComponent(serializePath('simple', false, playlistId, undefined)), - ); - if (type) { - queryParams.push(serializeQuery('form', true, 'type_', type)); - } - const finalUrl = `${this.baseUrl + urlEndpoint}?${encodeURI(queryParams.join('&'))}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Adding to a Playlist - * @description Adds a generator to a playlist, same parameters as the POST above. 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 - * @returns {Promise} - The promise with the result - */ - async addPlaylistContents(playlistId: number, uri: string, playQueueId: number): Promise { - if (playlistId === undefined || uri === undefined || playQueueId === undefined) { - throw new Error( - 'The following are required parameters: playlistId,uri,playQueueId, cannot be empty or blank', - ); - } - const queryParams: string[] = []; - let urlEndpoint = '/playlists/{playlistID}/items'; - urlEndpoint = urlEndpoint.replace( - '{playlistID}', - encodeURIComponent(serializePath('simple', false, playlistId, undefined)), - ); - if (uri) { - queryParams.push(serializeQuery('form', true, 'uri', uri)); - } - if (playQueueId) { - queryParams.push(serializeQuery('form', true, 'playQueueID', playQueueId)); - } - const finalUrl = `${this.baseUrl + urlEndpoint}?${encodeURI(queryParams.join('&'))}`; - const response: any = await this.httpClient.put( - finalUrl, - { uri, playQueueID: playQueueId }, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Delete Playlist Contents - * @description Clears a playlist, only works with dumb playlists. Returns the playlist. - - - * @param playlistID the ID of the playlist - * @returns {Promise} - The promise with the result - */ - async clearPlaylistContents(playlistId: number): Promise { - if (playlistId === undefined) { - throw new Error('The following parameter is required: playlistId, cannot be empty or blank'); - } - let urlEndpoint = '/playlists/{playlistID}/items'; - urlEndpoint = urlEndpoint.replace( - '{playlistID}', - encodeURIComponent(serializePath('simple', false, playlistId, undefined)), - ); - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Upload Playlist - * @description 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. - - * @returns {Promise} - The promise with the result - */ - async uploadPlaylist(path: string, force: Force): Promise { - if (path === undefined || force === undefined) { - throw new Error( - 'The following are required parameters: path,force, cannot be empty or blank', - ); - } - const queryParams: string[] = []; - if (path) { - queryParams.push(serializeQuery('form', true, 'path', path)); - } - if (force) { - queryParams.push(serializeQuery('form', true, 'force', force)); - } - const urlEndpoint = '/playlists/upload'; - const finalUrl = `${this.baseUrl + urlEndpoint}?${encodeURI(queryParams.join('&'))}`; - const response: any = await this.httpClient.post( - finalUrl, - { path, force }, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/playlists/index.ts b/src/services/playlists/index.ts deleted file mode 100644 index 69ce5b73..00000000 --- a/src/services/playlists/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type { Force } from './models/Force'; -export type { PlaylistType } from './models/PlaylistType'; -export type { Smart } from './models/Smart'; -export type { Type } from './models/Type'; diff --git a/src/services/playlists/models/Force.ts b/src/services/playlists/models/Force.ts deleted file mode 100644 index 523a7b36..00000000 --- a/src/services/playlists/models/Force.ts +++ /dev/null @@ -1 +0,0 @@ -export type Force = 0 | 1; diff --git a/src/services/playlists/models/PlaylistType.ts b/src/services/playlists/models/PlaylistType.ts deleted file mode 100644 index 14d4d794..00000000 --- a/src/services/playlists/models/PlaylistType.ts +++ /dev/null @@ -1 +0,0 @@ -export type PlaylistType = 'audio' | 'video' | 'photo'; diff --git a/src/services/playlists/models/Smart.ts b/src/services/playlists/models/Smart.ts deleted file mode 100644 index a119be22..00000000 --- a/src/services/playlists/models/Smart.ts +++ /dev/null @@ -1 +0,0 @@ -export type Smart = 0 | 1; diff --git a/src/services/playlists/models/Type.ts b/src/services/playlists/models/Type.ts deleted file mode 100644 index d4756d68..00000000 --- a/src/services/playlists/models/Type.ts +++ /dev/null @@ -1 +0,0 @@ -export type Type = 'audio' | 'video' | 'photo'; diff --git a/src/services/search/Search.ts b/src/services/search/Search.ts deleted file mode 100644 index 1872a239..00000000 --- a/src/services/search/Search.ts +++ /dev/null @@ -1,149 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { GetSearchResultsResponse } from './models/GetSearchResultsResponse'; - -import { serializeQuery } from '../../http/QuerySerializer'; - -export class SearchService extends BaseService { - /** - * @summary Perform a search - * @description 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). - - ``: 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 query The query term - * @param optionalParams - Optional parameters - * @param optionalParams.sectionId - This gives context to the search, and can result in re-ordering of search result hubs - * @param optionalParams.limit - The number of items to return per hub - * @returns {Promise} - The promise with the result - */ - async performSearch( - query: string, - optionalParams: { sectionId?: number; limit?: number } = {}, - ): Promise { - const { sectionId, limit } = optionalParams; - if (query === undefined) { - throw new Error('The following parameter is required: query, cannot be empty or blank'); - } - const queryParams: string[] = []; - if (query) { - queryParams.push(serializeQuery('form', true, 'query', query)); - } - if (sectionId) { - queryParams.push(serializeQuery('form', true, 'sectionId', sectionId)); - } - if (limit) { - queryParams.push(serializeQuery('form', true, 'limit', limit)); - } - const urlEndpoint = '/hubs/search'; - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Perform a voice search - * @description 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 query The query term - * @param optionalParams - Optional parameters - * @param optionalParams.sectionId - This gives context to the search, and can result in re-ordering of search result hubs - * @param optionalParams.limit - The number of items to return per hub - * @returns {Promise} - The promise with the result - */ - async performVoiceSearch( - query: string, - optionalParams: { sectionId?: number; limit?: number } = {}, - ): Promise { - const { sectionId, limit } = optionalParams; - if (query === undefined) { - throw new Error('The following parameter is required: query, cannot be empty or blank'); - } - const queryParams: string[] = []; - if (query) { - queryParams.push(serializeQuery('form', true, 'query', query)); - } - if (sectionId) { - queryParams.push(serializeQuery('form', true, 'sectionId', sectionId)); - } - if (limit) { - queryParams.push(serializeQuery('form', true, 'limit', limit)); - } - const urlEndpoint = '/hubs/search/voice'; - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Search Results - * @description This will search the database for the string provided. - - * @param query The search query string to use - * @returns {Promise>} - The promise with the result - */ - async getSearchResults(query: string): Promise> { - if (query === undefined) { - throw new Error('The following parameter is required: query, cannot be empty or blank'); - } - const queryParams: string[] = []; - if (query) { - queryParams.push(serializeQuery('form', true, 'query', query)); - } - const urlEndpoint = '/search'; - const finalUrl = `${this.baseUrl + urlEndpoint}?${encodeURI(queryParams.join('&'))}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/search/index.ts b/src/services/search/index.ts deleted file mode 100644 index 38cf08ad..00000000 --- a/src/services/search/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { GetSearchResultsResponse } from './models/GetSearchResultsResponse'; diff --git a/src/services/search/models/GetSearchResultsResponse.ts b/src/services/search/models/GetSearchResultsResponse.ts deleted file mode 100644 index 76b0db61..00000000 --- a/src/services/search/models/GetSearchResultsResponse.ts +++ /dev/null @@ -1,85 +0,0 @@ -export interface GetSearchResultsResponse { - MediaContainer?: MediaContainer; -} -interface MediaContainer { - size?: number; - identifier?: string; - mediaTagPrefix?: string; - mediaTagVersion?: number; - Metadata?: { - allowSync?: boolean; - librarySectionID?: number; - librarySectionTitle?: string; - librarySectionUUID?: string; - personal?: boolean; - sourceTitle?: string; - ratingKey?: number; - key?: string; - guid?: string; - studio?: string; - title?: string; - contentRating?: string; - summary?: string; - rating?: number; - audienceRating?: number; - year?: number; - tagline?: string; - thumb?: string; - art?: string; - duration?: number; - originallyAvailableAt?: string; - addedAt?: number; - updatedAt?: number; - audienceRatingImage?: string; - chapterSource?: string; - primaryExtraKey?: string; - ratingImage?: string; - Media?: { - id?: number; - duration?: number; - bitrate?: number; - width?: number; - height?: number; - aspectRatio?: number; - audioChannels?: number; - audioCodec?: string; - videoCodec?: string; - videoResolution?: number; - container?: string; - videoFrameRate?: string; - audioProfile?: string; - videoProfile?: string; - Part?: { - id?: number; - key?: string; - duration?: number; - file?: string; - size?: number; - audioProfile?: string; - container?: string; - videoProfile?: string; - }[]; - }[]; - Genre?: { - tag?: string; - }[]; - Director?: { - tag?: string; - }[]; - Writer?: { - tag?: string; - }[]; - Country?: { - tag?: string; - }[]; - Role?: { - tag?: string; - }[]; - type_?: string; - }[]; - Provider?: { - key?: string; - title?: string; - type_?: string; - }[]; -} diff --git a/src/services/security/Security.ts b/src/services/security/Security.ts deleted file mode 100644 index f49fabe0..00000000 --- a/src/services/security/Security.ts +++ /dev/null @@ -1,83 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { SecurityType } from './models/SecurityType'; -import { Scope } from './models/Scope'; - -import { serializeQuery } from '../../http/QuerySerializer'; - -export class SecurityService extends BaseService { - /** - * @summary Get a Transient Token. - * @description This endpoint provides the caller with a temporary token with the same access level as the caller's token. These tokens are valid for up to 48 hours and are destroyed if the server instance is restarted. - - - * @param type_ `delegation` - This is the only supported `type` parameter. - * @param scope `all` - This is the only supported `scope` parameter. - * @returns {Promise} - The promise with the result - */ - async getTransientToken(type: SecurityType, scope: Scope): Promise { - if (type === undefined || scope === undefined) { - throw new Error( - 'The following are required parameters: type,scope, cannot be empty or blank', - ); - } - const queryParams: string[] = []; - if (type) { - queryParams.push(serializeQuery('form', true, 'type_', type)); - } - if (scope) { - queryParams.push(serializeQuery('form', true, 'scope', scope)); - } - const urlEndpoint = '/security/token'; - const finalUrl = `${this.baseUrl + urlEndpoint}?${encodeURI(queryParams.join('&'))}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Source Connection Information - * @description If a caller requires connection details and a transient token for a source that is known to the server, for example a cloud media provider or shared PMS, then this endpoint can be called. This endpoint is only accessible with either an admin token or a valid transient token generated from an admin token. -Note: requires Plex Media Server >= 1.15.4. - - - * @param source The source identifier with an included prefix. - * @returns {Promise} - The promise with the result - */ - async getSourceConnectionInformation(source: string): Promise { - if (source === undefined) { - throw new Error('The following parameter is required: source, cannot be empty or blank'); - } - const queryParams: string[] = []; - if (source) { - queryParams.push(serializeQuery('form', true, 'source', source)); - } - const urlEndpoint = '/security/resources'; - const finalUrl = `${this.baseUrl + urlEndpoint}?${encodeURI(queryParams.join('&'))}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/security/index.ts b/src/services/security/index.ts deleted file mode 100644 index d8d98bf9..00000000 --- a/src/services/security/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export type { Scope } from './models/Scope'; -export type { SecurityType } from './models/SecurityType'; diff --git a/src/services/security/models/Scope.ts b/src/services/security/models/Scope.ts deleted file mode 100644 index 4548fa17..00000000 --- a/src/services/security/models/Scope.ts +++ /dev/null @@ -1 +0,0 @@ -export type Scope = 'all'; diff --git a/src/services/security/models/SecurityType.ts b/src/services/security/models/SecurityType.ts deleted file mode 100644 index f0d559fd..00000000 --- a/src/services/security/models/SecurityType.ts +++ /dev/null @@ -1 +0,0 @@ -export type SecurityType = 'delegation'; diff --git a/src/services/server/Server.ts b/src/services/server/Server.ts deleted file mode 100644 index 1c7a5115..00000000 --- a/src/services/server/Server.ts +++ /dev/null @@ -1,259 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { GetServerCapabilitiesResponse } from './models/GetServerCapabilitiesResponse'; -import { GetAvailableClientsResponse } from './models/GetAvailableClientsResponse'; -import { GetDevicesResponse } from './models/GetDevicesResponse'; -import { GetServerIdentityResponse } from './models/GetServerIdentityResponse'; -import { GetMyPlexAccountResponse } from './models/GetMyPlexAccountResponse'; -import { MinSize } from './models/MinSize'; -import { Upscale } from './models/Upscale'; -import { GetServerListResponse } from './models/GetServerListResponse'; - -import { serializeQuery } from '../../http/QuerySerializer'; - -export class ServerService extends BaseService { - /** - * @summary Server Capabilities - * @description Server Capabilities - - * @returns {Promise>} - The promise with the result - */ - async getServerCapabilities(): Promise> { - const urlEndpoint = '/'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Server Preferences - * @description Get Server Preferences - - * @returns {Promise} - The promise with the result - */ - async getServerPreferences(): Promise { - const urlEndpoint = '/:/prefs'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Available Clients - * @description Get Available Clients - - * @returns {Promise>} - The promise with the result - */ - async getAvailableClients(): Promise> { - const urlEndpoint = '/clients'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Devices - * @description Get Devices - - * @returns {Promise>} - The promise with the result - */ - async getDevices(): Promise> { - const urlEndpoint = '/devices'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Server Identity - * @description Get Server Identity - - * @returns {Promise>} - The promise with the result - */ - async getServerIdentity(): Promise> { - const urlEndpoint = '/identity'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get MyPlex Account - * @description Returns MyPlex Account Information - - * @returns {Promise>} - The promise with the result - */ - async getMyPlexAccount(): Promise> { - const urlEndpoint = '/myplex/account'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get a Resized Photo - * @description Plex's Photo transcoder is used throughout the service to serve images at specified sizes. - - - * @param width The width for the resized photo - * @param height The height for the resized photo - * @param opacity The opacity for the resized photo - * @param blur The width for the resized photo - * @param minSize images are always scaled proportionally. A value of '1' in minSize will make the smaller native dimension the dimension resized against. - * @param upscale allow images to be resized beyond native dimensions. - * @param url path to image within Plex - * @returns {Promise} - The promise with the result - */ - async getResizedPhoto( - width: number, - height: number, - opacity: number, - blur: number, - minSize: MinSize, - upscale: Upscale, - url: string, - ): Promise { - if ( - width === undefined || - height === undefined || - opacity === undefined || - blur === undefined || - minSize === undefined || - upscale === undefined || - url === undefined - ) { - throw new Error( - 'The following are required parameters: width,height,opacity,blur,minSize,upscale,url, cannot be empty or blank', - ); - } - const queryParams: string[] = []; - if (width) { - queryParams.push(serializeQuery('form', true, 'width', width)); - } - if (height) { - queryParams.push(serializeQuery('form', true, 'height', height)); - } - if (opacity) { - queryParams.push(serializeQuery('form', true, 'opacity', opacity)); - } - if (blur) { - queryParams.push(serializeQuery('form', true, 'blur', blur)); - } - if (minSize) { - queryParams.push(serializeQuery('form', true, 'minSize', minSize)); - } - if (upscale) { - queryParams.push(serializeQuery('form', true, 'upscale', upscale)); - } - if (url) { - queryParams.push(serializeQuery('form', true, 'url', url)); - } - const urlEndpoint = '/photo/:/transcode'; - const finalUrl = `${this.baseUrl + urlEndpoint}?${encodeURI(queryParams.join('&'))}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Server List - * @description Get Server List - - * @returns {Promise>} - The promise with the result - */ - async getServerList(): Promise> { - const urlEndpoint = '/servers'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/server/index.ts b/src/services/server/index.ts deleted file mode 100644 index adedc9da..00000000 --- a/src/services/server/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -export type { GetAvailableClientsResponse } from './models/GetAvailableClientsResponse'; -export type { GetDevicesResponse } from './models/GetDevicesResponse'; -export type { GetMyPlexAccountResponse } from './models/GetMyPlexAccountResponse'; -export type { GetServerCapabilitiesResponse } from './models/GetServerCapabilitiesResponse'; -export type { GetServerIdentityResponse } from './models/GetServerIdentityResponse'; -export type { GetServerListResponse } from './models/GetServerListResponse'; -export type { MinSize } from './models/MinSize'; -export type { Upscale } from './models/Upscale'; diff --git a/src/services/server/models/GetAvailableClientsResponse.ts b/src/services/server/models/GetAvailableClientsResponse.ts deleted file mode 100644 index 7e8de603..00000000 --- a/src/services/server/models/GetAvailableClientsResponse.ts +++ /dev/null @@ -1,20 +0,0 @@ -export type GetAvailableClientsResponse = { - MediaContainer?: MediaContainer; -}[]; - -interface MediaContainer { - size?: number; - Server?: { - name?: string; - host?: string; - address?: string; - port?: number; - machineIdentifier?: string; - version?: string; - protocol?: string; - product?: string; - deviceClass?: string; - protocolVersion?: number; - protocolCapabilities?: string; - }[]; -} diff --git a/src/services/server/models/GetDevicesResponse.ts b/src/services/server/models/GetDevicesResponse.ts deleted file mode 100644 index 86ae4a1b..00000000 --- a/src/services/server/models/GetDevicesResponse.ts +++ /dev/null @@ -1,14 +0,0 @@ -export interface GetDevicesResponse { - MediaContainer?: MediaContainer; -} -interface MediaContainer { - size?: number; - identifier?: string; - Device?: { - id?: number; - name?: string; - platform?: string; - clientIdentifier?: string; - createdAt?: number; - }[]; -} diff --git a/src/services/server/models/GetMyPlexAccountResponse.ts b/src/services/server/models/GetMyPlexAccountResponse.ts deleted file mode 100644 index 7bddfcca..00000000 --- a/src/services/server/models/GetMyPlexAccountResponse.ts +++ /dev/null @@ -1,17 +0,0 @@ -export interface GetMyPlexAccountResponse { - MyPlex?: MyPlex; -} -interface MyPlex { - authToken?: string; - username?: string; - mappingState?: string; - mappingError?: string; - signInState?: string; - publicAddress?: string; - publicPort?: number; - privateAddress?: string; - privatePort?: number; - subscriptionFeatures?: string; - subscriptionActive?: boolean; - subscriptionState?: string; -} diff --git a/src/services/server/models/GetServerCapabilitiesResponse.ts b/src/services/server/models/GetServerCapabilitiesResponse.ts deleted file mode 100644 index 06f1f824..00000000 --- a/src/services/server/models/GetServerCapabilitiesResponse.ts +++ /dev/null @@ -1,60 +0,0 @@ -export interface GetServerCapabilitiesResponse { - MediaContainer?: MediaContainer; -} -interface MediaContainer { - size?: number; - allowCameraUpload?: boolean; - allowChannelAccess?: boolean; - allowMediaDeletion?: boolean; - allowSharing?: boolean; - allowSync?: boolean; - allowTuners?: boolean; - backgroundProcessing?: boolean; - certificate?: boolean; - companionProxy?: boolean; - countryCode?: string; - diagnostics?: string; - eventStream?: boolean; - friendlyName?: string; - hubSearch?: boolean; - itemClusters?: boolean; - livetv?: number; - machineIdentifier?: string; - mediaProviders?: boolean; - multiuser?: boolean; - musicAnalysis?: number; - myPlex?: boolean; - myPlexMappingState?: string; - myPlexSigninState?: string; - myPlexSubscription?: boolean; - myPlexUsername?: string; - offlineTranscode?: number; - ownerFeatures?: string; - photoAutoTag?: boolean; - platform?: string; - platformVersion?: string; - pluginHost?: boolean; - pushNotifications?: boolean; - readOnlyLibraries?: boolean; - streamingBrainABRVersion?: number; - streamingBrainVersion?: number; - sync?: boolean; - transcoderActiveVideoSessions?: number; - transcoderAudio?: boolean; - transcoderLyrics?: boolean; - transcoderPhoto?: boolean; - transcoderSubtitles?: boolean; - transcoderVideo?: boolean; - transcoderVideoBitrates?: string; - transcoderVideoQualities?: string; - transcoderVideoResolutions?: string; - updatedAt?: number; - updater?: boolean; - version?: string; - voiceSearch?: boolean; - Directory?: { - count?: number; - key?: string; - title?: string; - }[]; -} diff --git a/src/services/server/models/GetServerIdentityResponse.ts b/src/services/server/models/GetServerIdentityResponse.ts deleted file mode 100644 index aefbccd7..00000000 --- a/src/services/server/models/GetServerIdentityResponse.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface GetServerIdentityResponse { - MediaContainer?: MediaContainer; -} -interface MediaContainer { - size?: number; - claimed?: boolean; - machineIdentifier?: string; - version?: string; -} diff --git a/src/services/server/models/GetServerListResponse.ts b/src/services/server/models/GetServerListResponse.ts deleted file mode 100644 index 28937c85..00000000 --- a/src/services/server/models/GetServerListResponse.ts +++ /dev/null @@ -1,14 +0,0 @@ -export interface GetServerListResponse { - MediaContainer?: MediaContainer; -} -interface MediaContainer { - size?: number; - Server?: { - name?: string; - host?: string; - address?: string; - port?: number; - machineIdentifier?: string; - version?: string; - }[]; -} diff --git a/src/services/server/models/MinSize.ts b/src/services/server/models/MinSize.ts deleted file mode 100644 index 9f0e1fe2..00000000 --- a/src/services/server/models/MinSize.ts +++ /dev/null @@ -1 +0,0 @@ -export type MinSize = 0 | 1; diff --git a/src/services/server/models/Upscale.ts b/src/services/server/models/Upscale.ts deleted file mode 100644 index 5252b310..00000000 --- a/src/services/server/models/Upscale.ts +++ /dev/null @@ -1 +0,0 @@ -export type Upscale = 0 | 1; diff --git a/src/services/sessions/Sessions.ts b/src/services/sessions/Sessions.ts deleted file mode 100644 index fd69b8d3..00000000 --- a/src/services/sessions/Sessions.ts +++ /dev/null @@ -1,113 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { GetTranscodeSessionsResponse } from './models/GetTranscodeSessionsResponse'; - -import { serializePath } from '../../http/QuerySerializer'; - -export class SessionsService extends BaseService { - /** - * @summary Get Active Sessions - * @description This will retrieve the "Now Playing" Information of the PMS. - - * @returns {Promise} - The promise with the result - */ - async getSessions(): Promise { - const urlEndpoint = '/status/sessions'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Session History - * @description This will Retrieve a listing of all history views. - - * @returns {Promise} - The promise with the result - */ - async getSessionHistory(): Promise { - const urlEndpoint = '/status/sessions/history/all'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get Transcode Sessions - * @description Get Transcode Sessions - - * @returns {Promise>} - The promise with the result - */ - async getTranscodeSessions(): Promise> { - const urlEndpoint = '/transcode/sessions'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Stop a Transcode Session - * @description Stop a Transcode Session - - * @param sessionKey the Key of the transcode session to stop - * @returns {Promise} - The promise with the result - */ - async stopTranscodeSession(sessionKey: string): Promise { - if (sessionKey === undefined) { - throw new Error('The following parameter is required: sessionKey, cannot be empty or blank'); - } - let urlEndpoint = '/transcode/sessions/{sessionKey}'; - urlEndpoint = urlEndpoint.replace( - '{sessionKey}', - encodeURIComponent(serializePath('simple', false, sessionKey, undefined)), - ); - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/sessions/index.ts b/src/services/sessions/index.ts deleted file mode 100644 index 7347ded8..00000000 --- a/src/services/sessions/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { GetTranscodeSessionsResponse } from './models/GetTranscodeSessionsResponse'; diff --git a/src/services/sessions/models/GetTranscodeSessionsResponse.ts b/src/services/sessions/models/GetTranscodeSessionsResponse.ts deleted file mode 100644 index 19e8bb03..00000000 --- a/src/services/sessions/models/GetTranscodeSessionsResponse.ts +++ /dev/null @@ -1,30 +0,0 @@ -export interface GetTranscodeSessionsResponse { - MediaContainer?: MediaContainer; -} -interface MediaContainer { - size?: number; - TranscodeSession?: { - key?: string; - throttled?: boolean; - complete?: boolean; - progress?: number; - size?: number; - speed?: number; - error?: boolean; - duration?: number; - context?: string; - sourceVideoCodec?: string; - sourceAudioCodec?: string; - videoDecision?: string; - audioDecision?: string; - protocol?: string; - container?: string; - videoCodec?: string; - audioCodec?: string; - audioChannels?: number; - transcodeHwRequested?: boolean; - timeStamp?: number; - maxOffsetAvailable?: number; - minOffsetAvailable?: number; - }[]; -} diff --git a/src/services/updater/Updater.ts b/src/services/updater/Updater.ts deleted file mode 100644 index d7cdfd55..00000000 --- a/src/services/updater/Updater.ts +++ /dev/null @@ -1,106 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { Download } from './models/Download'; -import { Tonight } from './models/Tonight'; -import { Skip } from './models/Skip'; - -import { serializeQuery } from '../../http/QuerySerializer'; - -export class UpdaterService extends BaseService { - /** - * @summary Querying status of updates - * @description Querying status of updates - - * @returns {Promise} - The promise with the result - */ - async getUpdateStatus(): Promise { - const urlEndpoint = '/updater/status'; - const finalUrl = `${this.baseUrl + urlEndpoint}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Checking for updates - * @description Checking for updates - - * @param optionalParams - Optional parameters - * @param optionalParams.download - Indicate that you want to start download any updates found. - * @returns {Promise} - The promise with the result - */ - async checkForUpdates(optionalParams: { download?: Download } = {}): Promise { - const { download } = optionalParams; - - const queryParams: string[] = []; - if (download) { - queryParams.push(serializeQuery('form', true, 'download', download)); - } - const urlEndpoint = '/updater/check'; - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.put( - finalUrl, - { download }, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Apply Updates - * @description Note that these two parameters are effectively mutually exclusive. The `tonight` parameter takes precedence and `skip` will be ignored if `tonight` is also passed - - - * @param optionalParams - Optional parameters - * @param optionalParams.tonight - Indicate that you want the update to run during the next Butler execution. Omitting this or setting it to false indicates that the update should install - * @param optionalParams.skip - Indicate that the latest version should be marked as skipped. The entry for this version will have the `state` set to `skipped`. - * @returns {Promise} - The promise with the result - */ - async applyUpdates(optionalParams: { tonight?: Tonight; skip?: Skip } = {}): Promise { - const { tonight, skip } = optionalParams; - - const queryParams: string[] = []; - if (tonight) { - queryParams.push(serializeQuery('form', true, 'tonight', tonight)); - } - if (skip) { - queryParams.push(serializeQuery('form', true, 'skip', skip)); - } - const urlEndpoint = '/updater/apply'; - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.put( - finalUrl, - { tonight, skip }, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/updater/index.ts b/src/services/updater/index.ts deleted file mode 100644 index 9518ba1d..00000000 --- a/src/services/updater/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type { Download } from './models/Download'; -export type { Skip } from './models/Skip'; -export type { Tonight } from './models/Tonight'; diff --git a/src/services/updater/models/Download.ts b/src/services/updater/models/Download.ts deleted file mode 100644 index 5b99d1f9..00000000 --- a/src/services/updater/models/Download.ts +++ /dev/null @@ -1 +0,0 @@ -export type Download = 0 | 1; diff --git a/src/services/updater/models/Skip.ts b/src/services/updater/models/Skip.ts deleted file mode 100644 index 963e6cee..00000000 --- a/src/services/updater/models/Skip.ts +++ /dev/null @@ -1 +0,0 @@ -export type Skip = 0 | 1; diff --git a/src/services/updater/models/Tonight.ts b/src/services/updater/models/Tonight.ts deleted file mode 100644 index 1eeb3492..00000000 --- a/src/services/updater/models/Tonight.ts +++ /dev/null @@ -1 +0,0 @@ -export type Tonight = 0 | 1; diff --git a/src/services/video/Video.ts b/src/services/video/Video.ts deleted file mode 100644 index 64134e35..00000000 --- a/src/services/video/Video.ts +++ /dev/null @@ -1,235 +0,0 @@ -import BaseService from '../../BaseService'; - -import Response from '../../http/Response'; - -import { State } from './models/State'; - -import { serializeQuery } from '../../http/QuerySerializer'; - -export class VideoService extends BaseService { - /** - * @summary Start Universal Transcode - * @description Begin a Universal Transcode Session - - * @param hasMDE Whether the media item has MDE - * @param path The path to the media item to transcode - * @param mediaIndex The index of the media item to transcode - * @param partIndex The index of the part to transcode - * @param protocol The protocol to use for the transcode session - * @param optionalParams - Optional parameters - * @param optionalParams.fastSeek - Whether to use fast seek or not - * @param optionalParams.directPlay - Whether to use direct play or not - * @param optionalParams.directStream - Whether to use direct stream or not - * @param optionalParams.subtitleSize - The size of the subtitles - * @param optionalParams.subtites - The subtitles - * @param optionalParams.audioBoost - The audio boost - * @param optionalParams.location - The location of the transcode session - * @param optionalParams.mediaBufferSize - The size of the media buffer - * @param optionalParams.session - The session ID - * @param optionalParams.addDebugOverlay - Whether to add a debug overlay or not - * @param optionalParams.autoAdjustQuality - Whether to auto adjust quality or not - * @returns {Promise} - The promise with the result - */ - async startUniversalTranscode( - hasMde: number, - path: string, - mediaIndex: number, - partIndex: number, - protocol: string, - optionalParams: { - fastSeek?: number; - directPlay?: number; - directStream?: number; - subtitleSize?: number; - subtites?: string; - audioBoost?: number; - location?: string; - mediaBufferSize?: number; - session?: string; - addDebugOverlay?: number; - autoAdjustQuality?: number; - } = {}, - ): Promise { - const { - fastSeek, - directPlay, - directStream, - subtitleSize, - subtites, - audioBoost, - location, - mediaBufferSize, - session, - addDebugOverlay, - autoAdjustQuality, - } = optionalParams; - if ( - hasMde === undefined || - path === undefined || - mediaIndex === undefined || - partIndex === undefined || - protocol === undefined - ) { - throw new Error( - 'The following are required parameters: hasMde,path,mediaIndex,partIndex,protocol, cannot be empty or blank', - ); - } - const queryParams: string[] = []; - if (hasMde) { - queryParams.push(serializeQuery('form', true, 'hasMDE', hasMde)); - } - if (path) { - queryParams.push(serializeQuery('form', true, 'path', path)); - } - if (mediaIndex) { - queryParams.push(serializeQuery('form', true, 'mediaIndex', mediaIndex)); - } - if (partIndex) { - queryParams.push(serializeQuery('form', true, 'partIndex', partIndex)); - } - if (protocol) { - queryParams.push(serializeQuery('form', true, 'protocol', protocol)); - } - if (fastSeek) { - queryParams.push(serializeQuery('form', true, 'fastSeek', fastSeek)); - } - if (directPlay) { - queryParams.push(serializeQuery('form', true, 'directPlay', directPlay)); - } - if (directStream) { - queryParams.push(serializeQuery('form', true, 'directStream', directStream)); - } - if (subtitleSize) { - queryParams.push(serializeQuery('form', true, 'subtitleSize', subtitleSize)); - } - if (subtites) { - queryParams.push(serializeQuery('form', true, 'subtites', subtites)); - } - if (audioBoost) { - queryParams.push(serializeQuery('form', true, 'audioBoost', audioBoost)); - } - if (location) { - queryParams.push(serializeQuery('form', true, 'location', location)); - } - if (mediaBufferSize) { - queryParams.push(serializeQuery('form', true, 'mediaBufferSize', mediaBufferSize)); - } - if (session) { - queryParams.push(serializeQuery('form', true, 'session', session)); - } - if (addDebugOverlay) { - queryParams.push(serializeQuery('form', true, 'addDebugOverlay', addDebugOverlay)); - } - if (autoAdjustQuality) { - queryParams.push(serializeQuery('form', true, 'autoAdjustQuality', autoAdjustQuality)); - } - const urlEndpoint = '/video/:/transcode/universal/start.mpd'; - const urlParams = queryParams.length > 0 ? `?${encodeURI(queryParams.join('&'))}` : ''; - const finalUrl = `${this.baseUrl + urlEndpoint}${urlParams}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } - - /** - * @summary Get the timeline for a media item - * @description Get the timeline for a media item - - * @param ratingKey The rating key of the media item - * @param key The key of the media item to get the timeline for - * @param state The state of the media item - * @param hasMDE Whether the media item has MDE - * @param time The time of the media item - * @param duration The duration of the media item - * @param context The context of the media item - * @param playQueueItemID The play queue item ID of the media item - * @param playBackTime The playback time of the media item - * @param row The row of the media item - * @returns {Promise} - The promise with the result - */ - async getTimeline( - ratingKey: number, - key: string, - state: State, - hasMde: number, - time: number, - duration: number, - context: string, - playQueueItemId: number, - playBackTime: number, - row: number, - ): Promise { - if ( - ratingKey === undefined || - key === undefined || - state === undefined || - hasMde === undefined || - time === undefined || - duration === undefined || - context === undefined || - playQueueItemId === undefined || - playBackTime === undefined || - row === undefined - ) { - throw new Error( - 'The following are required parameters: ratingKey,key,state,hasMde,time,duration,context,playQueueItemId,playBackTime,row, cannot be empty or blank', - ); - } - const queryParams: string[] = []; - if (ratingKey) { - queryParams.push(serializeQuery('form', true, 'ratingKey', ratingKey)); - } - if (key) { - queryParams.push(serializeQuery('form', true, 'key', key)); - } - if (state) { - queryParams.push(serializeQuery('form', true, 'state', state)); - } - if (hasMde) { - queryParams.push(serializeQuery('form', true, 'hasMDE', hasMde)); - } - if (time) { - queryParams.push(serializeQuery('form', true, 'time', time)); - } - if (duration) { - queryParams.push(serializeQuery('form', true, 'duration', duration)); - } - if (context) { - queryParams.push(serializeQuery('form', true, 'context', context)); - } - if (playQueueItemId) { - queryParams.push(serializeQuery('form', true, 'playQueueItemID', playQueueItemId)); - } - if (playBackTime) { - queryParams.push(serializeQuery('form', true, 'playBackTime', playBackTime)); - } - if (row) { - queryParams.push(serializeQuery('form', true, 'row', row)); - } - const urlEndpoint = '/:/timeline'; - const finalUrl = `${this.baseUrl + urlEndpoint}?${encodeURI(queryParams.join('&'))}`; - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = { - data: response.data, - headers: response.headers, - }; - return responseModel; - } -} diff --git a/src/services/video/index.ts b/src/services/video/index.ts deleted file mode 100644 index 234466e0..00000000 --- a/src/services/video/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { State } from './models/State'; diff --git a/src/services/video/models/State.ts b/src/services/video/models/State.ts deleted file mode 100644 index 07f9e46e..00000000 --- a/src/services/video/models/State.ts +++ /dev/null @@ -1 +0,0 @@ -export type State = 'playing' | 'paused' | 'stopped';