dart_plex_api 0.1.0

pub package

An API wrapper for the Plex Web API.

The Plex Web API is a poorly documented api exposed by Plex servers.

Import Package #

import 'package:dart_plex_api/dart_plex_api.dart';

Getting Started (Setup Connection) #

  1. Create a PlexCredentials object representing your plex account
PlexCredentials credentials = PlexCredentials(
    username: "<USERNAME>",
    password: "<PASSWORD>",
  );
  1. Create a PlexHeaders object with, at least, an identifier for your client.
PlexHeaders headers = PlexHeaders(
    clientIdentifier: "Plex Dart Client",
  );
  1. Finally, create a PlexConnection object passing the previous 2 objects. Be sure to call the asynchronous authorize method to ensure a safe connection.
PlexConnection connection = await PlexConnection(
    host: "127.0.0.1",
    port: 32400,
    credentials: credentials,
    headers: headers,
  ).authorize();

Requests #

dart_plex_api supports manual raw requests and known routes (using PlexRoutes).

Raw #

http.Response response = await connection.requestRaw("/");

Routing #

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();

Usage #

Root #

Raw #

http.Response response = await connection.requestRaw("/");

Routing #

PlexRoot root = await connection.root.request();

Library #

Raw #

http.Response response = await connection.requestRaw("/library");

Routing #

PlexLibrary library = await connection.root.library.request();

Library Section #

Raw #

http.Response response = await connection.requestRaw("/library/sections/2");

Routing #

PlexObject library = await connection.root.library.sections.get("2")request();

Other Resources #

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

0.1.0 #

  • Added non-null unit testing for routes
  • Added common plex data models
  • Implemented Routing! (Root, Library, Servers, Clients)
  • Added Exceptions

0.0.1 #

  • Implemented Media Types
  • Initial version, created by Stagehand

example/dart_plex_api_example.dart

import 'package:dart_plex_api/dart_plex_api.dart';

main() async {
  PlexCredentials credentials = PlexCredentials(
    username: "<USERNAME>",
    password: "<PASSWORD>",
  );

  PlexHeaders headers = PlexHeaders(
    clientIdentifier: "Plex Dart Client",
  );

  PlexConnection connection = await PlexConnection(
    host: "127.0.0.1",
    port: 32400,
    credentials: credentials,
    headers: headers,
  ).authorize();

  // Returns an http [Response] object
  await connection.requestRaw("/");
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dart_plex_api: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_plex_api/dart_plex_api.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
4
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
83
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Aug 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:dart_plex_api/dart_plex_api.dart.

Health suggestions

Format lib/src/object/library/plex_library.dart.

Run dartfmt to format lib/src/object/library/plex_library.dart.

Format lib/src/object/library/section/plex_artist_section.dart.

Run dartfmt to format lib/src/object/library/section/plex_artist_section.dart.

Format lib/src/object/library/section/plex_library_section.dart.

Run dartfmt to format lib/src/object/library/section/plex_library_section.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/object/library/section/plex_library_section_index.dart (Run dartfmt to format lib/src/object/library/section/plex_library_section_index.dart.)
  • lib/src/object/plex_root.dart (Run dartfmt to format lib/src/object/plex_root.dart.)
  • lib/src/route/library/plex_all_library_sections_route.dart (Run dartfmt to format lib/src/route/library/plex_all_library_sections_route.dart.)

Maintenance suggestions

The package description is too short. (-17 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
http ^0.12.0+2 0.12.0+2
meta ^1.1.7 1.1.7
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
pedantic ^1.0.0 1.8.0+1
test ^1.0.0