An API wrapper for the Plex Web API.
The Plex Web API is a poorly documented api exposed by Plex servers.
import 'package:dart_plex_api/dart_plex_api.dart';
- Create a
PlexCredentials
object representing your plex account
PlexCredentials credentials = PlexCredentials(
username: "<USERNAME>",
password: "<PASSWORD>",
);
- Create a
PlexHeaders
object with, at least, an identifier for your client.
PlexHeaders headers = PlexHeaders(
clientIdentifier: "Plex Dart Client",
);
- Finally, create a
PlexConnection
object passing the previous 2 objects. Be sure to call the asynchronousauthorize
method to ensure a safe connection.
PlexConnection connection = await PlexConnection(
host: "127.0.0.1",
port: 32400,
credentials: credentials,
headers: headers,
).authorize();
dart_plex_api supports manual raw requests and known routes (using PlexRoutes).
http.Response response = await connection.requestRaw("/");
Since the API is not properly documented, it may be difficult to know the exact result structure and correct route formats. PlexRoute
objects provide a way to quickly query routes without immediate knowledge of raw routes. Each PlexRoute
has a request
which returns a PlexObject
.
PlexRoot root = await connection.root.request();
This is also useful when multiple requests are neccessary to retrieve data. For example, it would be wise to query all library sections (at "/library/sections"
) to get a listing of library sections, followed by a request to get more details (at "/library/sections/<SECTION_KEY>"
).
dynamic sections = json.decode(
(await connection.requestRaw("/library/sections")).body
)["MediaContainer"]["Directory"][0];
dynamic firstSection = json.decode(
(await connection.requestRaw("/library/sections/" + sections["key"])).body
);
This can be done much easier using routing objects.
PlexLibrarySectionIndex index = await connection.root.library.sections.all.request();
/// A String identifying the Library Section
String key = index.directory[0].key;
/// A String identifying the type of section (ie Music, Photos, Videos...)
String type = index.directory[0].type;
List<PlexObject> sections = await connection.root.library.sections
.get(
key: key,
typeString:type,
).request();
http.Response response = await connection.requestRaw("/");
PlexRoot root = await connection.root.request();
http.Response response = await connection.requestRaw("/library");
PlexLibrary library = await connection.root.library.request();
http.Response response = await connection.requestRaw("/library/sections/2");
PlexObject library = await connection.root.library.sections.get("2")request();
Unofficial Python Bindings for Plex Api: https://github.com/pkkid/python-plexapi
Unofficial API Wiki (Earlopain): https://gitlab.com/Earlopain/plex-webapi
Unofficial API Wiki (Arcanemagus): https://github.com/Arcanemagus/plex-api/wiki
Remote control API Wiki (plexinc): https://github.com/plexinc/plex-media-player/wiki/Remote-control-API