@ctrl/plex 3.9.2 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/dist/src/alert.js +3 -1
- package/dist/src/audio.d.ts +2 -2
- package/dist/src/audio.js +11 -10
- package/dist/src/base/partialPlexObject.d.ts +1 -1
- package/dist/src/base/partialPlexObject.js +22 -25
- package/dist/src/base/plexObject.js +10 -2
- package/dist/src/client.d.ts +1 -1
- package/dist/src/client.js +11 -10
- package/dist/src/exceptions.js +5 -5
- package/dist/src/index.d.ts +1 -0
- package/dist/src/library.d.ts +5 -5
- package/dist/src/library.js +41 -52
- package/dist/src/media.js +83 -92
- package/dist/src/myplex.js +26 -18
- package/dist/src/playlist.d.ts +25 -2
- package/dist/src/playlist.js +43 -9
- package/dist/src/playqueue.js +4 -7
- package/dist/src/search.js +2 -2
- package/dist/src/search.types.d.ts +3 -3
- package/dist/src/server.d.ts +2 -2
- package/dist/src/server.js +14 -4
- package/dist/src/server.types.d.ts +5 -2
- package/dist/src/settings.js +5 -14
- package/dist/src/video.js +17 -35
- package/package.json +16 -16
package/dist/src/media.js
CHANGED
|
@@ -5,6 +5,7 @@ import { PlexObject } from './base/plexObject.js';
|
|
|
5
5
|
* the construct used for things such as Country, Director, Genre, etc.
|
|
6
6
|
*/
|
|
7
7
|
class MediaTag extends PlexObject {
|
|
8
|
+
static TAG;
|
|
8
9
|
// async items(): Promise<any[]> {
|
|
9
10
|
// if (!this.key) {
|
|
10
11
|
// throw new Error(`Key is not defined for this tag: ${this.tag}`);
|
|
@@ -19,7 +20,7 @@ class MediaTag extends PlexObject {
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
export class Media extends PlexObject {
|
|
22
|
-
static
|
|
23
|
+
static TAG = 'Media';
|
|
23
24
|
_loadData(data) {
|
|
24
25
|
this.aspectRatio = data.aspectRatio;
|
|
25
26
|
this.audioChannels = data.audioChannels;
|
|
@@ -39,7 +40,7 @@ export class Media extends PlexObject {
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
export class MediaPart extends PlexObject {
|
|
42
|
-
static
|
|
43
|
+
static TAG = 'Part';
|
|
43
44
|
/**
|
|
44
45
|
* Set the selected {@link AudioStream} for this MediaPart.
|
|
45
46
|
* @param stream Audio stream or stream ID to set as selected.
|
|
@@ -97,7 +98,7 @@ export class MediaPart extends PlexObject {
|
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
export class MediaPartStream extends PlexObject {
|
|
100
|
-
static
|
|
101
|
+
static TAG = 'Stream';
|
|
101
102
|
_loadData(data) {
|
|
102
103
|
this.id = data.id;
|
|
103
104
|
this.codec = data.codec;
|
|
@@ -112,8 +113,8 @@ export class MediaPartStream extends PlexObject {
|
|
|
112
113
|
* Represents a single Subtitle stream within a {@link MediaPart}.
|
|
113
114
|
*/
|
|
114
115
|
export class SubtitleStream extends MediaPartStream {
|
|
115
|
-
static
|
|
116
|
-
static
|
|
116
|
+
static TAG = 'Stream';
|
|
117
|
+
static STREAMTYPE = 3;
|
|
117
118
|
/**
|
|
118
119
|
* Sets this subtitle stream as the selected subtitle stream.
|
|
119
120
|
* Alias for `MediaPart.setSelectedSubtitleStream`.
|
|
@@ -145,8 +146,8 @@ export class SubtitleStream extends MediaPartStream {
|
|
|
145
146
|
* Represents a single Lyric stream within a {@link MediaPart}.
|
|
146
147
|
*/
|
|
147
148
|
export class LyricStream extends MediaPartStream {
|
|
148
|
-
static
|
|
149
|
-
static
|
|
149
|
+
static TAG = 'Stream';
|
|
150
|
+
static STREAMTYPE = 4;
|
|
150
151
|
_loadData(data) {
|
|
151
152
|
super._loadData(data);
|
|
152
153
|
this.format = data.format;
|
|
@@ -159,72 +160,48 @@ export class LyricStream extends MediaPartStream {
|
|
|
159
160
|
* Represents a single Role (actor/actress) media tag.
|
|
160
161
|
*/
|
|
161
162
|
export class Role extends MediaTag {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this.FILTER = 'role';
|
|
165
|
-
}
|
|
166
|
-
static { this.TAG = 'Role'; }
|
|
163
|
+
static TAG = 'Role';
|
|
164
|
+
FILTER = 'role';
|
|
167
165
|
}
|
|
168
166
|
/**
|
|
169
167
|
* Represents a single Genre media tag.
|
|
170
168
|
*/
|
|
171
169
|
export class Genre extends MediaTag {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
this.FILTER = 'genre';
|
|
175
|
-
}
|
|
176
|
-
static { this.TAG = 'Genre'; }
|
|
170
|
+
static TAG = 'Genre';
|
|
171
|
+
FILTER = 'genre';
|
|
177
172
|
}
|
|
178
173
|
/**
|
|
179
174
|
* Represents a single Country media tag.
|
|
180
175
|
*/
|
|
181
176
|
export class Country extends MediaTag {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
this.FILTER = 'country';
|
|
185
|
-
}
|
|
186
|
-
static { this.TAG = 'Country'; }
|
|
177
|
+
static TAG = 'Country';
|
|
178
|
+
FILTER = 'country';
|
|
187
179
|
}
|
|
188
180
|
/**
|
|
189
181
|
* Represents a single Writer media tag.
|
|
190
182
|
*/
|
|
191
183
|
export class Writer extends MediaTag {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
this.FILTER = 'writer';
|
|
195
|
-
}
|
|
196
|
-
static { this.TAG = 'Writer'; }
|
|
184
|
+
static TAG = 'Writer';
|
|
185
|
+
FILTER = 'writer';
|
|
197
186
|
}
|
|
198
187
|
/**
|
|
199
188
|
* Represents a single Director media tag.
|
|
200
189
|
*/
|
|
201
190
|
export class Director extends MediaTag {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
this.FILTER = 'director';
|
|
205
|
-
}
|
|
206
|
-
static { this.TAG = 'Director'; }
|
|
191
|
+
static TAG = 'Director';
|
|
192
|
+
FILTER = 'director';
|
|
207
193
|
}
|
|
208
194
|
export class Similar extends MediaTag {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
this.FILTER = 'similar';
|
|
212
|
-
}
|
|
213
|
-
static { this.TAG = 'Similar'; }
|
|
195
|
+
static TAG = 'Similar';
|
|
196
|
+
FILTER = 'similar';
|
|
214
197
|
}
|
|
215
198
|
export class Producer extends MediaTag {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
this.FILTER = 'producer';
|
|
219
|
-
}
|
|
220
|
-
static { this.TAG = 'Producer'; }
|
|
199
|
+
static TAG = 'Producer';
|
|
200
|
+
FILTER = 'producer';
|
|
221
201
|
}
|
|
222
202
|
export class Marker extends MediaTag {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
this.FILTER = 'marker';
|
|
226
|
-
}
|
|
227
|
-
static { this.TAG = 'Marker'; }
|
|
203
|
+
static TAG = 'Marker';
|
|
204
|
+
FILTER = 'marker';
|
|
228
205
|
_loadData(data) {
|
|
229
206
|
this.type = data.type;
|
|
230
207
|
this.startTimeOffset = data.startTimeOffset;
|
|
@@ -235,11 +212,8 @@ export class Marker extends MediaTag {
|
|
|
235
212
|
* Represents a single Chapter media tag.
|
|
236
213
|
*/
|
|
237
214
|
export class Chapter extends MediaTag {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
this.FILTER = 'chapter';
|
|
241
|
-
}
|
|
242
|
-
static { this.TAG = 'Chapter'; }
|
|
215
|
+
static TAG = 'Chapter';
|
|
216
|
+
FILTER = 'chapter';
|
|
243
217
|
_loadData(data) {
|
|
244
218
|
this.startTimeOffset = data.startTimeOffset;
|
|
245
219
|
this.endTimeOffset = data.endTimeOffset;
|
|
@@ -250,46 +224,31 @@ export class Chapter extends MediaTag {
|
|
|
250
224
|
* Represents a single Collection media tag.
|
|
251
225
|
*/
|
|
252
226
|
export class Collection extends MediaTag {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
this.FILTER = 'collection';
|
|
256
|
-
}
|
|
257
|
-
static { this.TAG = 'Collection'; }
|
|
227
|
+
static TAG = 'Collection';
|
|
228
|
+
FILTER = 'collection';
|
|
258
229
|
}
|
|
259
230
|
/** Represents a single Label media tag. */
|
|
260
231
|
export class Label extends MediaTag {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this.FILTER = 'label';
|
|
264
|
-
}
|
|
265
|
-
static { this.TAG = 'Label'; }
|
|
232
|
+
static TAG = 'Label';
|
|
233
|
+
FILTER = 'label';
|
|
266
234
|
}
|
|
267
235
|
/** Represents a single Style media tag. */
|
|
268
236
|
export class Style extends MediaTag {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
this.FILTER = 'style';
|
|
272
|
-
}
|
|
273
|
-
static { this.TAG = 'Style'; }
|
|
237
|
+
static TAG = 'Style';
|
|
238
|
+
FILTER = 'style';
|
|
274
239
|
}
|
|
275
240
|
/** Represents a single Format media tag. */
|
|
276
241
|
export class Format extends MediaTag {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
this.FILTER = 'format';
|
|
280
|
-
}
|
|
281
|
-
static { this.TAG = 'Format'; }
|
|
242
|
+
static TAG = 'Format';
|
|
243
|
+
FILTER = 'format';
|
|
282
244
|
}
|
|
283
245
|
/** Represents a single Subformat media tag. */
|
|
284
246
|
export class Subformat extends MediaTag {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
this.FILTER = 'subformat';
|
|
288
|
-
}
|
|
289
|
-
static { this.TAG = 'Subformat'; }
|
|
247
|
+
static TAG = 'Subformat';
|
|
248
|
+
FILTER = 'subformat';
|
|
290
249
|
}
|
|
291
250
|
export class Optimized extends PlexObject {
|
|
292
|
-
static
|
|
251
|
+
static TAG = 'Item';
|
|
293
252
|
// TODO: Implement items()
|
|
294
253
|
/**
|
|
295
254
|
* Remove this Optimized item.
|
|
@@ -332,13 +291,13 @@ class GuidTag extends PlexObject {
|
|
|
332
291
|
}
|
|
333
292
|
}
|
|
334
293
|
export class Guid extends GuidTag {
|
|
335
|
-
static
|
|
294
|
+
static TAG = 'Guid';
|
|
336
295
|
}
|
|
337
296
|
/**
|
|
338
297
|
* Represents a single Rating media tag.
|
|
339
298
|
*/
|
|
340
299
|
export class Rating extends PlexObject {
|
|
341
|
-
static
|
|
300
|
+
static TAG = 'Rating';
|
|
342
301
|
_loadData(data) {
|
|
343
302
|
this.image = data.image;
|
|
344
303
|
this.type = data.type;
|
|
@@ -380,26 +339,61 @@ class BaseResource extends PlexObject {
|
|
|
380
339
|
* Represents a single Art object.
|
|
381
340
|
*/
|
|
382
341
|
export class Art extends BaseResource {
|
|
383
|
-
static
|
|
342
|
+
static TAG = 'Art';
|
|
384
343
|
}
|
|
385
344
|
/**
|
|
386
345
|
* Represents a single Poster object.
|
|
387
346
|
*/
|
|
388
347
|
export class Poster extends BaseResource {
|
|
389
|
-
static
|
|
348
|
+
static TAG = 'Photo';
|
|
390
349
|
}
|
|
391
350
|
/**
|
|
392
351
|
* Represents a single Theme object.
|
|
393
352
|
*/
|
|
394
353
|
export class Theme extends BaseResource {
|
|
395
|
-
static
|
|
354
|
+
static TAG = 'Theme';
|
|
396
355
|
}
|
|
397
356
|
/**
|
|
398
357
|
* Represents a single Audio stream within a {@link MediaPart}.
|
|
399
358
|
*/
|
|
400
359
|
export class AudioStream extends MediaPartStream {
|
|
401
|
-
static
|
|
402
|
-
static
|
|
360
|
+
static TAG = 'Stream';
|
|
361
|
+
static STREAMTYPE = 2;
|
|
362
|
+
/** The audio channel layout of the audio stream (ex: 5.1(side)). */
|
|
363
|
+
audioChannelLayout;
|
|
364
|
+
/** The bit depth of the audio stream (ex: 16). */
|
|
365
|
+
bitDepth;
|
|
366
|
+
/** The bitrate mode of the audio stream (ex: cbr). */
|
|
367
|
+
bitrateMode;
|
|
368
|
+
/** The number of audio channels of the audio stream (ex: 6). */
|
|
369
|
+
channels;
|
|
370
|
+
/** The duration of audio stream in milliseconds. */
|
|
371
|
+
duration;
|
|
372
|
+
/** The profile of the audio stream. */
|
|
373
|
+
profile;
|
|
374
|
+
/** The sampling rate of the audio stream (ex: 48000) */
|
|
375
|
+
samplingRate;
|
|
376
|
+
/** The stream identifier of the audio stream. */
|
|
377
|
+
streamIdentifier;
|
|
378
|
+
// Track only attributes
|
|
379
|
+
/** The gain for the album. */
|
|
380
|
+
albumGain;
|
|
381
|
+
/** The peak for the album. */
|
|
382
|
+
albumPeak;
|
|
383
|
+
/** The range for the album. */
|
|
384
|
+
albumRange;
|
|
385
|
+
/** The end ramp for the track. */
|
|
386
|
+
endRamp;
|
|
387
|
+
/** The gain for the track. */
|
|
388
|
+
gain;
|
|
389
|
+
/** The loudness for the track. */
|
|
390
|
+
loudness;
|
|
391
|
+
/** The lra for the track. */
|
|
392
|
+
lra;
|
|
393
|
+
/** The peak for the track. */
|
|
394
|
+
peak;
|
|
395
|
+
/** The start ramp for the track. */
|
|
396
|
+
startRamp;
|
|
403
397
|
/**
|
|
404
398
|
* Sets this audio stream as the selected audio stream.
|
|
405
399
|
* Alias for {@link MediaPart.setSelectedAudioStream}.
|
|
@@ -436,7 +430,7 @@ export class AudioStream extends MediaPartStream {
|
|
|
436
430
|
}
|
|
437
431
|
/** Represents a single Image media tag. */
|
|
438
432
|
export class Image extends PlexObject {
|
|
439
|
-
static
|
|
433
|
+
static TAG = 'Image';
|
|
440
434
|
_loadData(data) {
|
|
441
435
|
this.alt = data.alt;
|
|
442
436
|
this.type = data.type;
|
|
@@ -446,7 +440,7 @@ export class Image extends PlexObject {
|
|
|
446
440
|
}
|
|
447
441
|
/** Represents a single Field. */
|
|
448
442
|
export class Field extends PlexObject {
|
|
449
|
-
static
|
|
443
|
+
static TAG = 'Field';
|
|
450
444
|
_loadData(data) {
|
|
451
445
|
// Convert potential string '1' or '0' to boolean
|
|
452
446
|
this.locked = data.locked === '1' || data.locked === true;
|
|
@@ -455,9 +449,6 @@ export class Field extends PlexObject {
|
|
|
455
449
|
}
|
|
456
450
|
/** Represents a single Mood media tag. */
|
|
457
451
|
export class Mood extends MediaTag {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
this.FILTER = 'mood';
|
|
461
|
-
}
|
|
462
|
-
static { this.TAG = 'Mood'; }
|
|
452
|
+
static TAG = 'Mood';
|
|
453
|
+
FILTER = 'mood';
|
|
463
454
|
}
|
package/dist/src/myplex.js
CHANGED
|
@@ -13,7 +13,13 @@ import { PlexServer } from './server.js';
|
|
|
13
13
|
* and return this object.
|
|
14
14
|
*/
|
|
15
15
|
export class MyPlexAccount {
|
|
16
|
-
|
|
16
|
+
baseUrl;
|
|
17
|
+
username;
|
|
18
|
+
password;
|
|
19
|
+
token;
|
|
20
|
+
timeout;
|
|
21
|
+
server;
|
|
22
|
+
static key = 'https://plex.tv/api/v2/user';
|
|
17
23
|
/**
|
|
18
24
|
* This follows the outline described in https://forums.plex.tv/t/authenticating-with-plex/609370
|
|
19
25
|
* to fetch a token and potentially compromise username and password. To use first call `getWebLogin()`
|
|
@@ -79,6 +85,18 @@ export class MyPlexAccount {
|
|
|
79
85
|
}
|
|
80
86
|
throw new Error('Failed to authenticate before timeout');
|
|
81
87
|
}
|
|
88
|
+
FRIENDINVITE = 'https://plex.tv/api/servers/{machineId}/shared_servers'; // post with data
|
|
89
|
+
HOMEUSERCREATE = 'https://plex.tv/api/home/users?title={title}'; // post with data
|
|
90
|
+
EXISTINGUSER = 'https://plex.tv/api/home/users?invitedEmail={username}'; // post with data
|
|
91
|
+
FRIENDSERVERS = 'https://plex.tv/api/servers/{machineId}/shared_servers/{serverId}'; // put with data
|
|
92
|
+
PLEXSERVERS = 'https://plex.tv/api/servers/{machineId}'; // get
|
|
93
|
+
FRIENDUPDATE = 'https://plex.tv/api/friends/{userId}'; // put with args, delete
|
|
94
|
+
REMOVEHOMEUSER = 'https://plex.tv/api/home/users/{userId}'; // delete
|
|
95
|
+
REMOVEINVITE = 'https://plex.tv/api/invites/requested/{userId}?friend=0&server=1&home=0'; // delete
|
|
96
|
+
REQUESTED = 'https://plex.tv/api/invites/requested'; // get
|
|
97
|
+
REQUESTS = 'https://plex.tv/api/invites/requests'; // get
|
|
98
|
+
SIGNIN = 'https://plex.tv/users/sign_in.json'; // get with auth
|
|
99
|
+
WEBHOOKS = 'https://plex.tv/api/v2/user/webhooks'; // get, post with data
|
|
82
100
|
/**
|
|
83
101
|
*
|
|
84
102
|
* @param username Your MyPlex username
|
|
@@ -95,18 +113,6 @@ export class MyPlexAccount {
|
|
|
95
113
|
this.token = token;
|
|
96
114
|
this.timeout = timeout;
|
|
97
115
|
this.server = server;
|
|
98
|
-
this.FRIENDINVITE = 'https://plex.tv/api/servers/{machineId}/shared_servers'; // post with data
|
|
99
|
-
this.HOMEUSERCREATE = 'https://plex.tv/api/home/users?title={title}'; // post with data
|
|
100
|
-
this.EXISTINGUSER = 'https://plex.tv/api/home/users?invitedEmail={username}'; // post with data
|
|
101
|
-
this.FRIENDSERVERS = 'https://plex.tv/api/servers/{machineId}/shared_servers/{serverId}'; // put with data
|
|
102
|
-
this.PLEXSERVERS = 'https://plex.tv/api/servers/{machineId}'; // get
|
|
103
|
-
this.FRIENDUPDATE = 'https://plex.tv/api/friends/{userId}'; // put with args, delete
|
|
104
|
-
this.REMOVEHOMEUSER = 'https://plex.tv/api/home/users/{userId}'; // delete
|
|
105
|
-
this.REMOVEINVITE = 'https://plex.tv/api/invites/requested/{userId}?friend=0&server=1&home=0'; // delete
|
|
106
|
-
this.REQUESTED = 'https://plex.tv/api/invites/requested'; // get
|
|
107
|
-
this.REQUESTS = 'https://plex.tv/api/invites/requests'; // get
|
|
108
|
-
this.SIGNIN = 'https://plex.tv/users/sign_in.json'; // get with auth
|
|
109
|
-
this.WEBHOOKS = 'https://plex.tv/api/v2/user/webhooks'; // get, post with data
|
|
110
116
|
if (this.token) {
|
|
111
117
|
Object.defineProperty(this, 'token', {
|
|
112
118
|
enumerable: false,
|
|
@@ -292,11 +298,13 @@ async function connect(cls, url, token, timeout) {
|
|
|
292
298
|
* content such as Plex Media Servers, iPhone or Android clients, etc.
|
|
293
299
|
*/
|
|
294
300
|
export class MyPlexResource {
|
|
295
|
-
|
|
301
|
+
account;
|
|
302
|
+
baseUrl;
|
|
303
|
+
static key = 'https://plex.tv/api/v2/resources?includeHttps=1&includeRelay=1';
|
|
304
|
+
TAG = 'Device';
|
|
296
305
|
constructor(account, data, baseUrl = null) {
|
|
297
306
|
this.account = account;
|
|
298
307
|
this.baseUrl = baseUrl;
|
|
299
|
-
this.TAG = 'Device';
|
|
300
308
|
this._loadData(data);
|
|
301
309
|
}
|
|
302
310
|
async connect(ssl = null, timeout) {
|
|
@@ -354,8 +362,8 @@ export class MyPlexResource {
|
|
|
354
362
|
}
|
|
355
363
|
}
|
|
356
364
|
export class ResourceConnection {
|
|
365
|
+
TAG = 'Connection';
|
|
357
366
|
constructor(data) {
|
|
358
|
-
this.TAG = 'Connection';
|
|
359
367
|
this._loadData(data);
|
|
360
368
|
}
|
|
361
369
|
_loadData(data) {
|
|
@@ -374,8 +382,8 @@ export class ResourceConnection {
|
|
|
374
382
|
* https://plex.tv/devices.xml
|
|
375
383
|
*/
|
|
376
384
|
export class MyPlexDevice extends PlexObject {
|
|
377
|
-
static
|
|
378
|
-
static
|
|
385
|
+
static TAG = 'Device';
|
|
386
|
+
static key = 'https://plex.tv/devices.xml';
|
|
379
387
|
async connect() {
|
|
380
388
|
// TODO: switch between PlexServer and PlexClient
|
|
381
389
|
// Try connecting to all known resource connections in parellel, but
|
package/dist/src/playlist.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Playable } from './base/playable.js';
|
|
2
|
+
import { Album, Artist, Track } from './audio.js';
|
|
2
3
|
import type { Section, SectionType } from './library.js';
|
|
3
4
|
import type { PlaylistResponse } from './playlist.types.js';
|
|
4
5
|
import type { PlexServer } from './server.js';
|
|
@@ -29,10 +30,32 @@ interface CreateSmartPlaylistOptions {
|
|
|
29
30
|
filters?: Record<string, any>;
|
|
30
31
|
}
|
|
31
32
|
type CreatePlaylistOptions = CreateRegularPlaylistOptions | CreateSmartPlaylistOptions;
|
|
32
|
-
type PlaylistContent = Episode | Movie;
|
|
33
|
+
type PlaylistContent = Episode | Movie | Track | Album | Artist;
|
|
34
|
+
export interface UpdatePlaylistOptions {
|
|
35
|
+
/** New title for the playlist */
|
|
36
|
+
title?: string;
|
|
37
|
+
/** New summary/description for the playlist */
|
|
38
|
+
summary?: string;
|
|
39
|
+
}
|
|
33
40
|
export declare class Playlist extends Playable {
|
|
34
41
|
static TAG: string;
|
|
35
42
|
static create(server: PlexServer, title: string, options: CreatePlaylistOptions): Promise<Playlist>;
|
|
43
|
+
/**
|
|
44
|
+
* Update a playlist's metadata by ratingKey without fetching the full playlist first.
|
|
45
|
+
*
|
|
46
|
+
* @param server - The Plex server instance
|
|
47
|
+
* @param ratingKey - The playlist's ratingKey
|
|
48
|
+
* @param options - Fields to update (title and/or summary)
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* await Playlist.update(server, '12345', {
|
|
53
|
+
* title: 'My Updated Playlist',
|
|
54
|
+
* summary: 'A new description'
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
static update(server: PlexServer, ratingKey: string, options: UpdatePlaylistOptions): Promise<void>;
|
|
36
59
|
/** Create a smart playlist. */
|
|
37
60
|
private static _create;
|
|
38
61
|
TYPE: string;
|
|
@@ -61,7 +84,7 @@ export declare class Playlist extends Playable {
|
|
|
61
84
|
* @returns the item in the playlist that matches the specified title.
|
|
62
85
|
*/
|
|
63
86
|
item(title: string): Promise<PlaylistContent | null>;
|
|
64
|
-
items(): Promise<
|
|
87
|
+
items<T extends PlaylistContent>(): Promise<T[]>;
|
|
65
88
|
/** Add items to a playlist. */
|
|
66
89
|
addItems(items: PlaylistContent[]): Promise<void>;
|
|
67
90
|
/** Remove an item from a playlist. */
|
package/dist/src/playlist.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { URLSearchParams } from 'url';
|
|
2
2
|
import { Playable } from './base/playable.js';
|
|
3
|
+
import { Album, Artist, Track } from './audio.js';
|
|
3
4
|
import { fetchItems } from './baseFunctionality.js';
|
|
4
5
|
import { BadRequest, NotFound } from './exceptions.js';
|
|
5
6
|
import { Episode, Movie } from './video.js';
|
|
@@ -12,18 +13,18 @@ function contentClass(data) {
|
|
|
12
13
|
return Episode;
|
|
13
14
|
case 'movie':
|
|
14
15
|
return Movie;
|
|
16
|
+
case 'track':
|
|
17
|
+
return Track;
|
|
18
|
+
case 'album':
|
|
19
|
+
return Album;
|
|
20
|
+
case 'artist':
|
|
21
|
+
return Artist;
|
|
15
22
|
default:
|
|
16
|
-
throw new Error(
|
|
23
|
+
throw new Error(`Media type '${data.type}' not implemented`);
|
|
17
24
|
}
|
|
18
25
|
}
|
|
19
26
|
export class Playlist extends Playable {
|
|
20
|
-
|
|
21
|
-
super(...arguments);
|
|
22
|
-
this.TYPE = 'playlist';
|
|
23
|
-
/** Cache of playlist items */
|
|
24
|
-
this._items = null;
|
|
25
|
-
}
|
|
26
|
-
static { this.TAG = 'Playlist'; }
|
|
27
|
+
static TAG = 'Playlist';
|
|
27
28
|
static async create(server, title, options) {
|
|
28
29
|
if (options.smart) {
|
|
29
30
|
throw new Error('not yet supported');
|
|
@@ -31,6 +32,35 @@ export class Playlist extends Playable {
|
|
|
31
32
|
}
|
|
32
33
|
return this._create(server, title, options.items);
|
|
33
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Update a playlist's metadata by ratingKey without fetching the full playlist first.
|
|
37
|
+
*
|
|
38
|
+
* @param server - The Plex server instance
|
|
39
|
+
* @param ratingKey - The playlist's ratingKey
|
|
40
|
+
* @param options - Fields to update (title and/or summary)
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* await Playlist.update(server, '12345', {
|
|
45
|
+
* title: 'My Updated Playlist',
|
|
46
|
+
* summary: 'A new description'
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
static async update(server, ratingKey, options) {
|
|
51
|
+
if (!options.title && !options.summary) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const params = new URLSearchParams();
|
|
55
|
+
if (options.title) {
|
|
56
|
+
params.set('title', options.title);
|
|
57
|
+
}
|
|
58
|
+
if (options.summary) {
|
|
59
|
+
params.set('summary', options.summary);
|
|
60
|
+
}
|
|
61
|
+
const key = `/playlists/${ratingKey}?${params.toString()}`;
|
|
62
|
+
await server.query(key, 'put');
|
|
63
|
+
}
|
|
34
64
|
/** Create a smart playlist. */
|
|
35
65
|
// private static _createSmart(server: PlexServer, title: string, options: CreatePlaylistOptions) {}
|
|
36
66
|
static async _create(server, title, items) {
|
|
@@ -50,6 +80,9 @@ export class Playlist extends Playable {
|
|
|
50
80
|
const data = await server.query(key, 'post');
|
|
51
81
|
return new Playlist(server, data.MediaContainer.Metadata[0], key);
|
|
52
82
|
}
|
|
83
|
+
TYPE = 'playlist';
|
|
84
|
+
/** Cache of playlist items */
|
|
85
|
+
_items = null;
|
|
53
86
|
async _edit(args) {
|
|
54
87
|
const searchparams = new URLSearchParams(args);
|
|
55
88
|
const key = `${this.key}?${searchparams.toString()}`;
|
|
@@ -63,7 +96,7 @@ export class Playlist extends Playable {
|
|
|
63
96
|
*/
|
|
64
97
|
async item(title) {
|
|
65
98
|
const items = await this.items();
|
|
66
|
-
const matched = items.find(item => item.title
|
|
99
|
+
const matched = items.find(item => item.title?.toLowerCase() === title.toLowerCase());
|
|
67
100
|
return matched ?? null;
|
|
68
101
|
}
|
|
69
102
|
async items() {
|
|
@@ -135,6 +168,7 @@ export class Playlist extends Playable {
|
|
|
135
168
|
if (!playlistItem) {
|
|
136
169
|
throw new NotFound(`Item with title "${item.title}" not found in the playlist`);
|
|
137
170
|
}
|
|
171
|
+
// playlistItemID is added dynamically by Plex API for playlist items
|
|
138
172
|
return playlistItem.playlistItemID;
|
|
139
173
|
}
|
|
140
174
|
}
|
package/dist/src/playqueue.js
CHANGED
|
@@ -9,13 +9,10 @@ import { BadRequest } from './exceptions.js';
|
|
|
9
9
|
* removing, and reordering items.
|
|
10
10
|
*/
|
|
11
11
|
export class PlayQueue extends PlexObject {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
static { this.TAG = 'PlayQueue'; }
|
|
18
|
-
static { this.TYPE = 'playqueue'; }
|
|
12
|
+
static TAG = 'PlayQueue';
|
|
13
|
+
static TYPE = 'playqueue';
|
|
14
|
+
/** Cache of PlayQueue items */
|
|
15
|
+
_items = null;
|
|
19
16
|
/**
|
|
20
17
|
* Retrieve an existing PlayQueue by identifier.
|
|
21
18
|
*/
|
package/dist/src/search.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PlexObject } from './base/plexObject.js';
|
|
2
2
|
import { rsplit } from './util.js';
|
|
3
3
|
export class SearchResult extends PlexObject {
|
|
4
|
-
static
|
|
4
|
+
static TAG = 'SearchResult';
|
|
5
5
|
_loadData(data) {
|
|
6
6
|
this.guid = data.guid;
|
|
7
7
|
this.lifespanEnded = data.lifespanEnded;
|
|
@@ -14,7 +14,7 @@ export class SearchResult extends PlexObject {
|
|
|
14
14
|
* Represents a single Agent
|
|
15
15
|
*/
|
|
16
16
|
export class Agent extends PlexObject {
|
|
17
|
-
static
|
|
17
|
+
static TAG = 'Agent';
|
|
18
18
|
// languageCode: any[] = [];
|
|
19
19
|
_loadData(data) {
|
|
20
20
|
this.hasAttribution = data.hasAttribution;
|
|
@@ -6,7 +6,7 @@ export interface MatchSearchResult {
|
|
|
6
6
|
year: number;
|
|
7
7
|
lifespanEnded: boolean;
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
9
|
+
export interface SearchResultContainer {
|
|
10
10
|
title: string;
|
|
11
11
|
type: string;
|
|
12
12
|
hubIdentifier: string;
|
|
@@ -15,7 +15,7 @@ export interface SearchResult {
|
|
|
15
15
|
more: boolean;
|
|
16
16
|
style: string;
|
|
17
17
|
Directory?: Directory[];
|
|
18
|
-
Metadata?:
|
|
18
|
+
Metadata?: SearchResult[];
|
|
19
19
|
}
|
|
20
20
|
export interface Directory {
|
|
21
21
|
key: string;
|
|
@@ -34,7 +34,7 @@ export interface Directory {
|
|
|
34
34
|
count: number;
|
|
35
35
|
thumb?: string;
|
|
36
36
|
}
|
|
37
|
-
interface
|
|
37
|
+
interface SearchResult {
|
|
38
38
|
librarySectionTitle: string;
|
|
39
39
|
ratingKey: string;
|
|
40
40
|
key: string;
|
package/dist/src/server.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { Playlist } from './playlist.js';
|
|
|
8
8
|
import { PlayQueue } from './playqueue.js';
|
|
9
9
|
import type { CreatePlayQueueOptions } from './playqueue.types.js';
|
|
10
10
|
import { Agent, SEARCHTYPES } from './search.js';
|
|
11
|
-
import type {
|
|
11
|
+
import type { HistoryResult } from './server.types.js';
|
|
12
12
|
import { Settings } from './settings.js';
|
|
13
13
|
/**
|
|
14
14
|
* This is the main entry point to interacting with a Plex server. It allows you to
|
|
@@ -190,7 +190,7 @@ export declare class PlexServer {
|
|
|
190
190
|
* @param accountId request history for a specific account ID.
|
|
191
191
|
* @param librarySectionId request history for a specific library section ID.
|
|
192
192
|
*/
|
|
193
|
-
history(maxresults?: number, mindate?: Date, ratingKey?: number | string, accountId?: number | string, librarySectionId?: number | string): Promise<
|
|
193
|
+
history(maxresults?: number, mindate?: Date, ratingKey?: number | string, accountId?: number | string, librarySectionId?: number | string): Promise<HistoryResult[]>;
|
|
194
194
|
settings(): Promise<Settings>;
|
|
195
195
|
/**
|
|
196
196
|
* Creates and returns a new PlayQueue.
|