Plex Media Server HTTP API Client
This library makes it easier to use the Plex Media Server HTTP API.
This library was written to be used to create fully featured PMS clients, which
would allow users to login with a Plex account and select an available server.
It also provides quite a few helper methods in the Library
class so you don't
have to manually construct the API paths yourself.
Note: This library only support music libraries at the moment, but there is
no reason it couldn't support other library types as well.
Usage
First add the library to your project
$ yarn add perplexed
Then create a new client instance. This describes the client that is making the
request. You can find more about these options on the node-plex-api
README.
const {Client} = require('perplexed')
const client = new Client({
identifier: 'f5941591-ef73-45e1-99c0-8f3a56941617',
product: 'Node.js App',
version: '1.0.0',
device: 'linux',
deviceName: 'Node.js App',
platform: 'Node.js',
platformVersion: '7.2.0',
})
Now you can create an account instance.
const {Account} = require('perplexed')
const account = new Account(client)
account.authenticate(username, password).then(() => {
})
Now you can create an server connection.
const {ServerConnection} = require('perplexed')
const uri = 'http://192.168.1.100:32400'
const serverConnection = new ServerConnection(uri, account)
Now use this connection to create a Library, which allows you to do awesome
stuff.
const {Library} = require('perplexed')
const library = new Library(serverConnection)
library.playlists().then((playlists) => {
})
Variables
Const DAYS
DAYS: "d" = "d"
Const HOURS
HOURS: "h" = "h"
Const MINUTES
MINUTES: "m" = "m"
Const MONTHS
MONTHS: "mon" = "mon"
Const PLAYLIST_TYPE_MUSIC
PLAYLIST_TYPE_MUSIC: "audio" = "audio"
Const PLAYLIST_TYPE_PHOTO
PLAYLIST_TYPE_PHOTO: "photo" = "photo"
Const PLAYLIST_TYPE_VIDEO
PLAYLIST_TYPE_VIDEO: "video" = "video"
Const PLEX_API
PLEX_API: "https://plex.tv" = "https://plex.tv"
Const SECONDS
SECONDS: "s" = "s"
Const SORT_ALBUMS_BY_ALBUM_ARTIST
SORT_ALBUMS_BY_ALBUM_ARTIST: string[] = sort('artist.titleSort,album.year','artist.titleSort:desc,album.year',)
Const SORT_ALBUMS_BY_DATE_ADDED
SORT_ALBUMS_BY_DATE_ADDED: string[] = sort('addedAt')
Const SORT_ALBUMS_BY_DATE_PLAYED
SORT_ALBUMS_BY_DATE_PLAYED: string[] = sort('lastViewedAt')
Const SORT_ALBUMS_BY_RATING
SORT_ALBUMS_BY_RATING: string[] = sort('userRating')
Const SORT_ALBUMS_BY_RELEASE_DATE
SORT_ALBUMS_BY_RELEASE_DATE: string[] = sort('originallyAvailableAt')
Const SORT_ALBUMS_BY_TITLE
SORT_ALBUMS_BY_TITLE: string[] = sort('titleSort')
Const SORT_ALBUMS_BY_VIEWS
SORT_ALBUMS_BY_VIEWS: string[] = sort('viewCount')
Const SORT_ALBUMS_BY_YEAR
SORT_ALBUMS_BY_YEAR: string[] = sort('year')
Const SORT_ARTISTS_BY_DATE_ADDED
SORT_ARTISTS_BY_DATE_ADDED: string[] = sort('addedAt')
Const SORT_ARTISTS_BY_DATE_PLAYED
SORT_ARTISTS_BY_DATE_PLAYED: string[] = sort('lastViewedAt')
Const SORT_ARTISTS_BY_PLAYS
SORT_ARTISTS_BY_PLAYS: string[] = sort('viewCount')
Const SORT_ARTISTS_BY_TITLE
SORT_ARTISTS_BY_TITLE: string[] = sort('titleSort')
Const SORT_PLAYLISTS_BY_DATE_ADDED
SORT_PLAYLISTS_BY_DATE_ADDED: string[] = sort('addedAt')
Const SORT_PLAYLISTS_BY_DURATION
SORT_PLAYLISTS_BY_DURATION: string[] = sort('duration')
Const SORT_PLAYLISTS_BY_ITEM_COUNT
SORT_PLAYLISTS_BY_ITEM_COUNT: string[] = sort('mediaCount')
Const SORT_PLAYLISTS_BY_LAST_PLAYED
SORT_PLAYLISTS_BY_LAST_PLAYED: string[] = sort('lastViewedAt')
Const SORT_PLAYLISTS_BY_NAME
SORT_PLAYLISTS_BY_NAME: string[] = sort('titleSort')
Const SORT_PLAYLISTS_BY_PLAYS
SORT_PLAYLISTS_BY_PLAYS: string[] = sort('viewCount')
Const SORT_TRACKS_BY_ALBUM
SORT_TRACKS_BY_ALBUM: string[] = sort('album.titleSort,track.index')
Const SORT_TRACKS_BY_ALBUM_ARTIST
SORT_TRACKS_BY_ALBUM_ARTIST: string[] = sort('artist.titleSort,album.titleSort,track.index',)
Const SORT_TRACKS_BY_ARTIST
SORT_TRACKS_BY_ARTIST: string[] = sort('track.originalTitle,album.titleSort,track.index',)
Const SORT_TRACKS_BY_BITRATE
SORT_TRACKS_BY_BITRATE: string[] = sort('mediaBitrate')
Const SORT_TRACKS_BY_DATE_ADDED
SORT_TRACKS_BY_DATE_ADDED: string[] = sort('addedAt')
Const SORT_TRACKS_BY_DURATION
SORT_TRACKS_BY_DURATION: string[] = sort('duration')
Const SORT_TRACKS_BY_PLAYS
SORT_TRACKS_BY_PLAYS: string[] = sort('viewCount')
Const SORT_TRACKS_BY_POPULARITY
SORT_TRACKS_BY_POPULARITY: string[] = sort('ratingCount')
Const SORT_TRACKS_BY_RATING
SORT_TRACKS_BY_RATING: string[] = sort('userRating')
Const SORT_TRACKS_BY_TITLE
SORT_TRACKS_BY_TITLE: string[] = sort('titleSort')
Const SORT_TRACKS_BY_YEAR
SORT_TRACKS_BY_YEAR: string[] = sort('year')
Const WEEKS
WEEKS: "w" = "w"
Const YEARS
YEARS: "y" = "y"
Const albumCollection
album
Collection: FilterValue = new FilterValue('album.collection')
Const albumDecade
album
Decade: FilterNumber = new FilterNumber('album.decade')
Const albumLastPlayed
album
LastPlayed: FilterDate = new FilterDate('album.lastViewdAt')
Const albumPlays
album
Plays: FilterNumber = new FilterNumber('album.viewCount')
Const albumRating
album
Rating: FilterNumber = new FilterNumber('album.userRating')
Const artistCollection
artist
Collection: FilterValue = new FilterValue('artist.collection')
Const artistRating
artist
Rating: FilterNumber = new FilterNumber('artist.userRating')
Const artistTitle
artist
Title: FilterString = new FilterString('artist.title')
Const dateAlbumAdded
date
AlbumAdded: FilterDate = new FilterDate('album.addedAt')
Const dateArtistAdded
date
ArtistAdded: FilterDate = new FilterDate('artist.addedAt')
Const trackLastPlayed
track
LastPlayed: FilterDate = new FilterDate('track.viewCount')
Const trackLastSkipped
track
LastSkipped: FilterDate = new FilterDate('track.lastSkippedAt')
Const trackPlays
track
Plays: FilterNumber = new FilterNumber('track.viewCount')
Const trackRating
track
Rating: FilterNumber = new FilterNumber('track.userRating')
Const trackSkips
track
Skips: FilterNumber = new FilterNumber('track.skipCount')
Parse a plex response based on the data type
data type
response from plex api