mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-06 04:20:46 +00:00
534 lines
22 KiB
C#
534 lines
22 KiB
C#
//------------------------------------------------------------------------------
|
|
// <auto-generated>
|
|
// This code was generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
//
|
|
// Changes to this file may cause incorrect behavior and will be lost when
|
|
// the code is regenerated.
|
|
// </auto-generated>
|
|
//------------------------------------------------------------------------------
|
|
#nullable enable
|
|
namespace LukeHagar.PlexAPI.SDK
|
|
{
|
|
using LukeHagar.PlexAPI.SDK.Hooks;
|
|
using LukeHagar.PlexAPI.SDK.Models.Components;
|
|
using LukeHagar.PlexAPI.SDK.Models.Errors;
|
|
using LukeHagar.PlexAPI.SDK.Utils;
|
|
using LukeHagar.PlexAPI.SDK.Utils.Retries;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
/// <summary>
|
|
/// The protocol to use for the server connection
|
|
/// </summary>
|
|
public enum ServerProtocol
|
|
{
|
|
[JsonProperty("http")]
|
|
Http,
|
|
[JsonProperty("https")]
|
|
Https,
|
|
}
|
|
|
|
public static class ServerProtocolExtension
|
|
{
|
|
public static string Value(this ServerProtocol value)
|
|
{
|
|
return ((JsonPropertyAttribute)value.GetType().GetMember(value.ToString())[0].GetCustomAttributes(typeof(JsonPropertyAttribute), false)[0]).PropertyName ?? value.ToString();
|
|
}
|
|
|
|
public static ServerProtocol ToEnum(this string value)
|
|
{
|
|
foreach(var field in typeof(ServerProtocol).GetFields())
|
|
{
|
|
var attributes = field.GetCustomAttributes(typeof(JsonPropertyAttribute), false);
|
|
if (attributes.Length == 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var attribute = attributes[0] as JsonPropertyAttribute;
|
|
if (attribute != null && attribute.PropertyName == value)
|
|
{
|
|
var enumVal = field.GetValue(null);
|
|
|
|
if (enumVal is ServerProtocol)
|
|
{
|
|
return (ServerProtocol)enumVal;
|
|
}
|
|
}
|
|
}
|
|
|
|
throw new Exception($"Unknown value {value} for enum ServerProtocol");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Plex-API: An Open API Spec for interacting with Plex.tv and Plex Media Server
|
|
///
|
|
/// <remarks>
|
|
/// # Plex Media Server OpenAPI Specification<br/>
|
|
/// <br/>
|
|
/// An Open Source OpenAPI Specification for Plex Media Server<br/>
|
|
/// <br/>
|
|
/// Automation and SDKs provided by <a href="https://speakeasyapi.dev/">Speakeasy</a><br/>
|
|
/// <br/>
|
|
/// ## Documentation<br/>
|
|
/// <br/>
|
|
/// <a href="https://plexapi.dev">API Documentation</a><br/>
|
|
/// <br/>
|
|
/// ## SDKs<br/>
|
|
/// <br/>
|
|
/// The following SDKs are generated from the OpenAPI Specification. They are automatically generated and may not be fully tested. If you find any issues, please open an issue on the <a href="https://github.com/LukeHagar/plex-api-spec">main specification Repository</a>.<br/>
|
|
/// <br/>
|
|
/// | Language | Repository | Releases | Other |<br/>
|
|
/// | --------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------- |<br/>
|
|
/// | Python | <a href="https://github.com/LukeHagar/plexpy">GitHub</a> | <a href="https://pypi.org/project/plex-api-client/">PyPI</a> | - |<br/>
|
|
/// | JavaScript/TypeScript | <a href="https://github.com/LukeHagar/plexjs">GitHub</a> | <a href="https://www.npmjs.com/package/@lukehagar/plexjs">NPM</a> \ <a href="https://jsr.io/@lukehagar/plexjs">JSR</a> | - |<br/>
|
|
/// | Go | <a href="https://github.com/LukeHagar/plexgo">GitHub</a> | <a href="https://github.com/LukeHagar/plexgo/releases">Releases</a> | <a href="https://pkg.go.dev/github.com/LukeHagar/plexgo">GoDoc</a> |<br/>
|
|
/// | Ruby | <a href="https://github.com/LukeHagar/plexruby">GitHub</a> | <a href="https://github.com/LukeHagar/plexruby/releases">Releases</a> | - |<br/>
|
|
/// | Swift | <a href="https://github.com/LukeHagar/plexswift">GitHub</a> | <a href="https://github.com/LukeHagar/plexswift/releases">Releases</a> | - |<br/>
|
|
/// | PHP | <a href="https://github.com/LukeHagar/plexphp">GitHub</a> | <a href="https://github.com/LukeHagar/plexphp/releases">Releases</a> | - |<br/>
|
|
/// | Java | <a href="https://github.com/LukeHagar/plexjava">GitHub</a> | <a href="https://github.com/LukeHagar/plexjava/releases">Releases</a> | - |<br/>
|
|
/// | C# | <a href="https://github.com/LukeHagar/plexcsharp">GitHub</a> | <a href="https://github.com/LukeHagar/plexcsharp/releases">Releases</a> | -<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public interface IPlexAPI
|
|
{
|
|
|
|
/// <summary>
|
|
/// Operations against the Plex Media Server System.<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public IServer Server { get; }
|
|
|
|
/// <summary>
|
|
/// API Calls interacting with Plex Media Server Media<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public IMedia Media { get; }
|
|
|
|
/// <summary>
|
|
/// API Calls that perform operations with Plex Media Server Videos<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public IVideo Video { get; }
|
|
|
|
/// <summary>
|
|
/// Activities are awesome. They provide a way to monitor and control asynchronous operations on the server. In order to receive real-time updates for activities, a client would normally subscribe via either EventSource or Websocket endpoints.<br/>
|
|
///
|
|
/// <remarks>
|
|
/// Activities are associated with HTTP replies via a special `X-Plex-Activity` header which contains the UUID of the activity.<br/>
|
|
/// Activities are optional cancellable. If cancellable, they may be cancelled via the `DELETE` endpoint. Other details:<br/>
|
|
/// - They can contain a `progress` (from 0 to 100) marking the percent completion of the activity.<br/>
|
|
/// - They must contain an `type` which is used by clients to distinguish the specific activity.<br/>
|
|
/// - They may contain a `Context` object with attributes which associate the activity with various specific entities (items, libraries, etc.)<br/>
|
|
/// - The may contain a `Response` object which attributes which represent the result of the asynchronous operation.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public IActivities Activities { get; }
|
|
|
|
/// <summary>
|
|
/// Butler is the task manager of the Plex Media Server Ecosystem.<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public IButler Butler { get; }
|
|
|
|
/// <summary>
|
|
/// API Calls that perform operations directly against https://Plex.tv<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public IPlex Plex { get; }
|
|
|
|
/// <summary>
|
|
/// Hubs are a structured two-dimensional container for media, generally represented by multiple horizontal rows.<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public IHubs Hubs { get; }
|
|
|
|
/// <summary>
|
|
/// API Calls that perform search operations with Plex Media Server<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public ISearch Search { get; }
|
|
|
|
/// <summary>
|
|
/// API Calls interacting with Plex Media Server Libraries<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public ILibrary Library { get; }
|
|
|
|
/// <summary>
|
|
/// API Calls that perform operations with Plex Media Server Watchlists<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public IWatchlist Watchlist { get; }
|
|
|
|
/// <summary>
|
|
/// Submit logs to the Log Handler for Plex Media Server<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public ILog Log { get; }
|
|
|
|
/// <summary>
|
|
/// Playlists are ordered collections of media. They can be dumb (just a list of media) or smart (based on a media query, such as "all albums from 2017").<br/>
|
|
///
|
|
/// <remarks>
|
|
/// They can be organized in (optionally nesting) folders.<br/>
|
|
/// Retrieving a playlist, or its items, will trigger a refresh of its metadata.<br/>
|
|
/// This may cause the duration and number of items to change.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public IPlaylists Playlists { get; }
|
|
|
|
/// <summary>
|
|
/// API Calls regarding authentication for Plex Media Server<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public IAuthentication Authentication { get; }
|
|
|
|
/// <summary>
|
|
/// API Calls that perform operations with Plex Media Server Statistics<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public IStatistics Statistics { get; }
|
|
|
|
/// <summary>
|
|
/// API Calls that perform search operations with Plex Media Server Sessions<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public ISessions Sessions { get; }
|
|
|
|
/// <summary>
|
|
/// This describes the API for searching and applying updates to the Plex Media Server.<br/>
|
|
///
|
|
/// <remarks>
|
|
/// Updates to the status can be observed via the Event API.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public IUpdater Updater { get; }
|
|
public IUsers Users { get; }
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Plex-API: An Open API Spec for interacting with Plex.tv and Plex Media Server
|
|
///
|
|
/// <remarks>
|
|
/// # Plex Media Server OpenAPI Specification<br/>
|
|
/// <br/>
|
|
/// An Open Source OpenAPI Specification for Plex Media Server<br/>
|
|
/// <br/>
|
|
/// Automation and SDKs provided by <a href="https://speakeasyapi.dev/">Speakeasy</a><br/>
|
|
/// <br/>
|
|
/// ## Documentation<br/>
|
|
/// <br/>
|
|
/// <a href="https://plexapi.dev">API Documentation</a><br/>
|
|
/// <br/>
|
|
/// ## SDKs<br/>
|
|
/// <br/>
|
|
/// The following SDKs are generated from the OpenAPI Specification. They are automatically generated and may not be fully tested. If you find any issues, please open an issue on the <a href="https://github.com/LukeHagar/plex-api-spec">main specification Repository</a>.<br/>
|
|
/// <br/>
|
|
/// | Language | Repository | Releases | Other |<br/>
|
|
/// | --------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------- |<br/>
|
|
/// | Python | <a href="https://github.com/LukeHagar/plexpy">GitHub</a> | <a href="https://pypi.org/project/plex-api-client/">PyPI</a> | - |<br/>
|
|
/// | JavaScript/TypeScript | <a href="https://github.com/LukeHagar/plexjs">GitHub</a> | <a href="https://www.npmjs.com/package/@lukehagar/plexjs">NPM</a> \ <a href="https://jsr.io/@lukehagar/plexjs">JSR</a> | - |<br/>
|
|
/// | Go | <a href="https://github.com/LukeHagar/plexgo">GitHub</a> | <a href="https://github.com/LukeHagar/plexgo/releases">Releases</a> | <a href="https://pkg.go.dev/github.com/LukeHagar/plexgo">GoDoc</a> |<br/>
|
|
/// | Ruby | <a href="https://github.com/LukeHagar/plexruby">GitHub</a> | <a href="https://github.com/LukeHagar/plexruby/releases">Releases</a> | - |<br/>
|
|
/// | Swift | <a href="https://github.com/LukeHagar/plexswift">GitHub</a> | <a href="https://github.com/LukeHagar/plexswift/releases">Releases</a> | - |<br/>
|
|
/// | PHP | <a href="https://github.com/LukeHagar/plexphp">GitHub</a> | <a href="https://github.com/LukeHagar/plexphp/releases">Releases</a> | - |<br/>
|
|
/// | Java | <a href="https://github.com/LukeHagar/plexjava">GitHub</a> | <a href="https://github.com/LukeHagar/plexjava/releases">Releases</a> | - |<br/>
|
|
/// | C# | <a href="https://github.com/LukeHagar/plexcsharp">GitHub</a> | <a href="https://github.com/LukeHagar/plexcsharp/releases">Releases</a> | -<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public class PlexAPI: IPlexAPI
|
|
{
|
|
public SDKConfig SDKConfiguration { get; private set; }
|
|
|
|
private const string _language = "csharp";
|
|
private const string _sdkVersion = "0.16.0";
|
|
private const string _sdkGenVersion = "2.674.1";
|
|
private const string _openapiDocVersion = "0.0.3";
|
|
public IServer Server { get; private set; }
|
|
public IMedia Media { get; private set; }
|
|
public IVideo Video { get; private set; }
|
|
public IActivities Activities { get; private set; }
|
|
public IButler Butler { get; private set; }
|
|
public IPlex Plex { get; private set; }
|
|
public IHubs Hubs { get; private set; }
|
|
public ISearch Search { get; private set; }
|
|
public ILibrary Library { get; private set; }
|
|
public IWatchlist Watchlist { get; private set; }
|
|
public ILog Log { get; private set; }
|
|
public IPlaylists Playlists { get; private set; }
|
|
public IAuthentication Authentication { get; private set; }
|
|
public IStatistics Statistics { get; private set; }
|
|
public ISessions Sessions { get; private set; }
|
|
public IUpdater Updater { get; private set; }
|
|
public IUsers Users { get; private set; }
|
|
|
|
public PlexAPI(SDKConfig config)
|
|
{
|
|
SDKConfiguration = config;
|
|
InitHooks();
|
|
|
|
Server = new Server(SDKConfiguration);
|
|
|
|
Media = new Media(SDKConfiguration);
|
|
|
|
Video = new Video(SDKConfiguration);
|
|
|
|
Activities = new Activities(SDKConfiguration);
|
|
|
|
Butler = new Butler(SDKConfiguration);
|
|
|
|
Plex = new Plex(SDKConfiguration);
|
|
|
|
Hubs = new Hubs(SDKConfiguration);
|
|
|
|
Search = new Search(SDKConfiguration);
|
|
|
|
Library = new Library(SDKConfiguration);
|
|
|
|
Watchlist = new Watchlist(SDKConfiguration);
|
|
|
|
Log = new Log(SDKConfiguration);
|
|
|
|
Playlists = new Playlists(SDKConfiguration);
|
|
|
|
Authentication = new Authentication(SDKConfiguration);
|
|
|
|
Statistics = new Statistics(SDKConfiguration);
|
|
|
|
Sessions = new Sessions(SDKConfiguration);
|
|
|
|
Updater = new Updater(SDKConfiguration);
|
|
|
|
Users = new Users(SDKConfiguration);
|
|
}
|
|
|
|
public PlexAPI(string? accessToken = null, Func<string>? accessTokenSource = null, int? serverIndex = null, ServerProtocol? protocol = null, string? ip = null, string? port = null, string? serverUrl = null, Dictionary<string, string>? urlParams = null, ISpeakeasyHttpClient? client = null, RetryConfig? retryConfig = null)
|
|
{
|
|
if (serverIndex != null)
|
|
{
|
|
if (serverIndex.Value < 0 || serverIndex.Value >= SDKConfig.ServerList.Length)
|
|
{
|
|
throw new Exception($"Invalid server index {serverIndex.Value}");
|
|
}
|
|
}
|
|
|
|
if (serverUrl != null)
|
|
{
|
|
if (urlParams != null)
|
|
{
|
|
serverUrl = Utilities.TemplateUrl(serverUrl, urlParams);
|
|
}
|
|
}
|
|
Func<LukeHagar.PlexAPI.SDK.Models.Components.Security>? _securitySource = null;
|
|
|
|
if(accessTokenSource != null)
|
|
{
|
|
_securitySource = () => new LukeHagar.PlexAPI.SDK.Models.Components.Security() { AccessToken = accessTokenSource() };
|
|
}
|
|
else if(accessToken != null)
|
|
{
|
|
_securitySource = () => new LukeHagar.PlexAPI.SDK.Models.Components.Security() { AccessToken = accessToken };
|
|
}
|
|
|
|
SDKConfiguration = new SDKConfig(client)
|
|
{
|
|
ServerIndex = serverIndex == null ? 0 : serverIndex.Value,
|
|
ServerUrl = serverUrl == null ? "" : serverUrl,
|
|
SecuritySource = _securitySource,
|
|
RetryConfig = retryConfig
|
|
};
|
|
|
|
if (protocol != null)
|
|
{
|
|
SDKConfiguration.SetServerVariable("protocol", ServerProtocolExtension.Value(protocol.Value));
|
|
}
|
|
|
|
if (ip != null)
|
|
{
|
|
SDKConfiguration.SetServerVariable("ip", ip);
|
|
}
|
|
|
|
if (port != null)
|
|
{
|
|
SDKConfiguration.SetServerVariable("port", port);
|
|
}
|
|
|
|
InitHooks();
|
|
|
|
Server = new Server(SDKConfiguration);
|
|
|
|
Media = new Media(SDKConfiguration);
|
|
|
|
Video = new Video(SDKConfiguration);
|
|
|
|
Activities = new Activities(SDKConfiguration);
|
|
|
|
Butler = new Butler(SDKConfiguration);
|
|
|
|
Plex = new Plex(SDKConfiguration);
|
|
|
|
Hubs = new Hubs(SDKConfiguration);
|
|
|
|
Search = new Search(SDKConfiguration);
|
|
|
|
Library = new Library(SDKConfiguration);
|
|
|
|
Watchlist = new Watchlist(SDKConfiguration);
|
|
|
|
Log = new Log(SDKConfiguration);
|
|
|
|
Playlists = new Playlists(SDKConfiguration);
|
|
|
|
Authentication = new Authentication(SDKConfiguration);
|
|
|
|
Statistics = new Statistics(SDKConfiguration);
|
|
|
|
Sessions = new Sessions(SDKConfiguration);
|
|
|
|
Updater = new Updater(SDKConfiguration);
|
|
|
|
Users = new Users(SDKConfiguration);
|
|
}
|
|
|
|
private void InitHooks()
|
|
{
|
|
string preHooksUrl = SDKConfiguration.GetTemplatedServerUrl();
|
|
var (postHooksUrl, postHooksClient) = SDKConfiguration.Hooks.SDKInit(preHooksUrl, SDKConfiguration.Client);
|
|
var config = SDKConfiguration;
|
|
if (preHooksUrl != postHooksUrl)
|
|
{
|
|
config.ServerUrl = postHooksUrl;
|
|
}
|
|
config.Client = postHooksClient;
|
|
SDKConfiguration = config;
|
|
}
|
|
|
|
public class SDKBuilder
|
|
{
|
|
private SDKConfig _sdkConfig = new SDKConfig(client: new SpeakeasyHttpClient());
|
|
|
|
public SDKBuilder() { }
|
|
|
|
public SDKBuilder WithServerIndex(int serverIndex)
|
|
{
|
|
if (serverIndex < 0 || serverIndex >= SDKConfig.ServerList.Length)
|
|
{
|
|
throw new Exception($"Invalid server index {serverIndex}");
|
|
}
|
|
_sdkConfig.ServerIndex = serverIndex;
|
|
return this;
|
|
}
|
|
|
|
public SDKBuilder WithProtocol(ServerProtocol protocol)
|
|
{
|
|
_sdkConfig.SetServerVariable("protocol", ServerProtocolExtension.Value(protocol));
|
|
return this;
|
|
}
|
|
|
|
public SDKBuilder WithIp(string ip)
|
|
{
|
|
_sdkConfig.SetServerVariable("ip", ip);
|
|
return this;
|
|
}
|
|
|
|
public SDKBuilder WithPort(string port)
|
|
{
|
|
_sdkConfig.SetServerVariable("port", port);
|
|
return this;
|
|
}
|
|
|
|
public SDKBuilder WithServerUrl(string serverUrl, Dictionary<string, string>? serverVariables = null)
|
|
{
|
|
if (serverVariables != null)
|
|
{
|
|
serverUrl = Utilities.TemplateUrl(serverUrl, serverVariables);
|
|
}
|
|
_sdkConfig.ServerUrl = serverUrl;
|
|
return this;
|
|
}
|
|
|
|
public SDKBuilder WithAccessTokenSource(Func<string> accessTokenSource)
|
|
{
|
|
_sdkConfig.SecuritySource = () => new LukeHagar.PlexAPI.SDK.Models.Components.Security() { AccessToken = accessTokenSource() };
|
|
return this;
|
|
}
|
|
|
|
public SDKBuilder WithAccessToken(string accessToken)
|
|
{
|
|
_sdkConfig.SecuritySource = () => new LukeHagar.PlexAPI.SDK.Models.Components.Security() { AccessToken = accessToken };
|
|
return this;
|
|
}
|
|
|
|
public SDKBuilder WithClient(ISpeakeasyHttpClient client)
|
|
{
|
|
_sdkConfig.Client = client;
|
|
return this;
|
|
}
|
|
|
|
public SDKBuilder WithRetryConfig(RetryConfig retryConfig)
|
|
{
|
|
_sdkConfig.RetryConfig = retryConfig;
|
|
return this;
|
|
}
|
|
|
|
public PlexAPI Build()
|
|
{
|
|
return new PlexAPI(_sdkConfig);
|
|
}
|
|
|
|
}
|
|
|
|
public static SDKBuilder Builder() => new SDKBuilder();
|
|
}
|
|
} |