From c15ddfcc7f5d9db824d87d0efc9b7ff5a91703e1 Mon Sep 17 00:00:00 2001 From: Wifsimster Date: Sun, 11 Aug 2019 11:47:15 +0200 Subject: [PATCH] Add playlist methods --- .gitignore | 1 + README.md | 82 ++++++++++++++++++++++++++++++------ pavie.js | 84 +++++++++++++++++++++++++++++++++++++ test/playlists.js | 28 +++++++++++++ server.js => test/signin.js | 6 ++- 5 files changed, 187 insertions(+), 14 deletions(-) create mode 100644 test/playlists.js rename server.js => test/signin.js (59%) diff --git a/.gitignore b/.gitignore index 93548ab..3488be3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ .vscode/ .git +settings.json diff --git a/README.md b/README.md index 0ff4383..fd3f39e 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,17 @@ Get the list actions availables. ie : platform, platformVersion, updatedAt, version, machineIdentifier, myPlexUsername. Return : [activities, butler, channels, clients, devices, diagnostics, hubs, library, livetv, media, player, playlists, resources, search, server, ...]. +#### getMedatadata([id]) + +Get metdata of a media. + +#### getServers() + +Get a list of servers. +Return: [name, host, address, port, machineIdentifier, version]. + +### Libraries + #### getLibraries() Get a list of libraries. @@ -72,6 +83,12 @@ Return: [section, recentlyAdded, onDeck]. Get a list of sections in the library. Return: [Movies, Music, TV Shows]. +#### refresh([library = 'sections'], [sectionId = 2]) + +Refresh a section. + +### Directories + #### getDirectoriesFromSection([library = 'sections'], [sectionId = 2]) Get list of directory in a specified section. @@ -90,18 +107,7 @@ Search Tv Shows, episodes, movies or musics. Default : [sectionId : Tv Shows, type: Tv Shows] For Tv Shows, type: [2: Tv Shows, 3: Seasonn, 4 : Episode] -#### refresh([library = 'sections'], [sectionId = 2]) - -Refresh a section. - -#### getMedatadata([id]) - -Get metdata of a media. - -#### getServers() - -Get a list of servers. -Return: [name, host, address, port, machineIdentifier, version]. +### Synchronize #### getSynchronize() @@ -111,6 +117,58 @@ Get synchronize info. Synchronize Plex and Trakt.tv. +### Hubs + #### getHubs([action = 'continueWatching']) Hubs actions [continueWatching, onDeck] + +### Playlists + +#### getPlaylists() + +Get all playlists + +#### getPlaylist([ratingKey]) + +Get playlist basic info + +- `ratingKey` ` | ` Identifiant + +#### getPlaylistFiles([ratingKey]) + +Get playlist video files + +- `ratingKey` ` | ` Identifiant + +#### addPlaylist([data]) + +Add new playlist + +- `data` `` + - `uri` `` Path to a list of video files, ie : `server://2c59cf8256eccd8629081638e98e27bf8349c3e7/com.plexapp.plugins.library/library/metadata/26082` + - `title` `` Title of the playlist + - `smart` `` Default: `0` + - `type` `` Default: `video` + +#### updatePlaylist([ratingKey], [data]) + +Update existing playlist + +- `ratingKey` ` | ` Identifiant +- `data` `` + - `title` `` Title + - `summary` `` Description + +#### updatePlaylistFiles([ratingKey], [uri]) + +Add files to an existing playlist + +- `ratingKey` ` | ` Identifiant +- `uri` `` Path to a list of video files, ie: `server://2c59cf8256eccd8629081638e98e27bf8349c3e7/com.plexapp.plugins.library/library/metadata/26082` + +#### removePlaylist([ratingKey]) + +Remove existing playlist + +- `ratingKey` ` | ` Identifiant diff --git a/pavie.js b/pavie.js index 7d8d067..5657819 100644 --- a/pavie.js +++ b/pavie.js @@ -249,4 +249,88 @@ module.exports = class { return response.data.MediaContainer } } + + /** + * Get all playlists + */ + async getPlaylists() { + const response = await this.instance.get(`/playlists`) + + if (response.status < 400) { + return response.data.MediaContainer + } + } + + /** + * Get playlist basic info + */ + async getPlaylist(ratingKey) { + const response = await this.instance.get(`/playlists/${ratingKey}`) + + if (response.status < 400) { + return response.data.MediaContainer + } + } + + /** + * Get playlist video files + */ + async getPlaylistFiles(ratingKey) { + const response = await this.instance.get(`/playlists/${ratingKey}/items`) + + if (response.status < 400) { + return response.data.MediaContainer + } + } + + /** + * Add playlist + */ + async addPlaylist(data) { + data = Object.assign( + { + smart: 0, + type: "video" + }, + data + ) + const response = await this.instance.post(`/playlists?${querystring.stringify(data)}`) + + if (response.status < 400) { + return response.data.MediaContainer + } + } + + /** + * Update playlist + */ + async updatePlaylist(ratingKey, data) { + const response = await this.instance.put(`/playlists/${ratingKey}?${querystring.stringify(data)}`) + + if (response.status < 400) { + return response.data + } + } + + /** + * Update playlist files + */ + async updatePlaylistFiles(ratingKey, uri) { + const response = await this.instance.put(`/playlists/${ratingKey}/items?uri=${uri}`) + + if (response.status < 400) { + return response.data + } + } + + /** + * Remove playlist + */ + async removePlaylist(ratingKey) { + const response = await this.instance.delete(`/playlists/${ratingKey}`) + + if (response.status < 400) { + return response.data + } + } } diff --git a/test/playlists.js b/test/playlists.js new file mode 100644 index 0000000..df4a25a --- /dev/null +++ b/test/playlists.js @@ -0,0 +1,28 @@ +const settings = require("../settings.json") + +const Pavie = require("../pavie") + +const pavie = new Pavie(settings) + +// pavie +// .signin() +// .then(async () => { +// const response = await pavie.getPlaylists() +// console.log(response) +// }) +// .catch(err => { +// console.error(err) +// }) + +pavie + .signin() + .then(async () => { + const response = await pavie.addPlaylistFiles({ + uri: "server://2c59cf8256eccd8629081638e98e27bf8349c3e7/com.plexapp.plugins.library/library/metadata/8412", + title: "lorem" + }) + console.log(response) + }) + .catch(err => { + console.error(err) + }) diff --git a/server.js b/test/signin.js similarity index 59% rename from server.js rename to test/signin.js index 220efe4..e5de526 100644 --- a/server.js +++ b/test/signin.js @@ -1,6 +1,8 @@ -const Pavie = require("./pavie") +const settings = require("../settings.json") -const pavie = new Pavie({ username: "USERNAME", password: "PASWORD" }) +const Pavie = require("../pavie") + +const pavie = new Pavie(settings) pavie .signin()