GithubHelp home page GithubHelp logo

jslattery26packages / dart_plex_api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jacob-shuman/dart_plex_api

0.0 0.0 0.0 54 KB

Unofficial Dart wrapper for the Plex Web API

License: MIT License

Dart 100.00%

dart_plex_api's Introduction

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

dart_plex_api's People

Contributors

jacob-shuman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.