(Library)
API Calls interacting with Plex Media Server Libraries
- GetFileHash - Get Hash Value
- GetRecentlyAdded - Get Recently Added
- GetLibraries - Get All Libraries
- GetLibrary - Get Library Details
- DeleteLibrary - Delete Library Section
- RefreshLibrary - Refresh Library
- SearchLibrary - Search Library
- GetMetadata - Get Items Metadata
- GetMetadataChildren - Get Items Children
- GetOnDeck - Get On Deck
This resource returns hash values for local files
package main
import(
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo"
"context"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithXPlexClientIdentifier("Postman"),
)
var url_ string = "file://C:\Image.png&type=13"
var type_ *float64 = plexgo.Float64(4462.17)
ctx := context.Background()
res, err := s.Library.GetFileHash(ctx, url_, type_)
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
url_ |
string | ✔️ | This is the path to the local file, must be prefixed by file:// |
file://C:\Image.png&type=13 |
type_ |
*float64 | ➖ | Item type |
*operations.GetFileHashResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.GetFileHashResponseBody | 401 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
This endpoint will return the recently added content.
package main
import(
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo"
"context"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithXPlexClientIdentifier("Postman"),
)
ctx := context.Background()
res, err := s.Library.GetRecentlyAdded(ctx)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
*operations.GetRecentlyAddedResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.GetRecentlyAddedResponseBody | 401 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
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).
package main
import(
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo"
"context"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithXPlexClientIdentifier("Postman"),
)
ctx := context.Background()
res, err := s.Library.GetLibraries(ctx)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
*operations.GetLibrariesResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.GetLibrariesResponseBody | 401 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
This endpoint provides comprehensive details about the library, focusing on organizational aspects rather than the content itself.
The details include:
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.
- Marked with
-
Special Directories:
- Includes a "By Folder" entry for filesystem-based browsing.
- Contains an obsolete
search="1"
entry for on-the-fly search dialog creation.
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), andtitle
.
-
Sort Objects:
- Description of sort fields.
- Attributes include
defaultDirection
(asc/desc),descKey
andkey
(sort parameters), andtitle
.
Note: Filters and sorts are optional; without them, no filtering controls are rendered.
package main
import(
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations"
"context"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithXPlexClientIdentifier("Postman"),
)
var sectionID float64 = 1000
var includeDetails *operations.IncludeDetails = operations.IncludeDetailsZero.ToPointer()
ctx := context.Background()
res, err := s.Library.GetLibrary(ctx, sectionID, includeDetails)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
sectionID |
float64 | ✔️ | the Id of the library to query | 1000 |
includeDetails |
*operations.IncludeDetails | ➖ | Whether or not to include details for a section (types, filters, and sorts). Only exists for backwards compatibility, media providers other than the server libraries have it on always. |
*operations.GetLibraryResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.GetLibraryResponseBody | 401 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
Delate a library using a specific section
package main
import(
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo"
"context"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithXPlexClientIdentifier("Postman"),
)
var sectionID float64 = 1000
ctx := context.Background()
res, err := s.Library.DeleteLibrary(ctx, sectionID)
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
sectionID |
float64 | ✔️ | the Id of the library to query | 1000 |
*operations.DeleteLibraryResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.DeleteLibraryResponseBody | 401 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
This endpoint Refreshes the library.
package main
import(
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo"
"context"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithXPlexClientIdentifier("Postman"),
)
var sectionID float64 = 934.16
ctx := context.Background()
res, err := s.Library.RefreshLibrary(ctx, sectionID)
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
sectionID |
float64 | ✔️ | the Id of the library to refresh |
*operations.RefreshLibraryResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.RefreshLibraryResponseBody | 401 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
Search for content within a specific section of the library.
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), andtitle
.
-
Sort Objects:
- Description of sort fields.
- Attributes include
defaultDirection
(asc/desc),descKey
andkey
(sort parameters), andtitle
.
Note: Filters and sorts are optional; without them, no filtering controls are rendered.
package main
import(
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations"
"context"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithXPlexClientIdentifier("Postman"),
)
var sectionID int64 = 933505
var type_ operations.Type = operations.TypeFour
ctx := context.Background()
res, err := s.Library.SearchLibrary(ctx, sectionID, type_)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
sectionID |
int64 | ✔️ | the Id of the library to query |
type_ |
operations.Type | ✔️ | Plex content type to search for |
*operations.SearchLibraryResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |
This endpoint will return the metadata of a library item specified with the ratingKey.
package main
import(
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo"
"context"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithXPlexClientIdentifier("Postman"),
)
var ratingKey float64 = 8382.31
ctx := context.Background()
res, err := s.Library.GetMetadata(ctx, ratingKey)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
ratingKey |
float64 | ✔️ | the id of the library item to return the children of. |
*operations.GetMetadataResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.GetMetadataResponseBody | 401 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
This endpoint will return the children of of a library item specified with the ratingKey.
package main
import(
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo"
"context"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithXPlexClientIdentifier("Postman"),
)
var ratingKey float64 = 1539.14
ctx := context.Background()
res, err := s.Library.GetMetadataChildren(ctx, ratingKey)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
ratingKey |
float64 | ✔️ | the id of the library item to return the children of. |
*operations.GetMetadataChildrenResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.GetMetadataChildrenResponseBody | 401 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
This endpoint will return the on deck content.
package main
import(
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo"
"context"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithXPlexClientIdentifier("Postman"),
)
ctx := context.Background()
res, err := s.Library.GetOnDeck(ctx)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
*operations.GetOnDeckResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.GetOnDeckResponseBody | 401 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |