Skip to content

Commit

Permalink
Add playlist methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Wifsimster committed Aug 11, 2019
1 parent 083ee5d commit c15ddfc
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
.vscode/
.git
settings.json
82 changes: 70 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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()

Expand All @@ -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` `<string> | <number>` Identifiant

#### getPlaylistFiles([ratingKey])

Get playlist video files

- `ratingKey` `<string> | <number>` Identifiant

#### addPlaylist([data])

Add new playlist

- `data` `<object>`
- `uri` `<string>` Path to a list of video files, ie : `server://2c59cf8256eccd8629081638e98e27bf8349c3e7/com.plexapp.plugins.library/library/metadata/26082`
- `title` `<string>` Title of the playlist
- `smart` `<number>` Default: `0`
- `type` `<string>` Default: `video`

#### updatePlaylist([ratingKey], [data])

Update existing playlist

- `ratingKey` `<string> | <number>` Identifiant
- `data` `<object>`
- `title` `<string>` Title
- `summary` `<string>` Description

#### updatePlaylistFiles([ratingKey], [uri])

Add files to an existing playlist

- `ratingKey` `<string> | <number>` Identifiant
- `uri` `<string>` Path to a list of video files, ie: `server://2c59cf8256eccd8629081638e98e27bf8349c3e7/com.plexapp.plugins.library/library/metadata/26082`

#### removePlaylist([ratingKey])

Remove existing playlist

- `ratingKey` `<string> | <number>` Identifiant
84 changes: 84 additions & 0 deletions pavie.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
28 changes: 28 additions & 0 deletions test/playlists.js
Original file line number Diff line number Diff line change
@@ -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)
})
6 changes: 4 additions & 2 deletions server.js → test/signin.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit c15ddfc

Please sign in to comment.