Skip to content

Small node module used to query the Plex Media Server HTTP API

License

Notifications You must be signed in to change notification settings

digitalgecko/node-plex-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

plex-api Build Status

Small module used to query the Plex Media Server HTTP API. Translates the XML given from the server to JSON.

Usage

query(uri) : Retrieve content from URI

Aside from translating all XML properties into JSON properties, a .uri-attribute are created to easier follow the URIs available in the HTTP API. At the moment URIs are attached for Directory and Server items.

var PlexAPI = require("plex-api");
var client = new PlexAPI("192.168.0.1");

client.query("/").then(function (result) {
	result.attributes; 	// MediaContainer attributes
	result.directory; 	// array of child Directory items
						// all directory-items will have the .uri-attribute attached
}, function (err) {
	throw new Error("Could not connect to server");
});

perform(uri) : Perform an API action

When performing an "action" on the HTTP API, the response body will be empty. As the response content itself will be worthless, perform() acts on the HTTP status codes the server responds with.

var PlexAPI = require("plex-api");
var client = new PlexAPI("192.168.0.1");

// update library section of key "1"
client.perform("/library/sections/1/refresh").then(function () {
	// successfully started to refresh library section #1
}, function (err) {
	throw new Error("Could not connect to server");
});

find(uri, [{criterias}]) : Find matching child items on URI

Uses the .query() behind the scenes, giving all directories the beloved .uri-attribute.

var PlexAPI = require("plex-api");
var client = new PlexAPI("192.168.0.1");

// filter directories on Directory attributes
client.find("/library/sections", {type: "movie"}).then(function (directories) {
	// directories would be an array of sections whose type are "movie"
}, function (err) {
	throw new Error("Could not connect to server");
});

// criterias are interpreted as regular expressions
client.find("/library/sections", {type: "movie|shows"}).then(function (directories) {
	// directories type would be "movie" OR "shows"
}, function (err) {
	throw new Error("Could not connect to server");
});

// shorthand to retrieve all Directories
client.find("/").then(function (directories) {
	// directories would be an array of Directory items
}, function (err) {
	throw new Error("Could not connect to server");
});

HTTP API Documentation

For more information about the API capabilities, see the HTTP/API Control description at plexapp.com

Running tests

$ make test

Or auto run tests while writing code

$ make tdd

Contributing

Contributions are more than welcome! Create an issue describing what you want to do. If that feature is seen to fit this project, send a pull request with the changes accompanied by tests.

Changelog

v0.4.2

  • Updated dependencies
  • Housekeeping with some minor code refactor

v0.4.1

  • Bugfix for not releasing HTTP agent sockets properly on .perform()

v0.4.0

  • Converted all methods to return promises, rather than accepting callback as argument
  • Converted buster tests to mocha/expect.js

v0.2.3

  • .find() matches attribute values by regular expression
  • Added getters for hostname and port
  • Made constructor hostname parameter required

v0.2.2

  • Bugfix for .find() only working when having Directory items

v0.2.1

  • Generalized URI resolving as bugfix for other types of items than Directories
  • Added URIs for Server items

v0.2.0

  • important Removed explicit XML to JSON conversion to ensure consistent child item names. The main difference for those using previous module versions, is the need to change their use of result.directories to result.directory.

License

(The MIT License)

Copyright (c) 2013-2014 Phillip Johnsen <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Small node module used to query the Plex Media Server HTTP API

Resources

License

Stars

Watchers

Forks

Packages

No packages published