@forward-widget/danmu-universe 0.0.14 → 0.0.15
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/danmu-universe.js +59 -36
- package/package.json +1 -1
package/dist/danmu-universe.js
CHANGED
|
@@ -4086,6 +4086,14 @@ class HttpStatusError extends Error {
|
|
|
4086
4086
|
});
|
|
4087
4087
|
}
|
|
4088
4088
|
}
|
|
4089
|
+
class HttpSchemaError extends Error {
|
|
4090
|
+
constructor(e, t, n){
|
|
4091
|
+
super(`Failed to parse response with schema: ${prettifyError(n)}`), fetch_define_property(this, "context", void 0), fetch_define_property(this, "response", void 0), fetch_define_property(this, "error", void 0), this.context = e, this.response = t, this.error = n, this.name = "HttpSchemaError", console.error(`\u{1F6AB} HTTP Request Failed Failed to parse response with schema: ${prettifyError(n)}: ${e.method} ${e.url}`), console.error("Response:", {
|
|
4092
|
+
headers: t.headers,
|
|
4093
|
+
data: t.data
|
|
4094
|
+
});
|
|
4095
|
+
}
|
|
4096
|
+
}
|
|
4089
4097
|
class Fetch {
|
|
4090
4098
|
setCookie(e) {
|
|
4091
4099
|
this.cookie = merge_merge(this.cookie, e);
|
|
@@ -4148,10 +4156,7 @@ class Fetch {
|
|
|
4148
4156
|
if (r) return console.debug("fetch cache hit", n), Promise.resolve(r);
|
|
4149
4157
|
}
|
|
4150
4158
|
let a = o ? void 0 : n, { timeout: u, schema: l, params: c, ...d } = s, f = t;
|
|
4151
|
-
c && (f = `${t}?${url_parse.qs.stringify(c)}`), console.debug("\u2B06\uFE0F fetch",
|
|
4152
|
-
...d,
|
|
4153
|
-
params: c
|
|
4154
|
-
});
|
|
4159
|
+
c && (f = `${t}?${url_parse.qs.stringify(c)}`), console.debug("\u2B06\uFE0F fetch", f, null != a ? a : "", d);
|
|
4155
4160
|
let p = o ? Widget.http.get(f, d) : Widget.http.post(f, a, d);
|
|
4156
4161
|
return u && u > 0 ? Promise.race([
|
|
4157
4162
|
p,
|
|
@@ -4167,6 +4172,11 @@ class Fetch {
|
|
|
4167
4172
|
fetch_define_property(this, "cookie", void 0), fetch_define_property(this, "headers", void 0), fetch_define_property(this, "handleResponse", void 0), this.cookie = e, this.headers = t, this.handleResponse = (e, t, n)=>{
|
|
4168
4173
|
var r;
|
|
4169
4174
|
if ((null == n || null == (r = n.successStatus) ? void 0 : r.length) && !n.successStatus.includes(e.statusCode)) throw new HttpStatusError(e.statusCode, n.successStatus, t, e);
|
|
4175
|
+
if (null == n ? void 0 : n.schema) {
|
|
4176
|
+
let r = n.schema.safeParse(e.data);
|
|
4177
|
+
if (!r.success) throw new HttpSchemaError(t, e, r.error);
|
|
4178
|
+
e.data = r.data;
|
|
4179
|
+
}
|
|
4170
4180
|
let i = e.headers["set-cookie"] || e.headers["Set-Cookie"];
|
|
4171
4181
|
if (i) {
|
|
4172
4182
|
let e = i.split(",").reduce((e, t)=>{
|
|
@@ -4182,13 +4192,6 @@ class Fetch {
|
|
|
4182
4192
|
ttl: n.cache.ttl
|
|
4183
4193
|
});
|
|
4184
4194
|
}
|
|
4185
|
-
if (null == n ? void 0 : n.schema) {
|
|
4186
|
-
let r = n.schema.safeParse(e.data);
|
|
4187
|
-
return r.success || (console.error(t.url, "Failed to parse response with schema:", prettifyError(r.error)), console.error("Response:", e.data)), {
|
|
4188
|
-
...e,
|
|
4189
|
-
data: r.data
|
|
4190
|
-
};
|
|
4191
|
-
}
|
|
4192
4195
|
return e;
|
|
4193
4196
|
};
|
|
4194
4197
|
}
|
|
@@ -4200,7 +4203,7 @@ const BASE_URL = "https://api.imdbapi.dev", fetch = new Fetch(), episodesRequest
|
|
|
4200
4203
|
season: coerce_number().optional().default(1),
|
|
4201
4204
|
pageSize: coerce_number().optional().default(20),
|
|
4202
4205
|
pageToken: schemas_string().optional()
|
|
4203
|
-
}),
|
|
4206
|
+
}), getImdbEpisodes = async (e, t)=>{
|
|
4204
4207
|
let { season: n, pageSize: r, pageToken: i } = episodesRequestSchema.parse(null != t ? t : {});
|
|
4205
4208
|
return (await fetch.get(`${BASE_URL}/titles/${e}/episodes`, {
|
|
4206
4209
|
params: {
|
|
@@ -4209,7 +4212,14 @@ const BASE_URL = "https://api.imdbapi.dev", fetch = new Fetch(), episodesRequest
|
|
|
4209
4212
|
pageToken: i
|
|
4210
4213
|
},
|
|
4211
4214
|
cache: {
|
|
4212
|
-
cacheKey:
|
|
4215
|
+
cacheKey: [
|
|
4216
|
+
"imdb",
|
|
4217
|
+
"episodes",
|
|
4218
|
+
e,
|
|
4219
|
+
n,
|
|
4220
|
+
r,
|
|
4221
|
+
i
|
|
4222
|
+
].filter(Boolean).join(":")
|
|
4213
4223
|
},
|
|
4214
4224
|
successStatus: [
|
|
4215
4225
|
200
|
|
@@ -4224,7 +4234,20 @@ const BASE_URL = "https://api.imdbapi.dev", fetch = new Fetch(), episodesRequest
|
|
|
4224
4234
|
nextPageToken: schemas_string().optional()
|
|
4225
4235
|
})
|
|
4226
4236
|
})).data;
|
|
4227
|
-
},
|
|
4237
|
+
}, getImdbSeasons = async (e)=>(await fetch.get(`${BASE_URL}/titles/${e}/seasons`, {
|
|
4238
|
+
cache: {
|
|
4239
|
+
cacheKey: [
|
|
4240
|
+
"imdb:seasons",
|
|
4241
|
+
e
|
|
4242
|
+
].join(":")
|
|
4243
|
+
},
|
|
4244
|
+
schema: schemas_object({
|
|
4245
|
+
seasons: schemas_array(schemas_object({
|
|
4246
|
+
season: schemas_string(),
|
|
4247
|
+
episodeCount: schemas_number().optional()
|
|
4248
|
+
}))
|
|
4249
|
+
})
|
|
4250
|
+
})).data, getExternalIdsByTmdbId = async (e, t)=>{
|
|
4228
4251
|
let n = null, r = `tmdb:${e}:${t}:external_ids`, i = storage.getJson(r);
|
|
4229
4252
|
return i ? n = i : (n = await Widget.tmdb.get(`/${e}/${t}/external_ids`), storage.setJson(r, n, {
|
|
4230
4253
|
ttl: TTL_7_DAYS
|
|
@@ -4246,9 +4269,19 @@ const BASE_URL = "https://api.imdbapi.dev", fetch = new Fetch(), episodesRequest
|
|
|
4246
4269
|
count: schemas_number().optional(),
|
|
4247
4270
|
name: schemas_string().optional()
|
|
4248
4271
|
})).optional()
|
|
4249
|
-
}), getDoubanInfoByImdbId = async (e)=>{
|
|
4250
|
-
var
|
|
4251
|
-
let
|
|
4272
|
+
}), getDoubanInfoByImdbId = async (e, t)=>{
|
|
4273
|
+
var n, r, i, o, s, a;
|
|
4274
|
+
let u = e;
|
|
4275
|
+
if (t && "1" !== t.toString()) {
|
|
4276
|
+
let n = await getImdbSeasons(e);
|
|
4277
|
+
if (!n || parseInt(t.toString()) > n.seasons.length) return null;
|
|
4278
|
+
let r = await getImdbEpisodes(e, {
|
|
4279
|
+
season: t
|
|
4280
|
+
});
|
|
4281
|
+
u = null != (s = null == r || null == (o = r.episodes.find((e)=>1 === e.episodeNumber)) ? void 0 : o.id) ? s : "";
|
|
4282
|
+
}
|
|
4283
|
+
u || (u = e), console.log("Get douban info by imdb id", u);
|
|
4284
|
+
let l = await douban_fetch.post(`https://api.douban.com/v2/movie/imdb/${u}`, {
|
|
4252
4285
|
apikey: DOUBAN_API_KEY
|
|
4253
4286
|
}, {
|
|
4254
4287
|
headers: {
|
|
@@ -4256,30 +4289,20 @@ const BASE_URL = "https://api.imdbapi.dev", fetch = new Fetch(), episodesRequest
|
|
|
4256
4289
|
},
|
|
4257
4290
|
schema: doubanImdbResponseSchema,
|
|
4258
4291
|
cache: {
|
|
4259
|
-
cacheKey: `douban:imdb:${
|
|
4292
|
+
cacheKey: `douban:imdb:${u}`,
|
|
4260
4293
|
ttl: TTL_7_DAYS
|
|
4261
4294
|
}
|
|
4262
4295
|
});
|
|
4263
|
-
if (200 !==
|
|
4264
|
-
let
|
|
4265
|
-
if (!
|
|
4266
|
-
return /\d+/.test(
|
|
4267
|
-
doubanId:
|
|
4268
|
-
originResponse:
|
|
4296
|
+
if (200 !== l.statusCode) throw Error(`Failed to get Douban info: ${l.statusCode}, ${JSON.stringify(l.data)}`);
|
|
4297
|
+
let c = null == (i = l.data) || null == (r = i.id) || null == (n = r.split("/")) ? void 0 : n.pop();
|
|
4298
|
+
if (!c) throw Error(`Failed to extract Douban ID from response: ${null == (a = l.data) ? void 0 : a.id}`);
|
|
4299
|
+
return /\d+/.test(c) ? {
|
|
4300
|
+
doubanId: c,
|
|
4301
|
+
originResponse: l.data
|
|
4269
4302
|
} : null;
|
|
4270
4303
|
}, getDoubanInfoByTmdbId = async (e, t, n)=>{
|
|
4271
4304
|
let r = await getExternalIdsByTmdbId(e, t);
|
|
4272
|
-
console.log("Get external ids by tmdb id", r);
|
|
4273
|
-
let i = r.imdb_id;
|
|
4274
|
-
if (!i) return null;
|
|
4275
|
-
if (n && 1 !== n) {
|
|
4276
|
-
var o, s;
|
|
4277
|
-
let e = await getEpisodesByImdbId(i, {
|
|
4278
|
-
season: n
|
|
4279
|
-
});
|
|
4280
|
-
i = null != (s = null == e || null == (o = e.episodes.find((e)=>1 === e.episodeNumber)) ? void 0 : o.id) ? s : "";
|
|
4281
|
-
}
|
|
4282
|
-
return i ? getDoubanInfoByImdbId(i) : null;
|
|
4305
|
+
return (console.log("Get external ids by tmdb id", r), r.imdb_id) ? getDoubanInfoByImdbId(r.imdb_id, n) : null;
|
|
4283
4306
|
}, doubanInfoResponseSchema = schemas_object({
|
|
4284
4307
|
is_tv: schemas_boolean().optional(),
|
|
4285
4308
|
vendors: schemas_array(schemas_object({
|
|
@@ -6163,7 +6186,7 @@ class scrapers_Scraper {
|
|
|
6163
6186
|
});
|
|
6164
6187
|
}
|
|
6165
6188
|
}
|
|
6166
|
-
const widgetVersion = "0.0.
|
|
6189
|
+
const widgetVersion = "0.0.15";
|
|
6167
6190
|
WidgetMetadata = {
|
|
6168
6191
|
id: "baranwang.danmu.universe",
|
|
6169
6192
|
title: "\u901A\u7528\u5F39\u5E55",
|