Skip to content

Commit

Permalink
Add image method
Browse files Browse the repository at this point in the history
  • Loading branch information
Wifsimster committed Aug 11, 2019
1 parent aff492a commit 4aaaee5
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 32 deletions.
59 changes: 51 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down Expand Up @@ -131,12 +133,6 @@ Get synchronize info.

Synchronize Plex and Trakt.tv.

### Hubs

#### getHubs([action = 'continueWatching'])

Hubs actions [continueWatching, onDeck].

### Playlists

#### getPlaylists()
Expand Down Expand Up @@ -194,5 +190,52 @@ Remove existing playlist.
Get the history of a TV Shows.

- `options` `<object>`

- `metadataItemID` `<number>` Identifiant
- `sort` `<string>` Order by, default : `viewed:desc`

### Metadata

### getMetadata([id])

Return all info about a media.

- `id` `<number>` Identifiant

### getMetadataChildren([id], [options])

Return all children metadata for a specified media.
ie: Returnn seasons metadata for a specified Tv Show.

- `id` `<number>` Identifiant
- `options` `<object>`
- `excludeAllLeaves` `<number>`, default: `1`

### getRelated([id], [options])

Return a list of related media.

- `id` `<number>` Identifiant
- `options` `<object>`
- `excludeFields` `<string>`, default: `summary`
- `includeExternalMetadata` `<number>`, default: `1`
- `asyncAugmentMetadata` `<number>`, default: `1`

### getSimilar([id])

Return a list of similar media.

- `id` `<number>` Identifiant

### Images

#### getImage([url], [options])

Return an image.

- `url` `<string>` Path to the image
- `options` `<object>`
- `width` `<number>`, default: `170`
- `height` `<number>`, default: `96`
- `minSize` `<number>`, default: `1`
- `upscale` `<number>`, default: `1`
78 changes: 55 additions & 23 deletions pavie.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
}
}
}
2 changes: 1 addition & 1 deletion test/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 4aaaee5

Please sign in to comment.