import type { Class } from 'type-fest'; import { Album, Artist, Track } from './audio.ts'; import { PartialPlexObject } from './base/partialPlexObject.ts'; import { PlexObject } from './base/plexObject.ts'; import { type ItemFilterValue, type QueryParamValue } from './baseFunctionality.ts'; import type { CommonData, CollectionData, Directory as LibraryDirectory, FirstCharacterData, FilterChoiceData, FilteringFieldData, FilteringFieldTypeData, FilteringFilterData, FilteringOperatorData, FilteringSortData, FilteringTypeData, FolderData, LibraryRootResponse, LibraryTagData, LibraryTimelineData, Location, ManagedHubData, SectionsDirectory } from './library.types.ts'; import { Chapter, Collection, Country, Director, Field, Format, Genre, Guid, Label, Marker, Mood, Producer, Rating, Role, Similar, Style, Subformat, Tag, Writer } from './media.ts'; import { Photo, Photoalbum } from './photo.ts'; import { Playlist, type CreateRegularPlaylistOptions, type CreateSmartPlaylistOptions } from './playlist.ts'; import { type Agent, SEARCHTYPES } from './search.ts'; import type { SearchResultContainer } from './search.types.ts'; import type { PlexServer } from './server.ts'; import type { HistoryOptions, HistoryResult } from './server.types.ts'; import { Setting, type SettingValue } from './settings.ts'; import { Clip, Episode, Movie, Season, Show } from './video.ts'; export type Section = MovieSection | ShowSection | MusicSection | PhotoSection; export type LibraryHubOptionValue = QueryParamValue | ReadonlyArray; export type LibrarySectionCreateType = 'artist' | 'movie' | 'photo' | 'show'; export type LibrarySectionAgent = string; export type LibrarySectionScanner = string; export type SectionForCreateType = T extends 'movie' ? MovieSection : T extends 'show' ? ShowSection : T extends 'artist' ? MusicSection : PhotoSection; export interface LibraryAddOptions { /** Library section title. */ name: string; /** Plex library section type. */ type: T; /** Metadata agent identifier, such as `tv.plex.agents.movie`. */ agent: LibrarySectionAgent; /** Scanner name, such as `Plex Movie`. */ scanner: LibrarySectionScanner; /** One or more server-visible folder paths to add to this section. */ locations: string | readonly string[]; /** Library language. Defaults to `en-US`, matching Plex/Python behavior. */ language?: string; /** Advanced preference values. Keys are encoded as `prefs[]`. */ preferences?: Record; } export interface LibraryHubsOptions { /** IDs of the sections to limit results to, or "playlists". */ sectionID?: string | number | ReadonlyArray; /** Hub identifiers to limit results to, such as "home.continue". */ identifier?: string | readonly string[]; [param: string]: LibraryHubOptionValue | undefined; } export interface LibrarySearchOptions { /** Exact or partial title query. */ title?: string; /** Limit results to a Plex library type. */ libtype?: Libtype; [param: string]: QueryParamValue; } export type LibraryHistoryOptions = Omit; export declare const LIBRARY_TAG_TYPES: { readonly tag: 0; readonly genre: 1; readonly collection: 2; readonly director: 4; readonly writer: 5; readonly role: 6; readonly producer: 7; readonly country: 8; readonly chapter: 9; readonly review: 10; readonly label: 11; readonly marker: 12; readonly mediaProcessingTarget: 42; readonly make: 200; readonly model: 201; readonly aperture: 202; readonly exposure: 203; readonly iso: 204; readonly lens: 205; readonly device: 206; readonly autotag: 207; readonly mood: 300; readonly style: 301; readonly format: 302; readonly subformat: 303; readonly similar: 305; readonly concert: 306; readonly banner: 311; readonly poster: 312; readonly art: 313; readonly guid: 314; readonly ratingImage: 316; readonly theme: 317; readonly studio: 318; readonly network: 319; readonly showOrdering: 322; readonly clearLogo: 323; readonly commonSenseMedia: 324; readonly squareArt: 325; readonly place: 400; readonly sharedWidth: 500; }; export type LibraryTagName = keyof typeof LIBRARY_TAG_TYPES; export type LibraryTagType = LibraryTagName | number | `${number}`; export interface LibraryTagItems { /** Number of library items with this tag, when Plex provides it. */ count?: number; /** Filter expression Plex uses for this tag. */ filter?: string; /** Tag id. */ id?: number | string; /** Library section id this tag belongs to, when scoped. */ librarySectionID?: number; /** Library section key this tag belongs to, when scoped. */ librarySectionKey?: string; /** Library section title this tag belongs to, when scoped. */ librarySectionTitle?: string; /** Numeric Plex section type this tag belongs to, when scoped. */ librarySectionType?: number; /** Search result reason, when the tag came from a search payload. */ reason?: string; /** Search result reason id, when Plex provides it. */ reasonID?: number; /** Search result reason title, when Plex provides it. */ reasonTitle?: string; /** Search score, when the tag came from a search payload. */ score?: number; /** Search result type. */ type?: string; /** Tag title. */ tag: string; /** Plex Discover rating key for person tags, when available. */ tagKey?: string; /** Numeric Plex tag type. */ tagType?: number; /** Numeric Plex tag value, when available. */ tagValue?: number; /** Tag thumbnail, when available. */ thumb?: string; /** Fetches the library items matching this tag. */ items(): Promise; } export type LibraryTagItemFor = T extends 'tag' ? Tag & LibraryTagItems : T extends 'genre' ? Genre & LibraryTagItems : T extends 'collection' ? Collection & LibraryTagItems : T extends 'director' ? Director & LibraryTagItems : T extends 'writer' ? Writer & LibraryTagItems : T extends 'role' ? Role & LibraryTagItems : T extends 'producer' ? Producer & LibraryTagItems : T extends 'country' ? Country & LibraryTagItems : T extends 'chapter' ? Chapter & LibraryTagItems : T extends 'label' ? Label & LibraryTagItems : T extends 'marker' ? Marker & LibraryTagItems : T extends 'mood' ? Mood & LibraryTagItems : T extends 'style' ? Style & LibraryTagItems : T extends 'format' ? Format & LibraryTagItems : T extends 'subformat' ? Subformat & LibraryTagItems : T extends 'similar' ? Similar & LibraryTagItems : LibraryMediaTag; export declare class Library { static key: string; private readonly server; /** Number of root library entries returned by Plex. */ size: number; /** Whether sync is allowed for the root library endpoint. */ allowSync: boolean; /** Root library artwork path. */ art: string; /** Root library content type. */ content: string; /** Unknown ('com.plexapp.plugins.library') */ identifier: string; /** Unknown (/system/bundle/media/flags/) */ mediaTagPrefix: string; /** Version for media tag assets. */ mediaTagVersion: number; /** 'Plex Library' (not sure how useful this is) */ title1: string; /** Second title (this is blank on my setup) */ title2: string; /** Root library directories returned by Plex. */ directories: LibraryDirectory[]; constructor(server: PlexServer, data: LibraryRootResponse); /** * @returns a list of all media sections in this library. Library sections may be any of */ sections(): Promise; section(title: string): Promise; sectionByID(sectionId: string | number): Promise; /** * Creates a library section and returns the newly created typed section. * * Pass server-visible paths in `locations`. Preference keys should be bare Plex * setting ids; this method encodes them as `prefs[...]`. * * @example * ```ts * const section = await library.add({ * name: 'Movies', * type: 'movie', * agent: 'tv.plex.agents.movie', * scanner: 'Plex Movie', * locations: ['/data/Movies', '/data/Archived Movies'], * preferences: { enableBIFGeneration: false }, * }) * ``` * * Parameters: * name (str): Name of the library * agent (str): Example com.plexapp.agents.imdb * type (str): movie, show, # check me * location (str): /path/to/files * language (str): Two letter language fx en * kwargs (dict): Advanced options should be passed as a dict. where the id is the key. * * **Photo Preferences** * * * **agent** (str): com.plexapp.agents.none * * **enableAutoPhotoTags** (bool): Tag photos. Default value false. * * **enableBIFGeneration** (bool): Enable video preview thumbnails. Default value true. * * **includeInGlobal** (bool): Include in dashboard. Default value true. * * **scanner** (str): Plex Photo Scanner * * **Movie Preferences** * * * **agent** (str): com.plexapp.agents.none, com.plexapp.agents.imdb, com.plexapp.agents.themoviedb * * **enableBIFGeneration** (bool): Enable video preview thumbnails. Default value true. * * **enableCinemaTrailers** (bool): Enable Cinema Trailers. Default value true. * * **includeInGlobal** (bool): Include in dashboard. Default value true. * * **scanner** (str): Plex Movie Scanner, Plex Video Files Scanner * * **IMDB Movie Options** (com.plexapp.agents.imdb) * * * **title** (bool): Localized titles. Default value false. * * **extras** (bool): Find trailers and extras automatically (Plex Pass required). Default value true. * * **only_trailers** (bool): Skip extras which aren't trailers. Default value false. * * **redband** (bool): Use red band (restricted audiences) trailers when available. Default value false. * * **native_subs** (bool): Include extras with subtitles in Library language. Default value false. * * **cast_list** (int): Cast List Source: Default value 1 Possible options: 0:IMDb,1:The Movie Database. * * **ratings** (int): Ratings Source, Default value 0 Possible options: * 0:Rotten Tomatoes, 1:IMDb, 2:The Movie Database. * * **summary** (int): Plot Summary Source: Default value 1 Possible options: 0:IMDb,1:The Movie Database. * * **country** (int): Default value 46 Possible options 0:Argentina, 1:Australia, 2:Austria, * 3:Belgium, 4:Belize, 5:Bolivia, 6:Brazil, 7:Canada, 8:Chile, 9:Colombia, 10:Costa Rica, * 11:Czech Republic, 12:Denmark, 13:Dominican Republic, 14:Ecuador, 15:El Salvador, * 16:France, 17:Germany, 18:Guatemala, 19:Honduras, 20:Hong Kong SAR, 21:Ireland, * 22:Italy, 23:Jamaica, 24:Korea, 25:Liechtenstein, 26:Luxembourg, 27:Mexico, 28:Netherlands, * 29:New Zealand, 30:Nicaragua, 31:Panama, 32:Paraguay, 33:Peru, 34:Portugal, * 35:Peoples Republic of China, 36:Puerto Rico, 37:Russia, 38:Singapore, 39:South Africa, * 40:Spain, 41:Sweden, 42:Switzerland, 43:Taiwan, 44:Trinidad, 45:United Kingdom, * 46:United States, 47:Uruguay, 48:Venezuela. * * **collections** (bool): Use collection info from The Movie Database. Default value false. * * **localart** (bool): Prefer artwork based on library language. Default value true. * * **adult** (bool): Include adult content. Default value false. * * **usage** (bool): Send anonymous usage data to Plex. Default value true. * * **TheMovieDB Movie Options** (com.plexapp.agents.themoviedb) * * * **collections** (bool): Use collection info from The Movie Database. Default value false. * * **localart** (bool): Prefer artwork based on library language. Default value true. * * **adult** (bool): Include adult content. Default value false. * * **country** (int): Country (used for release date and content rating). Default value 47 Possible * options 0:, 1:Argentina, 2:Australia, 3:Austria, 4:Belgium, 5:Belize, 6:Bolivia, 7:Brazil, 8:Canada, * 9:Chile, 10:Colombia, 11:Costa Rica, 12:Czech Republic, 13:Denmark, 14:Dominican Republic, 15:Ecuador, * 16:El Salvador, 17:France, 18:Germany, 19:Guatemala, 20:Honduras, 21:Hong Kong SAR, 22:Ireland, * 23:Italy, 24:Jamaica, 25:Korea, 26:Liechtenstein, 27:Luxembourg, 28:Mexico, 29:Netherlands, * 30:New Zealand, 31:Nicaragua, 32:Panama, 33:Paraguay, 34:Peru, 35:Portugal, * 36:Peoples Republic of China, 37:Puerto Rico, 38:Russia, 39:Singapore, 40:South Africa, 41:Spain, * 42:Sweden, 43:Switzerland, 44:Taiwan, 45:Trinidad, 46:United Kingdom, 47:United States, 48:Uruguay, * 49:Venezuela. * * **Show Preferences** * * * **agent** (str): com.plexapp.agents.none, com.plexapp.agents.thetvdb, com.plexapp.agents.themoviedb * * **enableBIFGeneration** (bool): Enable video preview thumbnails. Default value true. * * **episodeSort** (int): Episode order. Default -1 Possible options: 0:Oldest first, 1:Newest first. * * **flattenSeasons** (int): Seasons. Default value 0 Possible options: 0:Show,1:Hide. * * **includeInGlobal** (bool): Include in dashboard. Default value true. * * **scanner** (str): Plex Series Scanner * * **TheTVDB Show Options** (com.plexapp.agents.thetvdb) * * * **extras** (bool): Find trailers and extras automatically (Plex Pass required). Default value true. * * **native_subs** (bool): Include extras with subtitles in Library language. Default value false. * * **TheMovieDB Show Options** (com.plexapp.agents.themoviedb) * * * **collections** (bool): Use collection info from The Movie Database. Default value false. * * **localart** (bool): Prefer artwork based on library language. Default value true. * * **adult** (bool): Include adult content. Default value false. * * **country** (int): Country (used for release date and content rating). Default value 47 options * 0:, 1:Argentina, 2:Australia, 3:Austria, 4:Belgium, 5:Belize, 6:Bolivia, 7:Brazil, 8:Canada, 9:Chile, * 10:Colombia, 11:Costa Rica, 12:Czech Republic, 13:Denmark, 14:Dominican Republic, 15:Ecuador, * 16:El Salvador, 17:France, 18:Germany, 19:Guatemala, 20:Honduras, 21:Hong Kong SAR, 22:Ireland, * 23:Italy, 24:Jamaica, 25:Korea, 26:Liechtenstein, 27:Luxembourg, 28:Mexico, 29:Netherlands, * 30:New Zealand, 31:Nicaragua, 32:Panama, 33:Paraguay, 34:Peru, 35:Portugal, * 36:Peoples Republic of China, 37:Puerto Rico, 38:Russia, 39:Singapore, 40:South Africa, * 41:Spain, 42:Sweden, 43:Switzerland, 44:Taiwan, 45:Trinidad, 46:United Kingdom, 47:United States, * 48:Uruguay, 49:Venezuela. * * **Other Video Preferences** * * * **agent** (str): com.plexapp.agents.none, com.plexapp.agents.imdb, com.plexapp.agents.themoviedb * * **enableBIFGeneration** (bool): Enable video preview thumbnails. Default value true. * * **enableCinemaTrailers** (bool): Enable Cinema Trailers. Default value true. * * **includeInGlobal** (bool): Include in dashboard. Default value true. * * **scanner** (str): Plex Movie Scanner, Plex Video Files Scanner * * **IMDB Other Video Options** (com.plexapp.agents.imdb) * * * **title** (bool): Localized titles. Default value false. * * **extras** (bool): Find trailers and extras automatically (Plex Pass required). Default value true. * * **only_trailers** (bool): Skip extras which aren't trailers. Default value false. * * **redband** (bool): Use red band (restricted audiences) trailers when available. Default value false. * * **native_subs** (bool): Include extras with subtitles in Library language. Default value false. * * **cast_list** (int): Cast List Source: Default value 1 Possible options: 0:IMDb,1:The Movie Database. * * **ratings** (int): Ratings Source Default value 0 Possible options: * 0:Rotten Tomatoes,1:IMDb,2:The Movie Database. * * **summary** (int): Plot Summary Source: Default value 1 Possible options: 0:IMDb,1:The Movie Database. * * **country** (int): Country: Default value 46 Possible options: 0:Argentina, 1:Australia, 2:Austria, * 3:Belgium, 4:Belize, 5:Bolivia, 6:Brazil, 7:Canada, 8:Chile, 9:Colombia, 10:Costa Rica, * 11:Czech Republic, 12:Denmark, 13:Dominican Republic, 14:Ecuador, 15:El Salvador, 16:France, * 17:Germany, 18:Guatemala, 19:Honduras, 20:Hong Kong SAR, 21:Ireland, 22:Italy, 23:Jamaica, * 24:Korea, 25:Liechtenstein, 26:Luxembourg, 27:Mexico, 28:Netherlands, 29:New Zealand, 30:Nicaragua, * 31:Panama, 32:Paraguay, 33:Peru, 34:Portugal, 35:Peoples Republic of China, 36:Puerto Rico, * 37:Russia, 38:Singapore, 39:South Africa, 40:Spain, 41:Sweden, 42:Switzerland, 43:Taiwan, 44:Trinidad, * 45:United Kingdom, 46:United States, 47:Uruguay, 48:Venezuela. * * **collections** (bool): Use collection info from The Movie Database. Default value false. * * **localart** (bool): Prefer artwork based on library language. Default value true. * * **adult** (bool): Include adult content. Default value false. * * **usage** (bool): Send anonymous usage data to Plex. Default value true. * * **TheMovieDB Other Video Options** (com.plexapp.agents.themoviedb) * * * **collections** (bool): Use collection info from The Movie Database. Default value false. * * **localart** (bool): Prefer artwork based on library language. Default value true. * * **adult** (bool): Include adult content. Default value false. * * **country** (int): Country (used for release date and content rating). Default * value 47 Possible options 0:, 1:Argentina, 2:Australia, 3:Austria, 4:Belgium, 5:Belize, * 6:Bolivia, 7:Brazil, 8:Canada, 9:Chile, 10:Colombia, 11:Costa Rica, 12:Czech Republic, * 13:Denmark, 14:Dominican Republic, 15:Ecuador, 16:El Salvador, 17:France, 18:Germany, * 19:Guatemala, 20:Honduras, 21:Hong Kong SAR, 22:Ireland, 23:Italy, 24:Jamaica, * 25:Korea, 26:Liechtenstein, 27:Luxembourg, 28:Mexico, 29:Netherlands, 30:New Zealand, * 31:Nicaragua, 32:Panama, 33:Paraguay, 34:Peru, 35:Portugal, * 36:Peoples Republic of China, 37:Puerto Rico, 38:Russia, 39:Singapore, * 40:South Africa, 41:Spain, 42:Sweden, 43:Switzerland, 44:Taiwan, 45:Trinidad, * 46:United Kingdom, 47:United States, 48:Uruguay, 49:Venezuela. */ add(options: LibraryAddOptions): Promise>; /** * Returns hubs across all library sections. */ hubs({ sectionID, identifier, ...options }?: LibraryHubsOptions): Promise; /** * Returns a list of all on-deck items from all library sections. * On-deck items are media that is currently in progress. */ onDeck(): Promise; /** * Returns media from every library section. * * Use the options object for sorting, paging, and type-specific results. When * `libtype` is provided, each section is asked for that Plex item type and the * returned array is typed to the matching model. * * @example * ```ts * const everything = await library.all() * const movies = await library.all({ libtype: 'movie', sort: 'titleSort', maxResults: 25 }) * ``` */ all(options: LibrarySectionAllOptions & { libtype: T; }): Promise>>; all(): Promise; all(options: LibrarySectionAllOptions): Promise; /** * Returns recently added media from all library sections. */ recentlyAdded(): Promise; /** * Search across all library sections. Section search is more powerful and validates filters. */ search(options: LibrarySearchOptions & { libtype: T; }): Promise>>; search(options?: LibrarySearchOptions): Promise; /** * Clean old metadata bundles from the server. */ cleanBundles(): Promise; /** * If a library has items in the Library Trash, use this option to empty the Trash. */ emptyTrash(): Promise; /** * The Optimize option cleans up the server database from unused or fragmented data. * For example, if you have deleted or added an entire library or many items in a * library, you may like to optimize the database. */ optimize(): Promise; /** * Scan every library section for new media. */ update(): Promise; /** * Cancel an active full-library scan. */ cancelUpdate(): Promise; /** * Force refresh metadata for every library section. */ refresh(): Promise; /** * Delete preview thumbnails for all library sections. */ deleteMediaPreviews(): Promise; /** * Get watched history for all library sections for the owner. */ history(options?: LibraryHistoryOptions): Promise; /** * Returns global library tags for the requested Plex tag type. * * Prefer named tag types like `'genre'`, `'director'`, or `'label'` so the * result is typed to the corresponding tag class. Numeric Plex tag type ids are * accepted for less common tags and return generic {@link LibraryMediaTag} * objects. * * @example * ```ts * const genres = await library.tags('genre') // Genre[] * const custom = await library.tags(400) // LibraryMediaTag[] * ``` */ tags(tag: T): Promise>>; tags(tag: LibraryTagType): Promise; /** * Validates a filter field and values are available as a custom filter for the library. * Returns the validated field and values as a URL encoded parameter string. */ /** * Returns the validated and formatted search query API key * (``/library/sections//all?``). */ protected _loadData(data: LibraryRootResponse): void; } export type Libtype = keyof typeof SEARCHTYPES; /** * Generic library tag returned when Plex exposes a tag type that does not have a * dedicated media tag class in this package. * * Prefer {@link Library.tags} with a named tag type such as `'genre'` or * `'director'` when one is available. Numeric tag types use this fallback shape. */ export declare class LibraryMediaTag extends PlexObject implements LibraryTagItems { static TAG: string; FILTER: string; count?: number; filter?: string; id?: number | string; librarySectionID?: number; librarySectionKey?: string; librarySectionTitle?: string; librarySectionType?: number; reason?: string; reasonID?: number; reasonTitle?: string; score?: number; type?: string; tag: string; tagKey?: string; tagType?: number; tagValue?: number; thumb?: string; items(): Promise; protected _loadData(data: LibraryTagData): void; } export interface SearchArgs { [key: string]: SearchArgValue; /** General string query to search for. Partial string matches are allowed. */ title: string | string[]; /** A string of comma separated sort fields or a list of sort fields in the format ``column:dir``. */ sort: string | string[] | FilteringSort | FilteringSort[]; /** Only return the specified number of results. */ maxresults: number; /** Default 0 */ container_start: number; /** Default 100 (X_PLEX_CONTAINER_SIZE) */ container_size: number; /** Limit the number of results from the filter. */ limit: number; /** * Return results of a specific type (movie, show, season, episode, * artist, album, track, photoalbum, photo, collection) (e.g. ``libtype='movie'`` will only * return {@link Movie} objects) */ libtype: Libtype; /** * Return only results that have duplicates. */ duplicate: number; /** Include GUID data in metadata responses. Defaults to true. */ includeGuids: boolean; /** Advanced filters object used by music searches. */ filters?: AdvancedSearchFilters; } export interface HubSearchOptions { /** Optionally limit search results to a media type. */ mediatype?: keyof typeof SEARCHTYPES; /** Limit the number of results per hub. */ limit?: number; } export interface PlaylistSearchOptions { sort?: string; [filter: string]: ItemFilterValue | undefined; } export interface ManagedHubVisibilityOptions { /** Show or hide this hub on the library Recommended tab. */ recommended?: boolean; /** Show or hide this hub on the owner's Home page. */ home?: boolean; /** Show or hide this hub on shared users' Home pages. */ shared?: boolean; } type RequireAtLeastOne = { [K in keyof T]-?: Required> & Partial>; }[keyof T]; export type ManagedHubVisibilityChanges = RequireAtLeastOne; export type SectionAdvancedSettings = Record; export type LibrarySectionHistoryOptions = Omit; /** * Values accepted by {@link LibrarySection.edit}. * * Use this for section-level edits where Plex expects the full replacement list * of locations. For simple path changes, prefer {@link LibrarySection.addLocations} * and {@link LibrarySection.removeLocations}; they preserve the current paths for * you. */ export interface LibrarySectionEditOptions { /** Library agent identifier. Defaults to the section's current agent. */ agent?: string; /** Full replacement list of folder paths for this library section. */ locations?: string | readonly string[]; /** Additional section edit parameters or Plex preference keys. Boolean values are sent as `1` or `0`. */ preferences?: Record; } export interface LibrarySectionUpdateOptions { /** Full folder path to scan within this section. */ path?: string; } export type LibrarySectionGetOptions = Omit, 'libtype' | 'limit' | 'maxresults' | 'title'> & { /** Return a specific Plex item type instead of the section default. */ libtype?: Libtype; /** Exact item title to return. */ title: string; }; export type LibrarySectionAllOptions = Omit, 'libtype' | 'maxresults'> & { /** * Return a specific library item type instead of the section default. * * Passing this narrows `section.all({ libtype })` to the matching model type. */ libtype?: Libtype; /** * Maximum number of items to return. * * Plex may ignore the container size hint on some endpoints, so this method also * applies the limit locally before returning. */ maxResults?: number; }; export type SectionType = Movie | Show | Artist | Album | Track | Photoalbum; export type LibrarySearchItem = SectionType | Season | Episode | Clip | Photo | Collections; export type HubItem = LibrarySearchItem | Playlist; type RatingKeyItem = { ratingKey?: number | string; }; type SearchTagValue = { id: number | string; tag?: string; } | { id?: number | string; tag: string; }; export type SearchFilterPrimitive = boolean | Date | FilterChoice | number | SearchTagValue | string; export type SearchFilterValue = SearchFilterPrimitive | SearchFilterPrimitive[]; export type SearchArgValue = AdvancedSearchFilters | FilteringSort | FilteringSort[] | SearchFilterValue | undefined; export type AdvancedSearchFilters = { [field: string]: AdvancedSearchFilters[] | SearchFilterValue; and?: AdvancedSearchFilters[]; or?: AdvancedSearchFilters[]; }; type LibraryItemParent = { key?: number | string; librarySectionID?: number | string; parent?: WeakRef; }; export type EditableLibraryItem = LibrarySearchItem & { librarySectionID?: number | string; parent?: WeakRef; ratingKey?: number | string; title?: string; type?: string; }; export type SearchClassForLibtype = T extends 'movie' ? Movie : T extends 'show' ? Show : T extends 'season' ? Season : T extends 'episode' ? Episode : T extends 'artist' ? Artist : T extends 'album' ? Album : T extends 'track' ? Track : T extends 'photoalbum' ? Photoalbum : T extends 'photo' ? Photo : T extends 'clip' ? Clip : SectionType; /** * Base class for a single library section. */ export declare abstract class LibrarySection extends PlexObject { static ALLOWED_FILTERS: string[]; static ALLOWED_SORT: string[]; static BOOLEAN_FILTERS: string[]; /** Unknown (com.plexapp.agents.imdb, etc) */ agent: string; /** l True if you allow syncing content from this section. */ allowSync: boolean; /** Wallpaper artwork used to respresent this section. */ art: string; /** Composit image used to represent this section. */ composite: string; /** Unknown */ filters: boolean; /** Language represented in this section (en, xn, etc). */ language: string; /** Paths on disk where section content is stored. */ locations: Location[]; /** True if this section is currently being refreshed. */ refreshing: boolean; /** Internal scanner used to find media (Plex Movie Scanner, Plex Premium Music Scanner, etc.) */ scanner: string; /** Thumbnail image used to represent this section. */ thumb: string; /** Title of this section. */ title: string; /** Type of content section represents (movie, artist, photo, show). */ type: Libtype; /** Datetime this library section was last updated. */ updatedAt: Date; /** Datetime this library section was created. */ createdAt: Date; scannedAt: Date; /** Unique id for this section (32258d7c-3e6c-4ac5-98ad-bad7a3b78c63) */ uuid: string; CONTENT_TYPE: string; readonly SECTION_TYPE: Class; _filterTypes?: FilteringType[]; _fieldTypes?: FilteringFieldType[]; private _durationStorageCache?; /** * Returns the total number of items in the library. * Queries the library without fetching any items to get the total count. * * @param options.libtype Filter by a specific library type (movie, show, episode, etc.). * @param options.includeCollections Whether to include collections in the count. Default true. */ totalViewSize(options?: { libtype?: string; includeCollections?: boolean; }): Promise; /** * Returns the total number of items in the library, excluding collections. */ totalSize(): Promise; /** * Returns the total duration of all items in the library in milliseconds, or null if unavailable. */ totalDuration(): Promise; /** * Returns the total storage size of all items in the library in bytes, or null if unavailable. */ totalStorage(): Promise; /** * Add new file paths to the library section. * @param locations One or more file paths to add. */ addLocations(locations: string | string[]): Promise
; /** * Remove file paths from the library section. * @param locations One or more file paths to remove. */ removeLocations(locations: string | string[]): Promise
; /** * Returns all items from this library section. * * Use an options object for sorting, filters, paging, and type-specific results. * When `libtype` is omitted, the section default model is returned. When `libtype` * is provided, the returned array is typed to that Plex item type. * * @example * ```ts * const movies = await movieSection.all() * const sorted = await movieSection.all({ sort: 'titleSort', maxResults: 25 }) * const episodes = await showSection.all({ libtype: 'episode', sort: 'episode.originallyAvailableAt' }) * ``` */ all(options: LibrarySectionAllOptions & { libtype: T; }): Promise>>; all(): Promise; all(options: LibrarySectionAllOptions): Promise; agents(): Promise; /** * Returns the advanced preference settings for this library section. */ settings(): Promise; /** * Returns one item by exact title, optionally narrowed with normal search filters. * * Use filters to disambiguate duplicate titles. When `libtype` is provided, * the returned item is typed to that Plex model. * * @example * ```ts * const movie = await movieSection.get({ title: 'Big Buck Bunny', year: 2008 }) * const episode = await showSection.get({ title: 'Minimum Viable Product', libtype: 'episode' }) * ``` */ get(options: LibrarySectionGetOptions & { libtype: T; }): Promise>; get(options: LibrarySectionGetOptions): Promise; /** * Returns the media item with the specified external IMDB, TMDB, or TVDB ID. * Note: This search uses a PlexAPI operator so performance may be slow. All items from the * entire Plex library need to be retrieved for each guid search. It is recommended to create * your own lookup dictionary if you are searching for a lot of external guids. * * @param guid The external guid of the item to return. * Examples: IMDB ``imdb://tt0944947``, TMDB ``tmdb://1399``, TVDB ``tvdb://121361``. * * * Example: * * .. code-block:: python * * # This will retrieve all items in the entire library 3 times * result1 = library.getGuid('imdb://tt0944947') * result2 = library.getGuid('tmdb://1399') * result3 = library.getGuid('tvdb://121361') * * # This will only retrieve all items in the library once to create a lookup dictionary * guidLookup = {guid.id: item for item in library.all() for guid in item.guids} * result1 = guidLookup['imdb://tt0944947'] * result2 = guidLookup['tmdb://1399'] * result3 = guidLookup['tvdb://121361'] */ getGuid(guid: string): Promise; /** * Returns the Plex Web URL for the library. * * @param base The base URL before the fragment (``#!``). * Default is https://app.plex.tv/desktop. * @param tab The library tab (recommended, library, collections, playlists, timeline). * @param key A hub key. */ getWebURL({ base, tab, key, }?: { /** The base URL before the fragment (``#!``). Default is https://app.plex.tv/desktop. */ base?: string; /** The library tab (recommended, library, collections, playlists, timeline). */ tab?: string; /** A hub key. */ key?: string; }): string; /** * Search the library. The http requests will be batched in container_size. If you are only looking for the * first results, it would be wise to set the maxresults option to that amount so the search doesn't iterate * over all results on the server. * * Example: "studio=Comedy%20Central" or "year=1999" "title=Kung Fu" all work. Other items * such as actor= seem to work, but require you already know the id of the actor. * TLDR: This is untested but seems to work. Use library section search when you can. * @param args Search using a number of different attributes */ search(args?: Partial, Cls?: Class): Promise; /** * Run an analysis on all of the items in this library section. * See :func:`~plexapi.base.PlexPartialObject.analyze` for more details. */ analyze(): Promise; /** * If a section has items in the Trash, use this option to empty the Trash */ emptyTrash(): Promise; /** * Scan this section for new media. */ update({ path }?: LibrarySectionUpdateOptions): Promise; /** * Cancel update of this Library Section. */ cancelUpdate(): Promise; /** * Forces a download of fresh media information from the internet. * This can take a long time. Any locked fields are not modified. */ refresh(): Promise; /** * Delete the preview thumbnails for items in this library. This cannot * be undone. Recreating media preview files can take hours or even days. */ deleteMediaPreviews(): Promise; /** Delete a library section. */ delete(): Promise; /** * Edit this library section's agent, locations, or raw Plex preferences. * * `locations` replaces the section's complete path list. To add or remove one * path while preserving the rest, use {@link addLocations} or * {@link removeLocations}. * * @example * ```ts * await movieSection.edit({ * agent: 'com.plexapp.agents.imdb', * locations: ['/media/movies', '/media/archived-movies'], * preferences: { includeInGlobal: true }, * }) * ``` */ edit({ agent, locations, preferences, }?: LibrarySectionEditOptions): Promise
; /** * Edit this library section's advanced preference settings. */ editAdvanced(changes: SectionAdvancedSettings): Promise
; /** * Reset this library section's advanced preference settings to their defaults. */ defaultAdvanced(): Promise
; /** * Get watched history for this library section. */ history({ accountId, ...options }?: LibrarySectionHistoryOptions): Promise; /** * Returns the managed recommendation hubs for this library section. */ managedHubs(): Promise; /** * Reset managed hub customizations for this library section. */ resetManagedHubs(): Promise; hubs(): Promise; /** * Returns section-scoped hub search results. */ hubSearch(query: string, { mediatype, limit }?: HubSearchOptions): Promise; /** * Returns the current library section timeline status. */ timeline(): Promise; /** * Returns a list of playlists from this library section. */ playlists(args?: PlaylistSearchOptions): Promise; /** * Create a regular or smart playlist scoped to this library section. */ createPlaylist(title: string, options: CreateRegularPlaylistOptions | Omit): Promise; /** * Returns the playlist with the exact title. */ playlist(title: string): Promise; collections(args?: Record): Promise>>; /** * Create a regular collection in this library section. */ createCollection(title: string, items: T[]): Promise>; /** * Returns the collection with the exact title. */ collection(title: string): Promise>; /** * Returns a list of available Folders for this library section. */ folders(): Promise; genres(): Promise; /** * Returns a list of items currently on deck (in progress) for this library section. */ onDeck(): Promise; /** * Returns items from this library section's Continue Watching hub. */ continueWatching(): Promise; /** * Returns a list of recently added items for this library section. * * @param maxResults Maximum number of results to return. Default 50. */ recentlyAdded(maxResults?: number): Promise; recentlyAdded(maxResults: number | undefined, libtype: T): Promise>>; /** * Returns the list of first characters for items in this library section. * This is the data used to populate the alphabet bar in the Plex UI. */ firstCharacter(): Promise; /** * Returns a list of available {@link FilteringField} for a specified libtype. * This is the list of options in the custom filter dropdown menu */ listFields(libtype?: Libtype): Promise; getFilterType(libtype?: Libtype): Promise; /** * @param fieldType The data type for the field (tag, integer, string, boolean, date, subtitleLanguage, audioLanguage, resolution). */ getFieldType(fieldType: string): Promise; /** * @param libtype The library type to filter (movie, show, season, episode, * artist, album, track, photoalbum, photo, collection). * * @example * ```ts * const availableFilters = (await library.listFilters()).map(f => f.filter) * ``` */ listFilters(libtype?: Libtype): Promise; /** * Returns a list of available sorting fields for the specified libtype. */ listSorts(libtype?: Libtype): Promise; /** * Returns the available values for a custom filter field. */ listFilterChoices(field: string | FilteringFilter, libtype?: Libtype): Promise; /** * @param fieldType The data type for the field (tag, integer, string, boolean, date, * subtitleLanguage, audioLanguage, resolution). */ listOperators(fieldType: string): Promise; filterTypes(): Promise; fieldTypes(): Promise; /** * Returns fields common to all provided items. */ common(items: EditableLibraryItem | EditableLibraryItem[]): Promise; /** * Edit multiple items at once using Plex field keys. */ multiEdit(items: EditableLibraryItem | EditableLibraryItem[], changes: Record): Promise; /** * Lock a field for all items of a libtype in this library. */ lockAllField(field: string, libtype?: Libtype): Promise; /** * Unlock a field for all items of a libtype in this library. */ unlockAllField(field: string, libtype?: Libtype): Promise; private _fetchDurationStorage; private _validateItems; private _itemBelongsToThisSection; private _lockUnlockAllField; protected _loadData(data: SectionsDirectory): void; private _loadFilters; /** * Validates a filter field and value against the section filter metadata. */ private _validateFilterField; private _getFilterField; private _isStaticBooleanFilter; /** * Validates a filter operator against the field type metadata. */ private _validateFieldOperator; /** * Validates filter values are the correct data type and available where the server exposes choices. */ private _validateFieldValue; private _validateFieldValueDate; private _validateFieldValueTag; private _validateSortFields; private _validateSortField; private _validateAdvancedSearch; private _buildSearchKey; } export declare class MovieSection extends LibrarySection { static TYPE: string; static ALLOWED_FILTERS: string[]; static ALLOWED_SORT: string[]; static TAG: string; METADATA_TYPE: string; CONTENT_TYPE: string; readonly SECTION_TYPE: typeof Movie; /** Search for a movie. */ searchMovies(args?: Partial): Promise; /** Returns recently added movies from this library section. */ recentlyAddedMovies(maxResults?: number): Promise; } export declare class ShowSection extends LibrarySection { static TYPE: string; static ALLOWED_FILTERS: string[]; static ALLOWED_SORT: string[]; static TAG: string; METADATA_TYPE: string; CONTENT_TYPE: string; readonly SECTION_TYPE: typeof Show; /** Search for a show. */ searchShows(args?: Partial): Promise; /** Search for a season. */ searchSeasons(args?: Partial): Promise; /** Search for an episode. */ searchEpisodes(args?: Partial): Promise; /** Returns recently added shows from this library section. */ recentlyAddedShows(maxResults?: number): Promise; /** Returns recently added seasons from this library section. */ recentlyAddedSeasons(maxResults?: number): Promise; /** Returns recently added episodes from this library section. */ recentlyAddedEpisodes(maxResults?: number): Promise; /** * Returns a list of recently added shows from this library section. * * @param maxResults Maximum number of results to return. Default 50. */ recentlyAdded(maxResults?: number): Promise; } export declare class MusicSection extends LibrarySection { static TYPE: string; static TAG: string; METADATA_TYPE: string; CONTENT_TYPE: string; readonly SECTION_TYPE: typeof Track; /** Returns a list of Album objects in this section. */ albums(): Promise; /** * Returns the music stations Hub for this section, if available. * TODO: Investigate how to return actual station items (Playlists?) from the Hub. */ stations(): Promise; /** Search for an artist. */ searchArtists(args?: Partial): Promise; /** Search for an album. */ searchAlbums(args?: Partial): Promise; /** Search for a track. */ searchTracks(args?: Partial): Promise; /** Returns a list of recently added artists from this library section. */ recentlyAddedArtists({ maxResults }?: { maxResults?: number; }): Promise; /** Returns a list of recently added albums from this library section. */ recentlyAddedAlbums({ maxResults }?: { maxResults?: number; }): Promise; /** Returns a list of recently added tracks from this library section. */ recentlyAddedTracks({ maxResults }?: { maxResults?: number; }): Promise; /** * Returns a list of tracks from this library section that are part of a sonic adventure. * IDs should be of a track; other IDs will return an empty list or an error. * @param start The Track or ID of the first track in the sonic adventure. * @param end The Track or ID of the last track in the sonic adventure. * @returns A list of tracks that are part of a sonic adventure. */ sonicAdventure(start: Track | number, end: Track | number): Promise; } export declare class PhotoSection extends LibrarySection { static TYPE: string; static ALLOWED_FILTERS: string[]; static ALLOWED_SORT: string[]; static TAG: string; METADATA_TYPE: string; CONTENT_TYPE: string; readonly SECTION_TYPE: typeof Photoalbum; /** * Returns photo library items. * * Photo sections default to albums to match Plex's photo library behavior. Pass * `libtype: 'photo'` to return individual photos instead. * * @example * ```ts * const albums = await photoSection.all() * const photos = await photoSection.all({ libtype: 'photo', maxResults: 50 }) * ``` */ all(options: LibrarySectionAllOptions & { libtype: T; }): Promise>>; all(): Promise; all(options: LibrarySectionAllOptions): Promise; /** Photo libraries do not support collections. */ collections(): Promise>>; /** Search for a photo album. */ searchAlbums(args?: Partial): Promise; /** Search for a photo. */ searchPhotos(args?: Partial): Promise; /** Returns recently added photo albums from this library section. */ recentlyAddedAlbums(maxResults?: number): Promise; /** Returns recently added photos from this library section. */ recentlyAddedPhotos(maxResults?: number): Promise; /** Returns recently added photo albums from this library section. */ recentlyAdded(maxResults?: number): Promise; } export declare class LibraryTimeline extends PlexObject { static TAG: string; size?: number; allowSync: boolean; art?: string; content?: string; identifier?: string; latestEntryTime?: number; mediaTagPrefix?: string; mediaTagVersion?: number; thumb?: string; title1?: string; updateQueueSize?: number; viewGroup?: string; viewMode?: number; protected _loadData(data: LibraryTimelineData): void; } export declare class ManagedHub extends PlexObject { static TAG: string; deletable: boolean; homeVisibility: string; identifier: string; librarySectionID: string; promotedToOwnHome: boolean; promotedToRecommended: boolean; promotedToSharedHome: boolean; recommendationsVisibility: string; title: string; reload(): Promise; move(after?: ManagedHub): Promise; remove(): Promise; /** * Update where this managed hub is visible. * Omitted flags preserve the hub's current visibility state. */ updateVisibility(changes: ManagedHubVisibilityChanges): Promise; promoteRecommended(): Promise; demoteRecommended(): Promise; promoteHome(): Promise; demoteHome(): Promise; promoteShared(): Promise; demoteShared(): Promise; protected _loadData(data: ManagedHubData): void; } /** Represents a single Hub (or category) in the PlexServer search */ export declare class Hub extends PlexObject { static TAG: string; context?: string; hubKey?: string; hubIdentifier: string; librarySectionID?: string; /** True if Plex has more items available at this hub's key. */ more: boolean; /** Number of items found. */ size: number; style?: string; title: string; type: string; /** True if the hub items are randomized. */ random: boolean; Directory: SearchResultContainer['Directory']; Metadata: SearchResultContainer['Metadata']; private _metadata?; private _items?; /** * Return items from this hub. * * Plex often includes a partial `Metadata` list with the hub response. When * `more` is true, this fetches the hub key first so callers get the full item * list instead of only the preview items. */ items(): Promise; items(Cls: Class): Promise; section(): Promise
; protected _loadData(data: SearchResultContainer): void; } /** * Represents a Folder inside a library. */ export declare class Folder extends PlexObject { static TAG: string; title: string; /** * Returns a list of available Folders for this folder. * Continue down subfolders until a mediaType is found. */ subfolders(): Promise; /** * Returns all nested folders below this folder, excluding media item leaves. */ allSubfolders(): Promise; protected _loadData(data: FolderData): void; } export declare class Collections extends PartialPlexObject { static TAG: string; TYPE: string; guid: string; smart: boolean; content: string; collectionMode: number; collectionSort: number; titleSort: string; librarySectionTitle: string; librarySectionKey: string; contentRating: string; subtype: string; summary: string; index: number; rating: number; userRating: number; thumb: string; addedAt: number; updatedAt: number; childCount: number; maxYear: string; minYear: string; art?: string; VIDEO_TYPE: Class; get size(): number; /** * Returns a list of all items in the collection. */ items(): Promise; /** * Add items to the collection. * @param items Items to add to the collection. */ addItems(items: CollectionVideoType[]): Promise; /** * Remove items from the collection. * @param items Items to remove from the collection. */ removeItems(items: CollectionVideoType[]): Promise; /** * Move an item to a new position in the collection. * @param item Item to move. * @param after Item to place it after. If not provided, moves to the beginning. */ moveItem(item: CollectionVideoType, after?: CollectionVideoType): Promise; /** * Update the collection display mode. * @param mode Display mode: 'default' (-1), 'hide' (0), 'hideItems' (1), 'showItems' (2). */ modeUpdate(mode: 'default' | 'hide' | 'hideItems' | 'showItems'): Promise; /** * Update the collection sort order. * @param sort Sort order: 'release' (0), 'alpha' (1), 'custom' (2). */ sortUpdate(sort: 'release' | 'alpha' | 'custom'): Promise; /** * Create a new regular (non-smart) collection. * @param server The PlexServer instance. * @param title Title of the new collection. * @param section The library section to create the collection in. * @param items Items to add to the collection. */ static create(server: PlexServer, title: string, section: LibrarySection, items: T[]): Promise>; protected _loadFullData(data: CollectionData): void; protected _loadData(data: CollectionData): void; } export declare class Common extends PlexObject { static TAG: string; collections: Collection[]; contentRating?: string; countries: Country[]; directors: Director[]; editionTitle?: string; fields: Field[]; genres: Genre[]; grandparentRatingKey?: number; grandparentTitle?: string; guid?: string; guids: Guid[]; index?: number; labels: Label[]; mixedFields: string[]; moods: Mood[]; originallyAvailableAt?: Date; parentRatingKey?: number; parentTitle?: string; producers: Producer[]; ratingKey?: number; ratings: Rating[]; roles: Role[]; studio?: string; styles: Style[]; summary?: string; tags: Tag[]; tagline?: string; title?: string; titleSort?: string; type?: string; writers: Writer[]; year?: number; get commonType(): Libtype | undefined; get ratingKeys(): number[]; items(): Promise; protected _loadData(data: CommonData): void; } export declare class FilterChoice extends PlexObject { static TAG: string; /** * API URL path to quickly list all items with this filter choice. * (/library/sections/
/all?genre=) */ fastKey?: string; /** Thumbnail URL for the filter choice. */ thumb?: string; /** The title of the filter choice. */ title: string; /** The filter type (genre, contentRating, etc). */ type: string; items(): Promise; protected _loadData(data: FilterChoiceData): void; } /** * Represents a single first character entry for a library section. * Used to populate the alphabet bar in the Plex UI. */ export declare class FirstCharacter extends PlexObject { static TAG: string; /** The title of the character (e.g. 'A', 'B', '#'). */ title: string; /** The number of items starting with this character. */ size: number; protected _loadData(data: FirstCharacterData): void; } export declare class FilteringType extends PlexObject { static TAG: string; /** The libtype for the filter. */ type: string; /** True if this filter type is currently active. */ active: boolean; fields: FilteringField[]; filters: FilteringFilter[]; /** List of sort objects. */ sorts: FilteringSort[]; /** The title for the libtype filter. */ title: string; _loadData(data: FilteringTypeData): void; } /** * Represents a single Filter object for a {@link FilteringType} */ export declare class FilteringFilter extends PlexObject { static TAG: string; /** The key for the filter. */ filter: string; /** The :class:`~plexapi.library.FilteringFieldType` type (string, boolean, integer, date, etc). */ filterType: string; /** The title of the filter. */ title: string; /** 'filter' */ type: string; _loadData(data: FilteringFilterData): void; } /** * Represents a single Sort object for a {@link FilteringType} */ export declare class FilteringSort extends PlexObject { static TAG: string; /** True if the sort is currently active. */ active: boolean; /** The currently active sorting direction. */ activeDirection?: string; /** The currently active default sorting direction. */ default?: string; /** The default sorting direction. */ defaultDirection?: string; /** The URL key for sorting with desc. */ descKey?: string; /** API URL path for first character endpoint. */ firstCharacterKey?: string; /** The title of the sorting. */ title: string; _loadData(data: FilteringSortData): void; } /** * Represents a single Field object for a {@link FilteringType} */ export declare class FilteringField extends PlexObject { static TAG: string; type: string; title: string; /** The subtype of the filter (decade, rating, etc) */ subType?: string; _loadData(data: FilteringFieldData): void; } /** * Represents a single FieldType for library filtering. */ export declare class FilteringFieldType extends PlexObject { static TAG: string; /** The filtering data type (string, boolean, integer, date, etc). */ type: string; operators: FilteringOperator[]; _loadData(data: FilteringFieldTypeData): void; } /** * Represents a single FilterChoice for library filtering. */ export declare class FilteringOperator extends PlexObject { static TAG: string; /** The title of the operator. */ title: string; _loadData(data: FilteringOperatorData): void; } export {};