@epic-web/workshop-utils 6.47.8 → 6.47.9
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/epic-api.server.d.ts +2 -0
- package/dist/epic-api.server.js +34 -1
- package/package.json +1 -1
|
@@ -17,6 +17,8 @@ declare function getEpicVideoInfo({ epicVideoEmbed, accessToken, request, timing
|
|
|
17
17
|
statusCode: number;
|
|
18
18
|
statusText: string;
|
|
19
19
|
title?: string | null | undefined;
|
|
20
|
+
duration?: number | null | undefined;
|
|
21
|
+
durationEstimate?: number | null | undefined;
|
|
20
22
|
} | {
|
|
21
23
|
type: "unknown";
|
|
22
24
|
status: "error";
|
package/dist/epic-api.server.js
CHANGED
|
@@ -16,11 +16,42 @@ const Transcript = z
|
|
|
16
16
|
.nullable()
|
|
17
17
|
.optional()
|
|
18
18
|
.transform((s) => s ?? 'Transcripts not available');
|
|
19
|
-
const EpicVideoInfoSchema = z
|
|
19
|
+
const EpicVideoInfoSchema = z
|
|
20
|
+
.object({
|
|
20
21
|
title: z.string().nullable().optional(),
|
|
21
22
|
transcript: Transcript,
|
|
22
23
|
muxPlaybackId: z.string(),
|
|
24
|
+
duration: z.number().nullable().optional(),
|
|
25
|
+
durationEstimate: z.number().nullable().optional(),
|
|
26
|
+
})
|
|
27
|
+
.transform((data) => {
|
|
28
|
+
if (!data.duration && data.transcript) {
|
|
29
|
+
// estimate duration from transcript. Grab the last transcript timestamp and use that
|
|
30
|
+
const timestampRegex = /(\d+:\d+)/g;
|
|
31
|
+
const lastTimestampMatch = Array.from(data.transcript.matchAll(timestampRegex)).pop();
|
|
32
|
+
if (lastTimestampMatch) {
|
|
33
|
+
const lastTimestamp = lastTimestampMatch[1];
|
|
34
|
+
if (!lastTimestamp)
|
|
35
|
+
return data;
|
|
36
|
+
const durationInSeconds = hmsToSeconds(lastTimestamp);
|
|
37
|
+
return {
|
|
38
|
+
...data,
|
|
39
|
+
durationEstimate: durationInSeconds,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return data;
|
|
23
44
|
});
|
|
45
|
+
function hmsToSeconds(str) {
|
|
46
|
+
const p = str.split(':');
|
|
47
|
+
let s = 0;
|
|
48
|
+
let m = 1;
|
|
49
|
+
while (p.length > 0) {
|
|
50
|
+
s += m * parseInt(p.pop() ?? '0', 10);
|
|
51
|
+
m *= 60;
|
|
52
|
+
}
|
|
53
|
+
return s;
|
|
54
|
+
}
|
|
24
55
|
const EpicVideoRegionRestrictedErrorSchema = z.object({
|
|
25
56
|
requestCountry: z.string(),
|
|
26
57
|
restrictedCountry: z.string(),
|
|
@@ -31,6 +62,8 @@ const CachedEpicVideoInfoSchema = z
|
|
|
31
62
|
title: z.string().nullable().optional(),
|
|
32
63
|
transcript: Transcript,
|
|
33
64
|
muxPlaybackId: z.string(),
|
|
65
|
+
duration: z.number().nullable().optional(),
|
|
66
|
+
durationEstimate: z.number().nullable().optional(),
|
|
34
67
|
status: z.literal('success'),
|
|
35
68
|
statusCode: z.number(),
|
|
36
69
|
statusText: z.string(),
|