From 4aaaee5f2043fb047b5e2f806e53204855d3f918 Mon Sep 17 00:00:00 2001 From: Wifsimster Date: Sun, 11 Aug 2019 13:00:12 +0200 Subject: [PATCH] Add image method --- README.md | 59 ++++++++++++++++++++++++++++++++------ pavie.js | 78 +++++++++++++++++++++++++++++++++++--------------- test/signin.js | 2 +- 3 files changed, 107 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 9e82269..2fdc19c 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,14 @@ Tested on Plex Media Server v1.16.3. [Synchronize](https://github.com/Wifsimster/pavie#synchronize) -[Hubs](https://github.com/Wifsimster/pavie#hubs) - [Playlists](https://github.com/Wifsimster/pavie#playlists) [History](https://github.com/Wifsimster/pavie#history) +[Metadata](https://github.com/Wifsimster/pavie#metadata) + +[Images](https://github.com/Wifsimster/pavie#images) + ## Install ``` @@ -131,12 +133,6 @@ Get synchronize info. Synchronize Plex and Trakt.tv. -### Hubs - -#### getHubs([action = 'continueWatching']) - -Hubs actions [continueWatching, onDeck]. - ### Playlists #### getPlaylists() @@ -194,5 +190,52 @@ Remove existing playlist. Get the history of a TV Shows. - `options` `` + - `metadataItemID` `` Identifiant - `sort` `` Order by, default : `viewed:desc` + + ### Metadata + + ### getMetadata([id]) + + Return all info about a media. + + - `id` `` Identifiant + + ### getMetadataChildren([id], [options]) + + Return all children metadata for a specified media. + ie: Returnn seasons metadata for a specified Tv Show. + + - `id` `` Identifiant + - `options` `` + - `excludeAllLeaves` ``, default: `1` + + ### getRelated([id], [options]) + + Return a list of related media. + + - `id` `` Identifiant + - `options` `` + - `excludeFields` ``, default: `summary` + - `includeExternalMetadata` ``, default: `1` + - `asyncAugmentMetadata` ``, default: `1` + + ### getSimilar([id]) + + Return a list of similar media. + + - `id` `` Identifiant + +### Images + +#### getImage([url], [options]) + +Return an image. + +- `url` `` Path to the image +- `options` `` + - `width` ``, default: `170` + - `height` ``, default: `96` + - `minSize` ``, default: `1` + - `upscale` ``, default: `1` diff --git a/pavie.js b/pavie.js index 626bcf6..04bee9a 100644 --- a/pavie.js +++ b/pavie.js @@ -193,17 +193,6 @@ module.exports = class { } } - /** - * Get metdata of a media - */ - async getMedatadata(id) { - const response = await this.instance.get(`/library/metadata/${id}`) - - if (response.status < 400) { - return response.data.MediaContainer - } - } - /** * Get a list of servers * Return: [name, host, address, port, machineIdentifier, version] @@ -238,18 +227,6 @@ module.exports = class { } } - /** - * Hubs actions - * [continueWatchig, onDeck] - */ - async getHubs(action = "continueWatching") { - const response = await this.instance.get(`/hubs/home/${action}`) - - if (response.status < 400) { - return response.data.MediaContainer - } - } - /** * Get all playlists */ @@ -345,4 +322,59 @@ module.exports = class { return response.data.MediaContainer } } + + /** + * Get metadata of a media + */ + async getMedatadata(id) { + const response = await this.instance.get(`/library/metadata/${id}?includePreferences=1`) + + if (response.status < 400) { + return response.data.MediaContainer + } + } + + /** + * Get children metadata of a media + * ie: Seasons metadata for a specified Tv Show + */ + async getMedatadataChildren(id, options = {}) { + options = Object.assign({ excludeAllLeaves: 1 }, options) + const response = await this.instance.get(`/library/metadata/${id}/children?${querystring.stringify(options)}`) + + if (response.status < 400) { + return response.data.MediaContainer + } + } + + async getRelated(id, options = {}) { + options = Object.assign({ excludeFields: "summary", includeExternalMetadata: 1, asyncAugmentMetadata: 1 }, options) + const response = await this.instance.get(`/hubs/metadata/${id}/related?${querystring.stringify(options)}`) + + if (response.status < 400) { + return response.data.MediaContainer + } + } + + async getSimilar(id) { + const response = await this.instance.get(`/hubs/metadata/${id}/similar`) + + if (response.status < 400) { + return response.data.MediaContainer + } + } + + /** + * Return an image + * url: /library/metadata/25963/thumb/1557058611?X-Plex-Token=fPHNF2Wkg84qDPprCbqy + */ + async getImage(url, options = {}) { + options = Object.assign({ width: 170, height: 96, minSize: 1, upscale: 1, url: url }, options) + + const response = await this.instance.get(`/photo/:/transcode?${querystring.stringify(options)}`) + + if (response.status < 400) { + return response.data.MediaContainer + } + } } diff --git a/test/signin.js b/test/signin.js index e5de526..651a26b 100644 --- a/test/signin.js +++ b/test/signin.js @@ -7,7 +7,7 @@ const pavie = new Pavie(settings) pavie .signin() .then(async () => { - const response = await pavie.getLibraries() + const response = await pavie.getActions() console.log(response) }) .catch(err => {