Files
plexjava/docs/sdks/playlists
2024-07-01 16:03:10 +00:00
..
2024-07-01 16:03:10 +00:00

Playlists

(playlists())

Overview

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"). They can be organized in (optionally nesting) folders. Retrieving a playlist, or its items, will trigger a refresh of its metadata. This may cause the duration and number of items to change.

Available Operations

createPlaylist

Create a new playlist. By default the playlist is blank. To create a playlist along with a first item, pass:

  • uri - The content URI for what we're playing (e.g. server://1234/com.plexapp.plugins.library/library/metadata/1).
  • playQueueID - To create a playlist from an existing play queue.

Example Usage

package hello.world;

import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import lukehagar.plexapi.plexapi.PlexAPI;
import lukehagar.plexapi.plexapi.models.operations.*;
import lukehagar.plexapi.plexapi.models.shared.*;
import lukehagar.plexapi.plexapi.models.shared.Security;
import lukehagar.plexapi.plexapi.utils.EventStream;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            PlexAPI sdk = PlexAPI.builder()
                .accessToken("<YOUR_API_KEY_HERE>")
                .xPlexClientIdentifier("Postman")
                .build();

            CreatePlaylistRequest req = CreatePlaylistRequest.builder()
                .title("<value>")
                .type(QueryParamType.PHOTO)
                .smart(Smart.ONE)
                .uri("<value>")
                .build();

            CreatePlaylistResponse res = sdk.playlists().createPlaylist()
                .request(req)
                .call();

            if (res.object().isPresent()) {
                // handle response
            }
        } catch (lukehagar.plexapi.plexapi.models.errors.CreatePlaylistResponseBody e) {
            // handle exception
            throw e;
        } catch (lukehagar.plexapi.plexapi.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }

    }
}

Parameters

Parameter Type Required Description
request lukehagar.plexapi.plexapi.models.operations.CreatePlaylistRequest ✔️ The request object to use for the request.

Response

lukehagar.plexapi.plexapi.models.operations.CreatePlaylistResponse

Errors

Error Object Status Code Content Type
models/errors/CreatePlaylistResponseBody 401 application/json
models/errors/SDKError 4xx-5xx */*

getPlaylists

Get All Playlists given the specified filters.

Example Usage

package hello.world;

import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import lukehagar.plexapi.plexapi.PlexAPI;
import lukehagar.plexapi.plexapi.models.operations.*;
import lukehagar.plexapi.plexapi.models.shared.*;
import lukehagar.plexapi.plexapi.models.shared.Security;
import lukehagar.plexapi.plexapi.utils.EventStream;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            PlexAPI sdk = PlexAPI.builder()
                .accessToken("<YOUR_API_KEY_HERE>")
                .xPlexClientIdentifier("Postman")
                .build();

            GetPlaylistsResponse res = sdk.playlists().getPlaylists()
                .playlistType(PlaylistType.AUDIO)
                .smart(QueryParamSmart.ZERO)
                .call();

            if (res.object().isPresent()) {
                // handle response
            }
        } catch (lukehagar.plexapi.plexapi.models.errors.GetPlaylistsResponseBody e) {
            // handle exception
            throw e;
        } catch (lukehagar.plexapi.plexapi.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }

    }
}

Parameters

Parameter Type Required Description
playlistType Optional<? extends lukehagar.plexapi.plexapi.models.operations.PlaylistType> limit to a type of playlist.
smart Optional<? extends lukehagar.plexapi.plexapi.models.operations.QueryParamSmart> type of playlists to return (default is all).

Response

lukehagar.plexapi.plexapi.models.operations.GetPlaylistsResponse

Errors

Error Object Status Code Content Type
models/errors/GetPlaylistsResponseBody 401 application/json
models/errors/SDKError 4xx-5xx */*

getPlaylist

Gets detailed metadata for a playlist. A playlist for many purposes (rating, editing metadata, tagging), can be treated like a regular metadata item: Smart playlist details contain the content attribute. This is the content URI for the generator. This can then be parsed by a client to provide smart playlist editing.

Example Usage

package hello.world;

import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import lukehagar.plexapi.plexapi.PlexAPI;
import lukehagar.plexapi.plexapi.models.operations.*;
import lukehagar.plexapi.plexapi.models.shared.*;
import lukehagar.plexapi.plexapi.models.shared.Security;
import lukehagar.plexapi.plexapi.utils.EventStream;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            PlexAPI sdk = PlexAPI.builder()
                .accessToken("<YOUR_API_KEY_HERE>")
                .xPlexClientIdentifier("Postman")
                .build();

            GetPlaylistResponse res = sdk.playlists().getPlaylist()
                .playlistID(4109.48d)
                .call();

            if (res.object().isPresent()) {
                // handle response
            }
        } catch (lukehagar.plexapi.plexapi.models.errors.GetPlaylistResponseBody e) {
            // handle exception
            throw e;
        } catch (lukehagar.plexapi.plexapi.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }

    }
}

Parameters

Parameter Type Required Description
playlistID double ✔️ the ID of the playlist

Response

lukehagar.plexapi.plexapi.models.operations.GetPlaylistResponse

Errors

Error Object Status Code Content Type
models/errors/GetPlaylistResponseBody 401 application/json
models/errors/SDKError 4xx-5xx */*

deletePlaylist

This endpoint will delete a playlist

Example Usage

package hello.world;

import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import lukehagar.plexapi.plexapi.PlexAPI;
import lukehagar.plexapi.plexapi.models.operations.*;
import lukehagar.plexapi.plexapi.models.shared.*;
import lukehagar.plexapi.plexapi.models.shared.Security;
import lukehagar.plexapi.plexapi.utils.EventStream;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            PlexAPI sdk = PlexAPI.builder()
                .accessToken("<YOUR_API_KEY_HERE>")
                .xPlexClientIdentifier("Postman")
                .build();

            DeletePlaylistResponse res = sdk.playlists().deletePlaylist()
                .playlistID(216.22d)
                .call();

            // handle response
        } catch (lukehagar.plexapi.plexapi.models.errors.DeletePlaylistResponseBody e) {
            // handle exception
            throw e;
        } catch (lukehagar.plexapi.plexapi.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }

    }
}

Parameters

Parameter Type Required Description
playlistID double ✔️ the ID of the playlist

Response

lukehagar.plexapi.plexapi.models.operations.DeletePlaylistResponse

Errors

Error Object Status Code Content Type
models/errors/DeletePlaylistResponseBody 401 application/json
models/errors/SDKError 4xx-5xx */*

updatePlaylist

From PMS version 1.9.1 clients can also edit playlist metadata using this endpoint as they would via PUT /library/metadata/{playlistID}

Example Usage

package hello.world;

import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import lukehagar.plexapi.plexapi.PlexAPI;
import lukehagar.plexapi.plexapi.models.operations.*;
import lukehagar.plexapi.plexapi.models.shared.*;
import lukehagar.plexapi.plexapi.models.shared.Security;
import lukehagar.plexapi.plexapi.utils.EventStream;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            PlexAPI sdk = PlexAPI.builder()
                .accessToken("<YOUR_API_KEY_HERE>")
                .xPlexClientIdentifier("Postman")
                .build();

            UpdatePlaylistResponse res = sdk.playlists().updatePlaylist()
                .playlistID(3915d)
                .title("<value>")
                .summary("<value>")
                .call();

            // handle response
        } catch (lukehagar.plexapi.plexapi.models.errors.UpdatePlaylistResponseBody e) {
            // handle exception
            throw e;
        } catch (lukehagar.plexapi.plexapi.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }

    }
}

Parameters

Parameter Type Required Description
playlistID double ✔️ the ID of the playlist
title Optional<? extends String> name of the playlist
summary Optional<? extends String> summary description of the playlist

Response

lukehagar.plexapi.plexapi.models.operations.UpdatePlaylistResponse

Errors

Error Object Status Code Content Type
models/errors/UpdatePlaylistResponseBody 401 application/json
models/errors/SDKError 4xx-5xx */*

getPlaylistContents

Gets the contents of a playlist. Should be paged by clients via standard mechanisms. By default leaves are returned (e.g. episodes, movies). In order to return other types you can use the type parameter. For example, you could use this to display a list of recently added albums vis a smart playlist. Note that for dumb playlists, items have a playlistItemID attribute which is used for deleting or moving items.

Example Usage

package hello.world;

import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import lukehagar.plexapi.plexapi.PlexAPI;
import lukehagar.plexapi.plexapi.models.operations.*;
import lukehagar.plexapi.plexapi.models.shared.*;
import lukehagar.plexapi.plexapi.models.shared.Security;
import lukehagar.plexapi.plexapi.utils.EventStream;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            PlexAPI sdk = PlexAPI.builder()
                .accessToken("<YOUR_API_KEY_HERE>")
                .xPlexClientIdentifier("Postman")
                .build();

            GetPlaylistContentsResponse res = sdk.playlists().getPlaylistContents()
                .playlistID(5004.46d)
                .type(9403.59d)
                .call();

            if (res.object().isPresent()) {
                // handle response
            }
        } catch (lukehagar.plexapi.plexapi.models.errors.GetPlaylistContentsResponseBody e) {
            // handle exception
            throw e;
        } catch (lukehagar.plexapi.plexapi.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }

    }
}

Parameters

Parameter Type Required Description
playlistID double ✔️ the ID of the playlist
type double ✔️ the metadata type of the item to return

Response

lukehagar.plexapi.plexapi.models.operations.GetPlaylistContentsResponse

Errors

Error Object Status Code Content Type
models/errors/GetPlaylistContentsResponseBody 401 application/json
models/errors/SDKError 4xx-5xx */*

clearPlaylistContents

Clears a playlist, only works with dumb playlists. Returns the playlist.

Example Usage

package hello.world;

