nixamp 0.24.1 → 0.25.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 +47 -2
- package/dist/captions.d.ts +12 -0
- package/dist/captions.js +29 -2
- package/dist/hash.d.ts +12 -0
- package/dist/hash.js +139 -0
- package/dist/main.js +27 -3
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.js +49 -1
- package/dist/media-index.d.ts +67 -0
- package/dist/media-index.js +114 -0
- package/dist/media-local.d.ts +43 -0
- package/dist/media-local.js +88 -0
- package/dist/media-page.d.ts +18 -0
- package/dist/media-page.js +146 -0
- package/dist/media.d.ts +145 -0
- package/dist/media.js +364 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +200 -35
- package/dist/transcribe.js +20 -0
- package/dist/transcript-client.d.ts +19 -0
- package/dist/transcript-client.js +24 -0
- package/dist/trollbox.d.ts +5 -6
- package/dist/trollbox.js +0 -0
- package/package.json +1 -1
- package/src/captions.ts +32 -2
- package/src/hash.ts +139 -0
- package/src/main.ts +27 -3
- package/src/mcp.ts +49 -1
- package/src/media-index.ts +145 -0
- package/src/media-local.ts +117 -0
- package/src/media-page.ts +159 -0
- package/src/media.ts +433 -0
- package/src/server.ts +192 -34
- package/src/transcribe.ts +17 -0
- package/src/transcript-client.ts +34 -0
- package/src/trollbox.ts +0 -0
- package/web/dist/assets/{hls-3VKVEQE3-Dtl-3mpW.js → hls-3VKVEQE3-B4ltbKDh.js} +1 -1
- package/web/dist/assets/index-d7TvpeFZ.js +1 -0
- package/web/dist/assets/index-oyp61Kly.css +1 -0
- package/web/dist/assets/{mpegts-BJC48bFV.js → mpegts-Byy3EkfT.js} +1 -1
- package/web/dist/assets/{mpegts-LO6RVLD6-CUIAB9k3.js → mpegts-LO6RVLD6-C9qqolrW.js} +1 -1
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +6 -6
- package/web/dist/assets/index-B0h4Nexr.js +0 -1
- package/web/dist/assets/index-BTGV3Pi5.css +0 -1
package/src/server.ts
CHANGED
|
@@ -94,6 +94,10 @@ import {
|
|
|
94
94
|
Transcripts, fileFingerprint, formatOf, idFrom, languageCode, linesFrom, mediaOfLive, mediaOfUrl, toSrt, toText, toVtt, transcriptIdOf, wire,
|
|
95
95
|
} from "./transcripts.ts";
|
|
96
96
|
import { handleMessage as mcpMessage } from "./mcp.ts";
|
|
97
|
+
import { Media, factsFromRequest, holderFrom, mediaId, openFileListing, openFileOf, type MediaRecord } from "./media.ts";
|
|
98
|
+
import { mediaPage, type PageTranscript } from "./media-page.ts";
|
|
99
|
+
import { describeFile, refreshChanged } from "./media-local.ts";
|
|
100
|
+
import { WATCH_EVERY_MS, remember, watchOnce } from "./media-index.ts";
|
|
97
101
|
import { Outro } from "./outro.ts";
|
|
98
102
|
import { Profiles, Voices, spokenLine, spokenVoiceFor } from "./voices.ts";
|
|
99
103
|
import { confirm, DEFAULT_DIRECTORY, Publisher } from "./publish.ts";
|
|
@@ -1747,6 +1751,8 @@ export interface HandlerOptions {
|
|
|
1747
1751
|
transcripts?: Transcripts;
|
|
1748
1752
|
/** Stored transcripts translated, as jobs. */
|
|
1749
1753
|
translations?: StoredTranslations;
|
|
1754
|
+
/** The record of every file nixamp has met, by its SHA-256: nixamp.com/hash/<id>. */
|
|
1755
|
+
records?: Media;
|
|
1750
1756
|
/** nixamp.com's address, for the tools reached over /mcp to call. */
|
|
1751
1757
|
site?: string;
|
|
1752
1758
|
/** Other people's OpenProfiles, for the voice their lines are read in. */
|
|
@@ -2771,14 +2777,20 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
2771
2777
|
* The trollbox: the chat for one live room, keyed by the server and
|
|
2772
2778
|
* the channel so every viewer of a stream is in the same box whichever
|
|
2773
2779
|
* page they came from. Reading is open; a line needs a nixamp.com
|
|
2774
|
-
* account and is signed with its public handle;
|
|
2775
|
-
*
|
|
2780
|
+
* account and is signed with its public handle; and once sent it is
|
|
2781
|
+
* public record, so there is no DELETE here for anybody.
|
|
2776
2782
|
*/
|
|
2777
2783
|
if ((path === "/api/v1/trollbox" || path.startsWith("/api/v1/trollbox/")) && options.trollbox && options.accounts) {
|
|
2778
2784
|
const trollbox = options.trollbox;
|
|
2779
2785
|
const child = path.startsWith("/api/v1/trollbox/") ? path.slice("/api/v1/trollbox/".length) : "";
|
|
2786
|
+
// Nothing lives under a line's id: a sent line is public record, so
|
|
2787
|
+
// there is no line to address, whatever the method.
|
|
2788
|
+
if (child !== "") {
|
|
2789
|
+
json(response, 404, { error: "no such endpoint" });
|
|
2790
|
+
return;
|
|
2791
|
+
}
|
|
2780
2792
|
try {
|
|
2781
|
-
if (request.method === "GET"
|
|
2793
|
+
if (request.method === "GET") {
|
|
2782
2794
|
const where = roomFor(url.searchParams.get("server"), url.searchParams.get("channel"));
|
|
2783
2795
|
if (!where) {
|
|
2784
2796
|
json(response, 400, { error: "a room is a server address and a channel" });
|
|
@@ -2789,13 +2801,11 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
2789
2801
|
json(response, 200, {
|
|
2790
2802
|
room: where.room,
|
|
2791
2803
|
you: who ? ((await options.handles?.of(who.id)) || fallbackHandle(who.id)) : "",
|
|
2792
|
-
messages: lines.map((one) => ({
|
|
2793
|
-
id: one.id, handle: one.handle, body: one.body, createdAt: one.createdAt, mine: who !== null && one.authorId === who.id,
|
|
2794
|
-
})),
|
|
2804
|
+
messages: lines.map((one) => ({ id: one.id, handle: one.handle, body: one.body, createdAt: one.createdAt })),
|
|
2795
2805
|
});
|
|
2796
2806
|
return;
|
|
2797
2807
|
}
|
|
2798
|
-
if (request.method === "POST"
|
|
2808
|
+
if (request.method === "POST") {
|
|
2799
2809
|
const who = await options.accounts.whoIs(tokenFrom(request.headers));
|
|
2800
2810
|
if (who === null) {
|
|
2801
2811
|
json(response, 401, { error: "sign in to nixamp.com to chat" });
|
|
@@ -2816,33 +2826,10 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
2816
2826
|
const handle = (await options.handles?.of(who.id)) || fallbackHandle(who.id);
|
|
2817
2827
|
const line = await trollbox.post(where, who.id, handle, body.body);
|
|
2818
2828
|
readOnThePhone(where, who.id, line.handle, line.body);
|
|
2819
|
-
json(response, 201, { message: { id: line.id, handle: line.handle, body: line.body, createdAt: line.createdAt
|
|
2829
|
+
json(response, 201, { message: { id: line.id, handle: line.handle, body: line.body, createdAt: line.createdAt } });
|
|
2820
2830
|
return;
|
|
2821
2831
|
}
|
|
2822
|
-
|
|
2823
|
-
const who = await options.accounts.whoIs(tokenFrom(request.headers));
|
|
2824
|
-
if (who === null) {
|
|
2825
|
-
json(response, 401, { error: "sign in to nixamp.com first" });
|
|
2826
|
-
return;
|
|
2827
|
-
}
|
|
2828
|
-
const where = roomFor(url.searchParams.get("server"), url.searchParams.get("channel"));
|
|
2829
|
-
if (!where) {
|
|
2830
|
-
json(response, 400, { error: "a room is a server address and a channel" });
|
|
2831
|
-
return;
|
|
2832
|
-
}
|
|
2833
|
-
// The listing owner moderates their own server's rooms.
|
|
2834
|
-
const moderator = (options.directory?.list() ?? []).some((listing) => {
|
|
2835
|
-
try {
|
|
2836
|
-
return listing.ownerId === who.id && new URL(listing.url).origin === where.server;
|
|
2837
|
-
} catch {
|
|
2838
|
-
return false;
|
|
2839
|
-
}
|
|
2840
|
-
});
|
|
2841
|
-
const removed = await trollbox.remove(where.room, child, who.id, moderator);
|
|
2842
|
-
json(response, removed ? 200 : 404, removed ? { ok: true } : { error: "not your line, or already gone" });
|
|
2843
|
-
return;
|
|
2844
|
-
}
|
|
2845
|
-
json(response, 405, { error: "GET, POST or DELETE" });
|
|
2832
|
+
json(response, 405, { error: "GET or POST" });
|
|
2846
2833
|
} catch (error) {
|
|
2847
2834
|
if (error instanceof TrollboxError) json(response, error.status, { error: error.message });
|
|
2848
2835
|
else throw error;
|
|
@@ -2899,7 +2886,7 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
2899
2886
|
readOnThePhone(where, who.id, line.handle, line.body);
|
|
2900
2887
|
json(response, 201, {
|
|
2901
2888
|
...said,
|
|
2902
|
-
message: { id: line.id, handle: line.handle, body: line.body, createdAt: line.createdAt
|
|
2889
|
+
message: { id: line.id, handle: line.handle, body: line.body, createdAt: line.createdAt },
|
|
2903
2890
|
});
|
|
2904
2891
|
return;
|
|
2905
2892
|
}
|
|
@@ -2911,6 +2898,134 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
2911
2898
|
return;
|
|
2912
2899
|
}
|
|
2913
2900
|
|
|
2901
|
+
/*
|
|
2902
|
+
* One address per file: /hash/<sha256>, the record of the bytes (see
|
|
2903
|
+
* media.ts). As a page for a person, as an OpenFile file object or plain
|
|
2904
|
+
* JSON for a program, and its transcript as subtitles. Reading is open:
|
|
2905
|
+
* the id is the hash of the bytes, and whoever has it has the file.
|
|
2906
|
+
* Keeping (PUT on the API) is signed in, like the ear.
|
|
2907
|
+
*/
|
|
2908
|
+
if (path === "/.well-known/openfile.json" && options.records && options.site) {
|
|
2909
|
+
json(response, 200, openFileListing(await options.records.recent(), options.site));
|
|
2910
|
+
return;
|
|
2911
|
+
}
|
|
2912
|
+
if ((path.startsWith("/hash/") || path === "/api/v1/media" || path.startsWith("/api/v1/media/")) && options.records && options.transcripts && options.site) {
|
|
2913
|
+
const media = options.records;
|
|
2914
|
+
const store = options.transcripts;
|
|
2915
|
+
const site = options.site;
|
|
2916
|
+
const viaApi = path.startsWith("/api/v1/media");
|
|
2917
|
+
const tail = viaApi ? path.slice("/api/v1/media".length).replace(/^\//, "") : path.slice("/hash/".length);
|
|
2918
|
+
const parts = /^([^/.]+)(?:\.(openfile\.json|json|srt|vtt|txt))?\/?$/.exec(tail);
|
|
2919
|
+
if (!parts) {
|
|
2920
|
+
json(response, 404, { error: "a file is /hash/<sha256>, with .json, .openfile.json, .srt, .vtt or .txt after it" });
|
|
2921
|
+
return;
|
|
2922
|
+
}
|
|
2923
|
+
let named = "";
|
|
2924
|
+
try {
|
|
2925
|
+
named = decodeURIComponent(parts[1] as string);
|
|
2926
|
+
} catch {
|
|
2927
|
+
json(response, 400, { error: "bad id" });
|
|
2928
|
+
return;
|
|
2929
|
+
}
|
|
2930
|
+
const format = parts[2] ?? "";
|
|
2931
|
+
try {
|
|
2932
|
+
if (request.method === "PUT" && viaApi) {
|
|
2933
|
+
const who = await options.accounts?.whoIs(tokenFrom(request.headers));
|
|
2934
|
+
if (!who) {
|
|
2935
|
+
json(response, 401, { error: "sign in to nixamp.com to keep a file's record" });
|
|
2936
|
+
return;
|
|
2937
|
+
}
|
|
2938
|
+
const id = mediaId(named);
|
|
2939
|
+
if (!id) {
|
|
2940
|
+
json(response, 400, { error: "the id is the file's SHA-256, hex" });
|
|
2941
|
+
return;
|
|
2942
|
+
}
|
|
2943
|
+
let body: { name?: unknown; size?: unknown; contentType?: unknown; updated?: unknown; facts?: unknown; holder?: unknown } = {};
|
|
2944
|
+
try {
|
|
2945
|
+
body = JSON.parse(await readBody(request, 256 * 1024)) as typeof body;
|
|
2946
|
+
} catch {
|
|
2947
|
+
json(response, 400, { error: "bad JSON" });
|
|
2948
|
+
return;
|
|
2949
|
+
}
|
|
2950
|
+
const saved = await media.save({
|
|
2951
|
+
id,
|
|
2952
|
+
...(typeof body.name === "string" ? { name: body.name.trim() } : {}),
|
|
2953
|
+
...(typeof body.size === "number" && body.size >= 0 ? { size: Math.floor(body.size) } : {}),
|
|
2954
|
+
...(typeof body.contentType === "string" ? { contentType: body.contentType.trim().slice(0, 100) } : {}),
|
|
2955
|
+
...(typeof body.updated === "string" && !Number.isNaN(Date.parse(body.updated)) ? { updated: new Date(body.updated).toISOString() } : {}),
|
|
2956
|
+
facts: factsFromRequest(body.facts),
|
|
2957
|
+
holder: holderFrom(body.holder),
|
|
2958
|
+
by: who.id,
|
|
2959
|
+
});
|
|
2960
|
+
if (!saved) {
|
|
2961
|
+
json(response, 500, { error: "the record was not kept" });
|
|
2962
|
+
return;
|
|
2963
|
+
}
|
|
2964
|
+
json(response, 200, openFileOf(saved, site, saved.facts.fingerprint ? await store.languages(transcriptIdOf(saved.facts.fingerprint)) : []));
|
|
2965
|
+
return;
|
|
2966
|
+
}
|
|
2967
|
+
if (request.method !== "GET") {
|
|
2968
|
+
json(response, 405, { error: "GET the record, or PUT what you know" });
|
|
2969
|
+
return;
|
|
2970
|
+
}
|
|
2971
|
+
// By the SHA-256, by the transcript store's fingerprint, or by a transcript id.
|
|
2972
|
+
let record: MediaRecord | null = null;
|
|
2973
|
+
const hex = mediaId(named);
|
|
2974
|
+
if (hex) record = await media.get(hex);
|
|
2975
|
+
if (!record && /^file:v1:[0-9a-f]{64}$/.test(named)) record = await media.byFingerprint(named);
|
|
2976
|
+
if (!record && hex) {
|
|
2977
|
+
const transcript = await store.get(hex);
|
|
2978
|
+
if (transcript && transcript.kind === "file") record = await media.byFingerprint(transcript.media);
|
|
2979
|
+
}
|
|
2980
|
+
if (!record) {
|
|
2981
|
+
json(response, 404, { error: "nixamp.com does not know that file yet. `nixamp hash FILE` tells it." });
|
|
2982
|
+
return;
|
|
2983
|
+
}
|
|
2984
|
+
const transcriptId = record.facts.fingerprint ? transcriptIdOf(record.facts.fingerprint) : null;
|
|
2985
|
+
const languages = transcriptId ? await store.languages(transcriptId) : [];
|
|
2986
|
+
if (format === "srt" || format === "vtt" || format === "txt") {
|
|
2987
|
+
const language = languageCode(url.searchParams.get("language"));
|
|
2988
|
+
if (language === null) {
|
|
2989
|
+
json(response, 400, { error: "language is a two-letter code" });
|
|
2990
|
+
return;
|
|
2991
|
+
}
|
|
2992
|
+
const transcript = transcriptId ? await store.get(transcriptId, language) : null;
|
|
2993
|
+
if (!transcript) {
|
|
2994
|
+
json(response, 404, { error: language ? `not written down in ${language}` : "not written down yet" });
|
|
2995
|
+
return;
|
|
2996
|
+
}
|
|
2997
|
+
const text = format === "srt" ? toSrt(transcript.lines) : format === "vtt" ? toVtt(transcript.lines) : toText(transcript.lines);
|
|
2998
|
+
const name = (record.name.replace(/\.[^.]+$/, "") || record.id.slice(0, 12)).replace(/[^\w.-]+/g, "_").slice(0, 60);
|
|
2999
|
+
response.writeHead(200, {
|
|
3000
|
+
...CORS,
|
|
3001
|
+
"content-type": `${format === "vtt" ? "text/vtt" : "text/plain"}; charset=utf-8`,
|
|
3002
|
+
"content-length": Buffer.byteLength(text),
|
|
3003
|
+
"cache-control": "public, max-age=300",
|
|
3004
|
+
"content-disposition": `inline; filename="${name}${transcript.language ? `.${transcript.language}` : ""}.${format}"`,
|
|
3005
|
+
});
|
|
3006
|
+
response.end(text);
|
|
3007
|
+
return;
|
|
3008
|
+
}
|
|
3009
|
+
const descriptor = openFileOf(record, site, languages);
|
|
3010
|
+
const accept = String(request.headers["accept"] ?? "");
|
|
3011
|
+
const wantsJson = viaApi || format === "json" || format === "openfile.json" || (accept.includes("application/json") && !accept.includes("text/html"));
|
|
3012
|
+
if (wantsJson) {
|
|
3013
|
+
json(response, 200, descriptor);
|
|
3014
|
+
return;
|
|
3015
|
+
}
|
|
3016
|
+
const original = transcriptId ? await store.get(transcriptId) : null;
|
|
3017
|
+
const forPage: PageTranscript[] = languages
|
|
3018
|
+
.slice()
|
|
3019
|
+
.sort((a, b) => (a.translatedFrom === null ? -1 : 0) - (b.translatedFrom === null ? -1 : 0))
|
|
3020
|
+
.map((one) => (original && one.language === original.language && one.translatedFrom === null ? { ...one, shown: original.lines } : one));
|
|
3021
|
+
html(response, 200, mediaPage(record, site, forPage));
|
|
3022
|
+
} catch (error) {
|
|
3023
|
+
if (error instanceof SpeechError) json(response, error.status, { error: error.message });
|
|
3024
|
+
else throw error;
|
|
3025
|
+
}
|
|
3026
|
+
return;
|
|
3027
|
+
}
|
|
3028
|
+
|
|
2914
3029
|
/*
|
|
2915
3030
|
* Translation: texts in one language, said in another, by a model on
|
|
2916
3031
|
* this CPU (see translate.ts). Signed in only, like the ear. GET says
|
|
@@ -5815,6 +5930,8 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
5815
5930
|
// What was heard, kept: where the accounts are, under the media's identity.
|
|
5816
5931
|
const transcripts = pool ? new Transcripts(pool, (message) => console.log(message)) : undefined;
|
|
5817
5932
|
const translations = transcripts ? new StoredTranslations(transcripts, translator, (message) => console.log(message)) : undefined;
|
|
5933
|
+
// The record of every file nixamp has met, by its bytes: nixamp.com/hash/<id>.
|
|
5934
|
+
const records = pool ? new Media(pool, (message) => console.log(message)) : undefined;
|
|
5818
5935
|
|
|
5819
5936
|
// nixamp as an OAuth 2.1 authorization server, and the watch parties a
|
|
5820
5937
|
// client site bridges through it. Both need the same three things -- a
|
|
@@ -6024,7 +6141,28 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
6024
6141
|
return { ...base, media: mediaOfUrl(pasted), position: info.position };
|
|
6025
6142
|
}
|
|
6026
6143
|
try {
|
|
6027
|
-
|
|
6144
|
+
const source = info.source;
|
|
6145
|
+
return {
|
|
6146
|
+
...base,
|
|
6147
|
+
media: fileFingerprint(source),
|
|
6148
|
+
position: info.position,
|
|
6149
|
+
// The file itself, for nixamp.com/hash/<id>: hashed here, once,
|
|
6150
|
+
// with what ffprobe and nichedb said and where it is on the air.
|
|
6151
|
+
describe: async () => {
|
|
6152
|
+
const listen = publishable_ ? shareLink(publishable_.url, listenKey, false) : (options.publicUrl || `http://${options.host}:${options.port}`);
|
|
6153
|
+
const described = await describeFile(source, {
|
|
6154
|
+
tools,
|
|
6155
|
+
enricher: enricher ?? null,
|
|
6156
|
+
holder: { kind: "gateway", url: listen, seenAt: new Date().toISOString(), channel: id, name: streamName },
|
|
6157
|
+
});
|
|
6158
|
+
try {
|
|
6159
|
+
remember(source, { id: described.id, fingerprint: described.fingerprint, size: described.size, mtimeMs: described.mtimeMs });
|
|
6160
|
+
} catch {
|
|
6161
|
+
// The index is a convenience.
|
|
6162
|
+
}
|
|
6163
|
+
return { id: described.id, keep: described.keep };
|
|
6164
|
+
},
|
|
6165
|
+
};
|
|
6028
6166
|
} catch {
|
|
6029
6167
|
return null;
|
|
6030
6168
|
}
|
|
@@ -6034,6 +6172,25 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
6034
6172
|
},
|
|
6035
6173
|
})
|
|
6036
6174
|
: undefined;
|
|
6175
|
+
// The files this machine has told nixamp.com about, looked at again on
|
|
6176
|
+
// their own schedule (media-index.ts): a changed file is a new record.
|
|
6177
|
+
if (tools.carries) {
|
|
6178
|
+
const watch = async (): Promise<void> => {
|
|
6179
|
+
const signed = readSession();
|
|
6180
|
+
if (!signed) return;
|
|
6181
|
+
const counts = await watchOnce({
|
|
6182
|
+
refresh: (file, before) => refreshChanged(signed, file, before, { tools, enricher: enricher ?? null }),
|
|
6183
|
+
onEvent: (message) => console.log(` ${message}`),
|
|
6184
|
+
}).catch((error: unknown) => {
|
|
6185
|
+
console.log(` the media index could not be read: ${(error as Error).message}`);
|
|
6186
|
+
return null;
|
|
6187
|
+
});
|
|
6188
|
+
if (counts && counts.changed > 0) console.log(` ${counts.changed} file(s) changed since nixamp.com last heard of them; told it`);
|
|
6189
|
+
};
|
|
6190
|
+
const watching = setInterval(() => void watch(), WATCH_EVERY_MS);
|
|
6191
|
+
watching.unref?.();
|
|
6192
|
+
setTimeout(() => void watch(), 60_000).unref?.();
|
|
6193
|
+
}
|
|
6037
6194
|
const owner = new Owner({
|
|
6038
6195
|
ownerId: options.owner || (session?.token ? await ownerIdOf(session) : ""),
|
|
6039
6196
|
site: session?.site ?? DEFAULT_DIRECTORY,
|
|
@@ -6246,6 +6403,7 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
6246
6403
|
...(translator ? { translator } : {}),
|
|
6247
6404
|
...(transcripts ? { transcripts } : {}),
|
|
6248
6405
|
...(translations ? { translations } : {}),
|
|
6406
|
+
...(records ? { records } : {}),
|
|
6249
6407
|
site: nixampSite,
|
|
6250
6408
|
// Other people's OpenProfiles, read for the voice a line is spoken in,
|
|
6251
6409
|
// and the voices to speak in: ElevenLabs when the Telnyx account holds
|
package/src/transcribe.ts
CHANGED
|
@@ -24,6 +24,8 @@ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
24
24
|
import { basename, extname, join } from "node:path";
|
|
25
25
|
import { detectTools, type Tools } from "./audio.ts";
|
|
26
26
|
import { isQuiet } from "./captions.ts";
|
|
27
|
+
import { Enricher } from "./enrich.ts";
|
|
28
|
+
import { describeFile, keepFile } from "./media-local.ts";
|
|
27
29
|
import { readSession, type Session } from "./session.ts";
|
|
28
30
|
import { MAX_SECONDS, RATE, isWav, type Segment } from "./speech.ts";
|
|
29
31
|
import { fetchTranscript, keepLines, type Got, type StoredTranscript } from "./transcript-client.ts";
|
|
@@ -430,6 +432,21 @@ export async function transcribe(argv: string[], deps: TranscribeDeps = {}): Pro
|
|
|
430
432
|
}
|
|
431
433
|
const id = transcriptIdOf(media);
|
|
432
434
|
const title = /^https?:\/\//.test(file) ? file : basename(file, extname(file));
|
|
435
|
+
// A file gets its address at nixamp.com/hash/<sha256> too, with what this
|
|
436
|
+
// machine knows about it, so the transcript has somewhere to hang.
|
|
437
|
+
if (!/^https?:\/\//.test(file) && !deps.fingerprint) {
|
|
438
|
+
void (async () => {
|
|
439
|
+
try {
|
|
440
|
+
const tools = detectTools();
|
|
441
|
+
const described = await describeFile(file, { tools, enricher: new Enricher() });
|
|
442
|
+
const refused = await keepFile(signed, file, described, { fetcher });
|
|
443
|
+
if (refused) console.error(` The file's record was not kept: ${refused}`);
|
|
444
|
+
else console.error(` ${site}/hash/${described.id}`);
|
|
445
|
+
} catch {
|
|
446
|
+
// The transcript is the point; the record is a bonus.
|
|
447
|
+
}
|
|
448
|
+
})();
|
|
449
|
+
}
|
|
433
450
|
const wanted = (flag(argv, "--translate") ?? "").split(",").map((one) => languageCode(one)).filter((one): one is string => typeof one === "string" && one !== "");
|
|
434
451
|
if (argv.includes("--translate") && wanted.length === 0) {
|
|
435
452
|
console.error("nixamp: --translate is one or more two-letter codes, such as de,sv.");
|
package/src/transcript-client.ts
CHANGED
|
@@ -120,6 +120,40 @@ export async function translateTexts(
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/** What a machine tells nixamp.com about a file it has, for the record at /hash/<id>. */
|
|
124
|
+
export interface MediaToKeep {
|
|
125
|
+
name?: string;
|
|
126
|
+
size?: number;
|
|
127
|
+
contentType?: string;
|
|
128
|
+
updated?: string;
|
|
129
|
+
facts?: Record<string, unknown>;
|
|
130
|
+
holder?: { kind?: string; url: string; seenAt?: string; channel?: string; name?: string };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Keep what is known about a file, by its SHA-256 hex. */
|
|
134
|
+
export async function keepMedia(signed: Signed, id: string, ask: MediaToKeep, fetcher: typeof fetch = fetch): Promise<Got<Record<string, unknown>>> {
|
|
135
|
+
try {
|
|
136
|
+
const response = await fetcher(`${base(signed.site)}/api/v1/media/${encodeURIComponent(id)}`, {
|
|
137
|
+
method: "PUT",
|
|
138
|
+
headers: { authorization: `Bearer ${signed.token}`, "content-type": "application/json" },
|
|
139
|
+
body: JSON.stringify(ask),
|
|
140
|
+
});
|
|
141
|
+
return await asJson(response);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
return unreachable(signed.site, error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The record of a file, by id, fingerprint or transcript id. Public: no token needed. */
|
|
148
|
+
export async function fetchMedia(site: string, id: string, fetcher: typeof fetch = fetch): Promise<Got<Record<string, unknown>>> {
|
|
149
|
+
try {
|
|
150
|
+
const response = await fetcher(`${base(site)}/api/v1/media/${encodeURIComponent(id)}`, { headers: { accept: "application/json" } });
|
|
151
|
+
return await asJson(response);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
return unreachable(site, error);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
123
157
|
/** Forget some media's transcripts. Only whoever stored them may. */
|
|
124
158
|
export async function forgetTranscript(signed: Signed, id: string, fetcher: typeof fetch = fetch): Promise<Got<{ ok: true }>> {
|
|
125
159
|
try {
|
package/src/trollbox.ts
CHANGED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./index-
|
|
1
|
+
import{t as e}from"./index-d7TvpeFZ.js";var t=3;async function n(n){let{media:r,src:i,isTv:a}=n,{default:o}=await e(async()=>{let{default:e}=await import(`./hls-n74Cnh8A.js`);return{default:e}},[]);if(!o.isSupported())return n.onError(`This browser cannot play HLS streams.`),{destroy:()=>void 0,levels:()=>[]};let s=new o({...a?{maxBufferLength:60,maxMaxBufferLength:120,backBufferLength:30,liveSyncDurationCount:4}:{backBufferLength:90},enableWorker:!0}),c=0,l=!1;s.on(o.Events.ERROR,(e,r)=>{if(!l&&r.fatal){if(c>=t){n.onError(`This stream kept failing and has been stopped.`),s.destroy();return}switch(c+=1,r.type){case o.ErrorTypes.NETWORK_ERROR:n.onNotice(`Reconnecting…`),s.startLoad();break;case o.ErrorTypes.MEDIA_ERROR:n.onNotice(`Recovering…`),s.recoverMediaError();break;default:n.onError(`This stream could not be played.`),s.destroy()}}}),s.on(o.Events.MANIFEST_PARSED,()=>{l||(n.onNotice(null),n.onReady?.({live:s.levels.length>0&&!Number.isFinite(r.duration),levels:u()}))}),s.on(o.Events.LEVEL_LOADED,(e,t)=>{l||n.onReady?.({live:t.details.live,levels:u()})}),s.on(o.Events.FRAG_BUFFERED,()=>{l||n.onNotice(null)});function u(){return s.levels.map((e,t)=>({index:t,height:e.height||null,bitrate:e.bitrate||null,label:e.height?`${String(e.height)}p`:`${String(Math.round((e.bitrate||0)/1e3))}k`}))}return s.loadSource(i),s.attachMedia(r),{destroy(){l=!0,s.destroy()},levels:u,setLevel(e){s.currentLevel=e},currentLevel:()=>s.autoLevelEnabled?-1:s.currentLevel}}export{n as createHlsEngine};
|