Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@hyperlink/plex-api
Advanced tools
Readme
Small module which helps you query the Plex Media Server HTTP API.
PlexAPI(options | hostname)
Instantiate a PlexAPI client.
The parameter can be a string representing the server's hostname, or an object with the following properties:
Options:
32400
)false
)generated uuid v4
. Note: you should really provide this rather than let it get generated. Every time your app runs, a new "device" will get registered on your Plex account, which can lead to poor performance once hundreds or thousands of them get created. Trust me!Plex Web
, Plex Home Theater
, Plex for Xbox One
. Default Node.js App
1.0
Node.js App
Chrome
, Plex Home Theater
, Windows
. Default is Node.js
.Windows
, iPhone
, Xbox One
. Default is whatever os.platform()
returns.Here's an example of what an app shows up as on the Plex web interface
The rows in that example from top to bottom are deviceName
, version
, product
, and device
.
Retrieve content from URI
The parameter can be a string representing the URI, or an object with the following properties:
Aside from requesting the API and returning its response, an .uri
property 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) {
console.log("%s running Plex Media Server v%s",
result.friendlyName,
result.version);
// array of children, such as Directory or Server items
// will have the .uri-property attached
console.log(result._children);
}, function (err) {
throw new Error("Could not connect to server");
});
Send a POST request and retrieve the response
This is identical to query()
, except that the request will be a POST rather than a GET. It has the same required and optional parameters as query()
.
Note that the parameters can only be passed as a query string as part of the uri, which is all Plex requires. (Content-Length
will always be zero)
var PlexAPI = require("plex-api");
var client = new PlexAPI("192.168.0.1");
client.postQuery("/playQueue?type=video&uri=someuri&shuffle=0").then(function (result) {
console.log("Added video to playQueue %s",
result.playQueueID);
// array of children, such as Directory or Server items
// will have the .uri-property attached
console.log(result._children);
}, function (err) {
throw new Error("Could not connect to server");
});
Send a PUT request and retrieve the response
This is identical to query()
, except that the request will be a PUT rather than a GET. It has the same required and optional parameters as query()
. It's is used to update parts of your Plex library.
Note that the parameters can only be passed as a query string as part of the uri, which is all Plex requires. (Content-Length
will always be zero)
var PlexAPI = require("plex-api");
var client = new PlexAPI("192.168.0.1");
client.putQuery("/library/sections/3/all?id=123&summary.value=updatedSummaryText")
.then(function (result) {
console.log("Description of video by id 123 has been set to 'updatedSummaryText'");
}, function (err) {
throw new Error("Could not connect to server");
});
Perform an API action
When performing an "action" on the HTTP API, the response body will be empty.
As the response content itself is worthless, perform()
acts on the HTTP status codes the server responds with.
It has the same required and optional parameters as query()
.
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 matching child items on URI
Uses query()
behind the scenes, giving all directories and servers the beloved .uri
property. It has the same required and optional parameters as query
, in addition to a second optional criterias
parameter.
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");
});
An authenticator is used by plex-api to authenticate its request against Plex Servers with a PlexHome setup. The most common authentication mechanism is by username and password.
You can provide your own custom authentication mechanism, read more about custom authenticators below.
Comes bundled with plex-api. Just provide options.username
and options.password
when creating a PlexAPI instance and you are good to go.
See the plex-api-credentials module for more information about its inner workings.
In its simplest form an authenticator
is an object with one required function authenticate()
which should return the autentication token needed by plex-api to satisfy Plex Server.
An optional method initialize()
could be implemented if you need reference to the created PlexAPI instance when it's created.
{
// OPTIONAL
initialize: function(plexApi) {
// plexApi === the PlexAPI instance just created
},
// REQUIRED
authenticate: function(plexApi, callback) {
// plexApi === the PlexAPI instance requesting the authentication token
// invoke callback if something fails
if (somethingFailed) {
return callback(new Error('I haz no cluez about token!'));
}
// or when you have a token
callback(null, 'I-found-this-token');
}
}
For more information about the API capabilities, see the unofficial Plex API documentation. The PlexInc's desktop client wiki might also be valueable.
$ npm test
plex-api has proven to be useful in more than one project over the years.
Do you have project which uses plex-api? Please tell us about it and we'll list it here :)
Alexa (Amazon Echo) app for interacting with a Plex Server and controlling client playback.
https://github.com/OverloadUT/alexa-plex by @OverloadUT.
The Plex Remote control app for the Homey device.
https://github.com/MikeOne/nl.kikkert.plex by @MikeOne.
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.
(The MIT License)
Copyright (c) 2013-2015 Phillip Johnsen <phillip@lightweight.no>
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.
FAQs
Simple wrapper for querying against HTTP API on the Plex Media Server
The npm package @hyperlink/plex-api receives a total of 1 weekly downloads. As such, @hyperlink/plex-api popularity was classified as not popular.
We found that @hyperlink/plex-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.