import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import lukehagar.plexapi.plexapi.PlexAPI;
import lukehagar.plexapi.plexapi.models.operations.*;
import lukehagar.plexapi.plexapi.models.shared.*;
import lukehagar.plexapi.plexapi.models.shared.Security;
import lukehagar.plexapi.plexapi.utils.EventStream;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            PlexAPI sdk = PlexAPI.builder()
                .accessToken("<YOUR_API_KEY_HERE>")
                .xPlexClientIdentifier("Postman")
                .build();

            ClearPlaylistContentsResponse res = sdk.playlists().clearPlaylistContents()
                .playlistID(1893.18d)
                .call();

            // handle response
        } catch (lukehagar.plexapi.plexapi.models.errors.ClearPlaylistContentsResponseBody e) {
            // handle exception
            throw e;
        } catch (lukehagar.plexapi.plexapi.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }

    }
}

Parameters

Parameter Type Required Description
playlistID double ✔️ the ID of the playlist

Response

lukehagar.plexapi.plexapi.models.operations.ClearPlaylistContentsResponse

Errors

Error Object Status Code Content Type
models/errors/ClearPlaylistContentsResponseBody 401 application/json
models/errors/SDKError 4xx-5xx */*

addPlaylistContents

Adds a generator to a playlist, same parameters as the POST to create. With a dumb playlist, this adds the specified items to the playlist. With a smart playlist, passing a new uri parameter replaces the rules for the playlist. Returns the playlist.

Example Usage

package hello.world;

import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import lukehagar.plexapi.plexapi.PlexAPI;
import lukehagar.plexapi.plexapi.models.operations.*;
import lukehagar.plexapi.plexapi.models.shared.*;
import lukehagar.plexapi.plexapi.models.shared.Security;
import lukehagar.plexapi.plexapi.utils.EventStream;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            PlexAPI sdk = PlexAPI.builder()
                .accessToken("<YOUR_API_KEY_HERE>")
                .xPlexClientIdentifier("Postman")
                .build();

            AddPlaylistContentsResponse res = sdk.playlists().addPlaylistContents()
                .playlistID(8502.01d)
                .uri("server://12345/com.plexapp.plugins.library/library/metadata/1")
                .playQueueID(123d)
                .call();

            if (res.object().isPresent()) {
                // handle response
            }
        } catch (lukehagar.plexapi.plexapi.models.errors.AddPlaylistContentsResponseBody e) {
            // handle exception
            throw e;
        } catch (lukehagar.plexapi.plexapi.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }

    }
}

Parameters

Parameter Type Required Description Example
playlistID double ✔️ the ID of the playlist
uri String ✔️ the content URI for the playlist server://12345/com.plexapp.plugins.library/library/metadata/1
playQueueID Optional<? extends Double> the play queue to add to a playlist 123

Response

lukehagar.plexapi.plexapi.models.operations.AddPlaylistContentsResponse

Errors

Error Object Status Code Content Type
models/errors/AddPlaylistContentsResponseBody 401 application/json
models/errors/SDKError 4xx-5xx */*

uploadPlaylist

Imports m3u playlists by passing a path on the server to scan for m3u-formatted playlist files, or a path to a single playlist file.

Example Usage

package hello.world;

import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import lukehagar.plexapi.plexapi.PlexAPI;
import lukehagar.plexapi.plexapi.models.operations.*;
import lukehagar.plexapi.plexapi.models.shared.*;
import lukehagar.plexapi.plexapi.models.shared.Security;
import lukehagar.plexapi.plexapi.utils.EventStream;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            PlexAPI sdk = PlexAPI.builder()
                .accessToken("<YOUR_API_KEY_HERE>")
                .xPlexClientIdentifier("Postman")
                .build();

            UploadPlaylistResponse res = sdk.playlists().uploadPlaylist()
                .path("/home/barkley/playlist.m3u")
                .force(Force.ZERO)
                .call();

            // handle response
        } catch (lukehagar.plexapi.plexapi.models.errors.UploadPlaylistResponseBody e) {
            // handle exception
            throw e;
        } catch (lukehagar.plexapi.plexapi.models.errors.SDKError e) {
            // handle exception
            throw e;
        } catch (Exception e) {
            // handle exception
            throw e;
        }

    }
}

Parameters

Parameter Type Required Description Example
path String ✔️ absolute path to a directory on the server where m3u files are stored, or the absolute path to a playlist file on the server.
If the path argument is a directory, that path will be scanned for playlist files to be processed.
Each file in that directory creates a separate playlist, with a name based on the filename of the file that created it.
The GUID of each playlist is based on the filename.
If the path argument is a file, that file will be used to create a new playlist, with the name based on the filename of the file that created it.
The GUID of each playlist is based on the filename.
/home/barkley/playlist.m3u
force lukehagar.plexapi.plexapi.models.operations.Force ✔️ Force overwriting of duplicate playlists.
By default, a playlist file uploaded with the same path will overwrite the existing playlist.
The force argument is used to disable overwriting.
If the force argument is set to 0, a new playlist will be created suffixed with the date and time that the duplicate was uploaded.

Response

lukehagar.plexapi.plexapi.models.operations.UploadPlaylistResponse

Errors

Error Object Status Code Content Type
models/errors/UploadPlaylistResponseBody 401 application/json
models/errors/SDKError 4xx-5xx */*