//------------------------------------------------------------------------------ // // This code was generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. // // Changes to this file may cause incorrect behavior and will be lost when // the code is regenerated. // //------------------------------------------------------------------------------ #nullable enable namespace PlexAPI { using Newtonsoft.Json; using PlexAPI.Models.Components; using PlexAPI.Models.Requests; using PlexAPI.Utils; using System.Net.Http.Headers; using System.Net.Http; using System.Threading.Tasks; using System; /// /// API Calls interacting with Plex Media Server Libraries
/// /// /// /// ///
public interface ILibrary { /// /// Get Hash Value /// /// /// This resource returns hash values for local files /// /// Task GetFileHashAsync(string url, double? type = null); /// /// Get Recently Added /// /// /// This endpoint will return the recently added content.
/// ///
///
Task GetRecentlyAddedAsync(); /// /// Get All Libraries /// /// /// 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).
/// ///
///
Task GetLibrariesAsync(); /// /// Get Library Details /// /// /// ## Library Details Endpoint
///
/// This endpoint provides comprehensive details about the library, focusing on organizational aspects rather than the content itself.
///
/// The details include:
///
/// ### Directories
/// Organized into three categories:
///
/// - **Primary Directories**:
/// - Used in some clients for quick access to media subsets (e.g., "All", "On Deck").
/// - Most can be replicated via media queries.
/// - Customizable by users.
///
/// - **Secondary Directories**:
/// - Marked with `secondary="1"`.
/// - Used in older clients for structured navigation.
///
/// - **Special Directories**:
/// - Includes a "By Folder" entry for filesystem-based browsing.
/// - Contains an obsolete `search="1"` entry for on-the-fly search dialog creation.
///
/// ### Types
/// Each type in the library comes with a set of filters and sorts, aiding in building dynamic media controls:
///
/// - **Type Object Attributes**:
/// - `key`: Endpoint for the media list of this type.
/// - `type`: Metadata type (if standard Plex type).
/// - `title`: Title for this content type (e.g., "Movies").
///
/// - **Filter Objects**:
/// - Subset of the media query language.
/// - Attributes include `filter` (name), `filterType` (data type), `key` (endpoint for value range), and `title`.
///
/// - **Sort Objects**:
/// - Description of sort fields.
/// - Attributes include `defaultDirection` (asc/desc), `descKey` and `key` (sort parameters), and `title`.
///
/// > **Note**: Filters and sorts are optional; without them, no filtering controls are rendered.
/// ///
///
Task GetLibraryAsync(double sectionId, IncludeDetails? includeDetails = null); /// /// Delete Library Section /// /// /// Delate a library using a specific section /// /// Task DeleteLibraryAsync(double sectionId); /// /// Get Library Items /// /// /// Fetches details from a specific section of the library identified by a section key and a tag. The tag parameter accepts the following values:
/// - `all`: All items in the section.
/// - `unwatched`: Items that have not been played.
/// - `newest`: Items that are recently released.
/// - `recentlyAdded`: Items that are recently added to the library.
/// - `recentlyViewed`: Items that were recently viewed.
/// - `onDeck`: Items to continue watching.
/// - `collection`: Items categorized by collection.
/// - `edition`: Items categorized by edition.
/// - `genre`: Items categorized by genre.
/// - `year`: Items categorized by year of release.
/// - `decade`: Items categorized by decade.
/// - `director`: Items categorized by director.
/// - `actor`: Items categorized by starring actor.
/// - `country`: Items categorized by country of origin.
/// - `contentRating`: Items categorized by content rating.
/// - `rating`: Items categorized by rating.
/// - `resolution`: Items categorized by resolution.
/// - `firstCharacter`: Items categorized by the first letter.
/// - `folder`: Items categorized by folder.
/// ///
///
Task GetLibraryItemsAsync(long sectionId, Tag tag); /// /// Refresh Library /// /// /// This endpoint Refreshes the library.
/// ///
///
Task RefreshLibraryAsync(double sectionId); /// /// Search Library /// /// /// Search for content within a specific section of the library.
///
/// ### Types
/// Each type in the library comes with a set of filters and sorts, aiding in building dynamic media controls:
///
/// - **Type Object Attributes**:
/// - `type`: Metadata type (if standard Plex type).
/// - `title`: Title for this content type (e.g., "Movies").
///
/// - **Filter Objects**:
/// - Subset of the media query language.
/// - Attributes include `filter` (name), `filterType` (data type), `key` (endpoint for value range), and `title`.
///
/// - **Sort Objects**:
/// - Description of sort fields.
/// - Attributes include `defaultDirection` (asc/desc), `descKey` and `key` (sort parameters), and `title`.
///
/// > **Note**: Filters and sorts are optional; without them, no filtering controls are rendered.
/// ///
///
Task SearchLibraryAsync(long sectionId, Type type); /// /// Get Items Metadata /// /// /// This endpoint will return the metadata of a library item specified with the ratingKey.
/// ///
///
Task GetMetadataAsync(double ratingKey); /// /// Get Items Children /// /// /// This endpoint will return the children of of a library item specified with the ratingKey.
/// ///
///
Task GetMetadataChildrenAsync(double ratingKey); /// /// Get On Deck /// /// /// This endpoint will return the on deck content.
/// ///
///
Task GetOnDeckAsync(); } /// /// API Calls interacting with Plex Media Server Libraries
/// /// /// /// ///
public class Library: ILibrary { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; private const string _sdkVersion = "0.2.0"; private const string _sdkGenVersion = "2.277.0"; private const string _openapiDocVersion = "0.0.3"; private const string _userAgent = "speakeasy-sdk/csharp 0.2.0 2.277.0 0.0.3 Plex-API"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; public Library(ISpeakeasyHttpClient defaultClient, Func? securitySource, string serverUrl, SDKConfig config) { _defaultClient = defaultClient; _securitySource = securitySource; _serverUrl = serverUrl; SDKConfiguration = config; } public async Task GetFileHashAsync(string url, double? type = null) { var request = new GetFileHashRequest() { Url = url, Type = type, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = URLBuilder.Build(baseUrl, "/library/hashes", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new GetFileHashResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200) || (response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.Object = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task GetRecentlyAddedAsync() { string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = baseUrl + "/library/recentlyAdded"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new GetRecentlyAddedResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } if((response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task GetLibrariesAsync() { string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = baseUrl + "/library/sections"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new GetLibrariesResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } if((response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task GetLibraryAsync(double sectionId, IncludeDetails? includeDetails = null) { var request = new GetLibraryRequest() { SectionId = sectionId, IncludeDetails = includeDetails, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = URLBuilder.Build(baseUrl, "/library/sections/{sectionId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new GetLibraryResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } if((response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task DeleteLibraryAsync(double sectionId) { var request = new DeleteLibraryRequest() { SectionId = sectionId, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = URLBuilder.Build(baseUrl, "/library/sections/{sectionId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Delete, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new DeleteLibraryResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200) || (response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.Object = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task GetLibraryItemsAsync(long sectionId, Tag tag) { var request = new GetLibraryItemsRequest() { SectionId = sectionId, Tag = tag, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = URLBuilder.Build(baseUrl, "/library/sections/{sectionId}/{tag}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new GetLibraryItemsResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.Object = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task RefreshLibraryAsync(double sectionId) { var request = new RefreshLibraryRequest() { SectionId = sectionId, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = URLBuilder.Build(baseUrl, "/library/sections/{sectionId}/refresh", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new RefreshLibraryResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200) || (response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.Object = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task SearchLibraryAsync(long sectionId, Type type) { var request = new SearchLibraryRequest() { SectionId = sectionId, Type = type, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = URLBuilder.Build(baseUrl, "/library/sections/{sectionId}/search", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new SearchLibraryResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.Object = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task GetMetadataAsync(double ratingKey) { var request = new GetMetadataRequest() { RatingKey = ratingKey, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = URLBuilder.Build(baseUrl, "/library/metadata/{ratingKey}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new GetMetadataResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } if((response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task GetMetadataChildrenAsync(double ratingKey) { var request = new GetMetadataChildrenRequest() { RatingKey = ratingKey, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = URLBuilder.Build(baseUrl, "/library/metadata/{ratingKey}/children", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new GetMetadataChildrenResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } if((response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task GetOnDeckAsync() { string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = baseUrl + "/library/onDeck"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new GetOnDeckResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } if((response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } } }