@nuclearplayer/plugin-sdk 1.1.0 → 1.2.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/dist/index.d.ts +19 -0
- package/dist/index.js +91 -61
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -186,6 +186,23 @@ export declare type LocalFileInfo = {
|
|
|
186
186
|
scannedAtIso?: string;
|
|
187
187
|
};
|
|
188
188
|
|
|
189
|
+
export declare class LoggerAPI {
|
|
190
|
+
private host;
|
|
191
|
+
constructor(host?: LoggerHost);
|
|
192
|
+
trace(message: string): void;
|
|
193
|
+
debug(message: string): void;
|
|
194
|
+
info(message: string): void;
|
|
195
|
+
warn(message: string): void;
|
|
196
|
+
error(message: string): void;
|
|
197
|
+
log(level: LogLevel, message: string): void;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export declare type LoggerHost = {
|
|
201
|
+
log: (level: LogLevel, message: string) => void;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export declare type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
205
|
+
|
|
189
206
|
declare class MetadataAPI {
|
|
190
207
|
#private;
|
|
191
208
|
constructor(host?: MetadataHost);
|
|
@@ -235,6 +252,7 @@ export declare class NuclearAPI {
|
|
|
235
252
|
readonly Http: HttpAPI;
|
|
236
253
|
readonly Ytdlp: YtdlpAPI;
|
|
237
254
|
readonly Favorites: FavoritesAPI;
|
|
255
|
+
readonly Logger: LoggerAPI;
|
|
238
256
|
constructor(opts?: {
|
|
239
257
|
settingsHost?: SettingsHost;
|
|
240
258
|
providersHost?: ProvidersHost;
|
|
@@ -244,6 +262,7 @@ export declare class NuclearAPI {
|
|
|
244
262
|
httpHost?: HttpHost;
|
|
245
263
|
ytdlpHost?: YtdlpHost;
|
|
246
264
|
favoritesHost?: FavoritesHost;
|
|
265
|
+
loggerHost?: LoggerHost;
|
|
247
266
|
});
|
|
248
267
|
}
|
|
249
268
|
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState as l, useEffect as
|
|
1
|
+
import { useState as l, useEffect as g, useMemo as f } from "react";
|
|
2
2
|
class b {
|
|
3
3
|
#e;
|
|
4
4
|
constructor(t) {
|
|
@@ -50,25 +50,25 @@ class b {
|
|
|
50
50
|
return this.#t((e) => e.subscribe(t));
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
const m = (
|
|
54
|
-
if (
|
|
53
|
+
const m = (r) => {
|
|
54
|
+
if (r instanceof Headers) {
|
|
55
55
|
const t = {};
|
|
56
|
-
return
|
|
57
|
-
t[
|
|
56
|
+
return r.forEach((e, s) => {
|
|
57
|
+
t[s] = e;
|
|
58
58
|
}), t;
|
|
59
59
|
}
|
|
60
|
-
return Array.isArray(
|
|
60
|
+
return Array.isArray(r) ? Object.fromEntries(r) : r;
|
|
61
61
|
};
|
|
62
|
-
function A(
|
|
62
|
+
function A(r) {
|
|
63
63
|
return async (t, e) => {
|
|
64
|
-
const
|
|
64
|
+
const s = String(t instanceof Request ? t.url : t), u = e?.headers ? m(e.headers) : void 0, n = typeof e?.body == "string" ? e.body : void 0, a = await r.fetch(s, {
|
|
65
65
|
method: e?.method,
|
|
66
|
-
headers:
|
|
66
|
+
headers: u,
|
|
67
67
|
body: n
|
|
68
68
|
});
|
|
69
|
-
return new Response(
|
|
70
|
-
status:
|
|
71
|
-
headers: new Headers(
|
|
69
|
+
return new Response(a.body, {
|
|
70
|
+
status: a.status,
|
|
71
|
+
headers: new Headers(a.headers)
|
|
72
72
|
});
|
|
73
73
|
};
|
|
74
74
|
}
|
|
@@ -85,7 +85,35 @@ class w {
|
|
|
85
85
|
this.fetch = A(t ?? v);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
const T = {
|
|
89
|
+
log: () => {
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
class p {
|
|
93
|
+
host;
|
|
94
|
+
constructor(t) {
|
|
95
|
+
this.host = t ?? T;
|
|
96
|
+
}
|
|
97
|
+
trace(t) {
|
|
98
|
+
this.host.log("trace", t);
|
|
99
|
+
}
|
|
100
|
+
debug(t) {
|
|
101
|
+
this.host.log("debug", t);
|
|
102
|
+
}
|
|
103
|
+
info(t) {
|
|
104
|
+
this.host.log("info", t);
|
|
105
|
+
}
|
|
106
|
+
warn(t) {
|
|
107
|
+
this.host.log("warn", t);
|
|
108
|
+
}
|
|
109
|
+
error(t) {
|
|
110
|
+
this.host.log("error", t);
|
|
111
|
+
}
|
|
112
|
+
log(t, e) {
|
|
113
|
+
this.host.log(t, e);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
class I {
|
|
89
117
|
#e;
|
|
90
118
|
constructor(t) {
|
|
91
119
|
this.#e = t;
|
|
@@ -97,27 +125,27 @@ class T {
|
|
|
97
125
|
return t(e);
|
|
98
126
|
}
|
|
99
127
|
search(t, e) {
|
|
100
|
-
return this.#t((
|
|
128
|
+
return this.#t((s) => s.search(t, e));
|
|
101
129
|
}
|
|
102
130
|
fetchArtistDetails(t, e) {
|
|
103
|
-
return this.#t((
|
|
131
|
+
return this.#t((s) => s.fetchArtistDetails(t, e));
|
|
104
132
|
}
|
|
105
133
|
fetchArtistAlbums(t, e) {
|
|
106
|
-
return this.#t((
|
|
134
|
+
return this.#t((s) => s.fetchArtistAlbums(t, e));
|
|
107
135
|
}
|
|
108
136
|
fetchArtistTopTracks(t, e) {
|
|
109
|
-
return this.#t((
|
|
137
|
+
return this.#t((s) => s.fetchArtistTopTracks(t, e));
|
|
110
138
|
}
|
|
111
139
|
fetchArtistRelatedArtists(t, e) {
|
|
112
140
|
return this.#t(
|
|
113
|
-
(
|
|
141
|
+
(s) => s.fetchArtistRelatedArtists(t, e)
|
|
114
142
|
);
|
|
115
143
|
}
|
|
116
144
|
fetchAlbumDetails(t, e) {
|
|
117
|
-
return this.#t((
|
|
145
|
+
return this.#t((s) => s.fetchAlbumDetails(t, e));
|
|
118
146
|
}
|
|
119
147
|
}
|
|
120
|
-
class
|
|
148
|
+
class H {
|
|
121
149
|
#e;
|
|
122
150
|
constructor(t) {
|
|
123
151
|
this.#e = t;
|
|
@@ -141,7 +169,7 @@ class p {
|
|
|
141
169
|
return this.#t((e) => e.get(t));
|
|
142
170
|
}
|
|
143
171
|
}
|
|
144
|
-
class
|
|
172
|
+
class y {
|
|
145
173
|
#e;
|
|
146
174
|
constructor(t) {
|
|
147
175
|
this.#e = t;
|
|
@@ -165,7 +193,7 @@ class I {
|
|
|
165
193
|
return this.#t((e) => e.addNext(t));
|
|
166
194
|
}
|
|
167
195
|
addAt(t, e) {
|
|
168
|
-
return this.#t((
|
|
196
|
+
return this.#t((s) => s.addAt(t, e));
|
|
169
197
|
}
|
|
170
198
|
removeByIds(t) {
|
|
171
199
|
return this.#t((e) => e.removeByIds(t));
|
|
@@ -177,10 +205,10 @@ class I {
|
|
|
177
205
|
return this.#t((t) => t.clearQueue());
|
|
178
206
|
}
|
|
179
207
|
reorder(t, e) {
|
|
180
|
-
return this.#t((
|
|
208
|
+
return this.#t((s) => s.reorder(t, e));
|
|
181
209
|
}
|
|
182
210
|
updateItemState(t, e) {
|
|
183
|
-
return this.#t((
|
|
211
|
+
return this.#t((s) => s.updateItemState(t, e));
|
|
184
212
|
}
|
|
185
213
|
goToNext() {
|
|
186
214
|
return this.#t((t) => t.goToNext());
|
|
@@ -207,7 +235,7 @@ class I {
|
|
|
207
235
|
return this.#t((e) => e.subscribeToCurrentItem(t));
|
|
208
236
|
}
|
|
209
237
|
}
|
|
210
|
-
class
|
|
238
|
+
class S {
|
|
211
239
|
#e;
|
|
212
240
|
constructor(t) {
|
|
213
241
|
this.#e = t;
|
|
@@ -225,13 +253,13 @@ class H {
|
|
|
225
253
|
return this.#t((e) => e.get(t));
|
|
226
254
|
}
|
|
227
255
|
set(t, e) {
|
|
228
|
-
return this.#t((
|
|
256
|
+
return this.#t((s) => s.set(t, e));
|
|
229
257
|
}
|
|
230
258
|
subscribe(t, e) {
|
|
231
|
-
return this.#t((
|
|
259
|
+
return this.#t((s) => s.subscribe(t, e));
|
|
232
260
|
}
|
|
233
261
|
}
|
|
234
|
-
class
|
|
262
|
+
class F {
|
|
235
263
|
#e;
|
|
236
264
|
constructor(t) {
|
|
237
265
|
this.#e = t;
|
|
@@ -249,7 +277,7 @@ class y {
|
|
|
249
277
|
return this.#t((e) => e.resolveStreamForCandidate(t));
|
|
250
278
|
}
|
|
251
279
|
}
|
|
252
|
-
class
|
|
280
|
+
class P {
|
|
253
281
|
host;
|
|
254
282
|
constructor(t) {
|
|
255
283
|
this.host = t;
|
|
@@ -268,7 +296,7 @@ class S {
|
|
|
268
296
|
return this.host.getStream(t);
|
|
269
297
|
}
|
|
270
298
|
}
|
|
271
|
-
class
|
|
299
|
+
class E {
|
|
272
300
|
Settings;
|
|
273
301
|
Providers;
|
|
274
302
|
Queue;
|
|
@@ -277,47 +305,48 @@ class F {
|
|
|
277
305
|
Http;
|
|
278
306
|
Ytdlp;
|
|
279
307
|
Favorites;
|
|
308
|
+
Logger;
|
|
280
309
|
constructor(t) {
|
|
281
|
-
this.Settings = new
|
|
310
|
+
this.Settings = new S(t?.settingsHost), this.Providers = new H(t?.providersHost), this.Queue = new y(t?.queueHost), this.Streaming = new F(t?.streamingHost), this.Metadata = new I(t?.metadataHost), this.Http = new w(t?.httpHost), this.Ytdlp = new P(t?.ytdlpHost), this.Favorites = new b(t?.favoritesHost), this.Logger = new p(t?.loggerHost);
|
|
282
311
|
}
|
|
283
312
|
}
|
|
284
|
-
class
|
|
313
|
+
class C extends E {
|
|
285
314
|
}
|
|
286
|
-
class
|
|
315
|
+
class R extends Error {
|
|
287
316
|
constructor(t) {
|
|
288
317
|
super(`Missing capability: ${t}`), this.name = "MissingCapabilityError";
|
|
289
318
|
}
|
|
290
319
|
}
|
|
291
|
-
const
|
|
292
|
-
const [e,
|
|
293
|
-
|
|
294
|
-
if (!
|
|
320
|
+
const k = (r, t) => {
|
|
321
|
+
const [e, s] = l(void 0);
|
|
322
|
+
g(() => {
|
|
323
|
+
if (!r)
|
|
295
324
|
return;
|
|
296
|
-
let n = !0,
|
|
297
|
-
const i =
|
|
298
|
-
n && (
|
|
325
|
+
let n = !0, a = !1;
|
|
326
|
+
const i = r.subscribe(t, (o) => {
|
|
327
|
+
n && (a = !0, s(o));
|
|
299
328
|
});
|
|
300
|
-
return
|
|
301
|
-
n && (
|
|
329
|
+
return r.get(t).then((o) => {
|
|
330
|
+
n && (a || s(o));
|
|
302
331
|
}), () => {
|
|
303
332
|
n = !1, i && i();
|
|
304
333
|
};
|
|
305
|
-
}, [t,
|
|
306
|
-
const
|
|
334
|
+
}, [t, r]);
|
|
335
|
+
const u = f(
|
|
307
336
|
() => (n) => {
|
|
308
|
-
|
|
337
|
+
r && r.set(t, n);
|
|
309
338
|
},
|
|
310
|
-
[t,
|
|
339
|
+
[t, r]
|
|
311
340
|
);
|
|
312
|
-
return [e,
|
|
341
|
+
return [e, u];
|
|
313
342
|
};
|
|
314
|
-
function
|
|
315
|
-
if (!
|
|
343
|
+
function Q(r, t, e) {
|
|
344
|
+
if (!r?.items?.length)
|
|
316
345
|
return;
|
|
317
|
-
const
|
|
318
|
-
if (!
|
|
319
|
-
return
|
|
320
|
-
const
|
|
346
|
+
const s = r.items.filter((i) => !(i.purpose && i.purpose !== t || !i.url));
|
|
347
|
+
if (!s.length)
|
|
348
|
+
return r.items[0];
|
|
349
|
+
const u = (i) => !i.width || !i.height ? 1 : i.width / i.height, a = ((i) => {
|
|
321
350
|
switch (i) {
|
|
322
351
|
case "avatar":
|
|
323
352
|
case "thumbnail":
|
|
@@ -330,8 +359,8 @@ function R(s, t, e) {
|
|
|
330
359
|
return 1;
|
|
331
360
|
}
|
|
332
361
|
})(t);
|
|
333
|
-
return
|
|
334
|
-
const o = Math.min(i.width || 0, i.height || 0), h = Math.abs(
|
|
362
|
+
return s.map((i) => {
|
|
363
|
+
const o = Math.min(i.width || 0, i.height || 0), h = Math.abs(u(i) - a), c = Math.abs(o - e), d = o < e ? e / o : 1;
|
|
335
364
|
return {
|
|
336
365
|
artwork: i,
|
|
337
366
|
score: (d > 1.5 ? -1e3 : 0) + -h * 50 + -c * 0.1
|
|
@@ -341,10 +370,11 @@ function R(s, t, e) {
|
|
|
341
370
|
export {
|
|
342
371
|
b as FavoritesAPI,
|
|
343
372
|
w as HttpAPI,
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
373
|
+
p as LoggerAPI,
|
|
374
|
+
R as MissingCapabilityError,
|
|
375
|
+
E as NuclearAPI,
|
|
376
|
+
C as NuclearPluginAPI,
|
|
377
|
+
P as YtdlpAPI,
|
|
378
|
+
Q as pickArtwork,
|
|
379
|
+
k as useSetting
|
|
350
380
|
};
|