nixamp 0.58.0 → 0.59.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/ai-label.d.ts +6 -0
- package/dist/ai-label.js +1 -0
- package/dist/channels.d.ts +20 -0
- package/dist/channels.js +38 -0
- package/dist/follow-page.js +1 -1
- package/dist/label-routes.js +3 -1
- package/dist/music-hub.d.ts +97 -0
- package/dist/music-hub.js +215 -0
- package/dist/music-store.d.ts +2 -0
- package/dist/music-store.js +4 -2
- package/dist/radio-pages.js +1 -1
- package/dist/server.d.ts +9 -0
- package/dist/server.js +92 -6
- package/dist/station-routes.d.ts +9 -1
- package/dist/station-routes.js +63 -3
- package/dist/store-routes.js +5 -4
- package/package.json +1 -1
- package/src/ai-label.ts +3 -0
- package/src/channels.ts +43 -0
- package/src/follow-page.ts +1 -1
- package/src/label-routes.ts +3 -1
- package/src/music-hub.ts +210 -0
- package/src/music-store.ts +6 -2
- package/src/radio-pages.ts +1 -1
- package/src/server.ts +85 -6
- package/src/station-routes.ts +69 -4
- package/src/store-routes.ts +5 -4
- package/web/dist/assets/{ar-C8G_vLmh.js → ar-BGz59p0i.js} +1 -1
- package/web/dist/assets/chunk-Q2XQMA4B-BaoaSqsD.js +1 -0
- package/web/dist/assets/{cs-7bYMjFS2.js → cs-DKsmGQfn.js} +1 -1
- package/web/dist/assets/{da-DHY5Csp_.js → da-VBBFYTgq.js} +1 -1
- package/web/dist/assets/{de-YNBoxnLa.js → de-DocjfCJV.js} +1 -1
- package/web/dist/assets/{es-9F9kBzzh.js → es-ScAWdKuT.js} +1 -1
- package/web/dist/assets/{fi-BqpzsfBb.js → fi-BCjOujwG.js} +1 -1
- package/web/dist/assets/{fr-BKQXRwFk.js → fr-EO9zGot_.js} +1 -1
- package/web/dist/assets/{hi-CGNIGyR-.js → hi-DOv37S1y.js} +1 -1
- package/web/dist/assets/{hls-OR5FY6YP-CxI-FwpW.js → hls-OR5FY6YP-B-70I17r.js} +1 -1
- package/web/dist/assets/{hu-anYPYX8d.js → hu-BMxwsXKm.js} +1 -1
- package/web/dist/assets/{id-BW3GasRn.js → id-DDfdVuoK.js} +1 -1
- package/web/dist/assets/{it-C7w2DZ3R.js → it-BbbFjt9-.js} +1 -1
- package/web/dist/assets/{main-YkIgU0VD.js → main-BMYkP1N_.js} +2 -2
- package/web/dist/assets/modulepreload-polyfill-P2Xu9kJm.js +1 -0
- package/web/dist/assets/{mpegts-7CN75AI2-D-6xFZI-.js → mpegts-7CN75AI2-D-bdbDNw.js} +1 -1
- package/web/dist/assets/{mpegts-D2ZKeEby.js → mpegts-C_-pZIIG.js} +1 -1
- package/web/dist/assets/music-CmI2KJ1Y.js +1 -0
- package/web/dist/assets/music-jouma3VD.css +1 -0
- package/web/dist/assets/{nl-BNrkTQI2.js → nl-CO-MkYd-.js} +1 -1
- package/web/dist/assets/radio-DmVc3wpH.js +1 -0
- package/web/dist/assets/{ru-CnKOo1uk.js → ru-C48YQfIR.js} +1 -1
- package/web/dist/assets/{station-CSnjPeod.css → station-6b_smJHe.css} +1 -1
- package/web/dist/assets/station-DtY1LOm5.js +3 -0
- package/web/dist/assets/{sv-BsknKdtx.js → sv--HR26-tY.js} +1 -1
- package/web/dist/assets/{uk-u_igTh6D.js → uk-p55LkwrK.js} +1 -1
- package/web/dist/assets/{vi-DH0ApTua.js → vi-DPS8isVc.js} +1 -1
- package/web/dist/assets/vod-BzQvQVLd.js +1 -0
- package/web/dist/assets/watch-B9LW8D1C.js +1 -0
- package/web/dist/assets/{zh-Bcnk2nIV.js → zh-Dw9Ji9b2.js} +1 -1
- package/web/dist/index.html +4 -3
- package/web/dist/music.html +43 -0
- package/web/dist/radio.html +3 -2
- package/web/dist/station.html +4 -3
- package/web/dist/sw.js +32 -29
- package/web/dist/vod.html +4 -3
- package/web/dist/watch.html +4 -3
- package/web/dist/assets/chunk-Q2XQMA4B-PTuZPMen.js +0 -1
- package/web/dist/assets/radio-DV3h4YZS.js +0 -1
- package/web/dist/assets/station-M7G4NiE3.js +0 -3
- package/web/dist/assets/vod-Br9Ooz6-.js +0 -1
- package/web/dist/assets/watch-Brz-RgjN.js +0 -1
package/dist/server.js
CHANGED
|
@@ -64,6 +64,7 @@ import { handleAiRoutes, isPublicSharePath } from "./ai-routes.js";
|
|
|
64
64
|
import { AiLabel } from "./ai-label.js";
|
|
65
65
|
import { buyLink, handleLabelRoutes, isPublicLabelPath } from "./label-routes.js";
|
|
66
66
|
import { GrantVerifier, MusicStore, PRICES } from "./music-store.js";
|
|
67
|
+
import { handleMusicRoutes, isMusicPath, MusicHub, musicPageFor, serverId } from "./music-hub.js";
|
|
67
68
|
import { handleStoreRoutes, isStorePath } from "./store-routes.js";
|
|
68
69
|
import { AiRadio } from "./ai-radio.js";
|
|
69
70
|
import { ListenerShares } from "./listener-shares.js";
|
|
@@ -1591,7 +1592,7 @@ export function createHandler(engine, options) {
|
|
|
1591
1592
|
query.set("t", station.listenToken);
|
|
1592
1593
|
request.url = `/api/v1/stations/${station.id}/${sub[2]}?${query.toString()}`;
|
|
1593
1594
|
const here = options.stations.publicBase?.() ?? "";
|
|
1594
|
-
rewriteResponse(response, radioRewriter(station, sub[1], /^https:\/\//.test(here) ? `${storeSite}/buy?server=${
|
|
1595
|
+
rewriteResponse(response, radioRewriter(station, sub[1], /^https:\/\//.test(here) ? `${storeSite}/buy?server=${serverId(here)}&` : ""));
|
|
1595
1596
|
return handle(request, response);
|
|
1596
1597
|
}
|
|
1597
1598
|
}
|
|
@@ -2309,6 +2310,9 @@ export function createHandler(engine, options) {
|
|
|
2309
2310
|
!(isPublicLabelPath(path) && Boolean(options.stations?.label)) &&
|
|
2310
2311
|
// The music store: its pages, checkout, receipts and grants (nixamp.com).
|
|
2311
2312
|
!(isStorePath(path) && Boolean(options.musicStore)) &&
|
|
2313
|
+
// nixamp.com/music: the app and its catalogue, for anybody.
|
|
2314
|
+
!(isMusicPath(path) && Boolean(options.music)) &&
|
|
2315
|
+
!(/^\/radio\/(artist|album)\//.test(path) && Boolean(options.music)) &&
|
|
2312
2316
|
// What is on, as MCP, for anybody.
|
|
2313
2317
|
path !== "/mcp/public" &&
|
|
2314
2318
|
// Supporting a copyright holder is for anybody listening.
|
|
@@ -2643,6 +2647,15 @@ export function createHandler(engine, options) {
|
|
|
2643
2647
|
// /radio: public, listed stations under readable names, and the artists and
|
|
2644
2648
|
// albums they play (radio-pages.ts). A station's own paths under its name
|
|
2645
2649
|
// were answered at the top of this handler.
|
|
2650
|
+
// On nixamp.com, live.streaming's artist and album addresses open the same page of the music app.
|
|
2651
|
+
if (options.music && /^\/radio\/(artist|album)\//.test(path) && (request.method === "GET" || request.method === "HEAD")) {
|
|
2652
|
+
const target = await musicPageFor(options.music.hub, path).catch(() => "");
|
|
2653
|
+
if (target) {
|
|
2654
|
+
response.writeHead(302, { location: target });
|
|
2655
|
+
response.end();
|
|
2656
|
+
return;
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2646
2659
|
if (options.stations && isRadioPath(path) && (request.method === "GET" || request.method === "HEAD")) {
|
|
2647
2660
|
const stations = options.stations;
|
|
2648
2661
|
const named = radioStations(stations.store.list());
|
|
@@ -2844,6 +2857,23 @@ export function createHandler(engine, options) {
|
|
|
2844
2857
|
});
|
|
2845
2858
|
return;
|
|
2846
2859
|
}
|
|
2860
|
+
if (options.music && isMusicPath(path)) {
|
|
2861
|
+
const music = options.music;
|
|
2862
|
+
const shell = web ? join(web, "music.html") : "";
|
|
2863
|
+
if (await handleMusicRoutes(request, response, path, {
|
|
2864
|
+
hub: music.hub,
|
|
2865
|
+
json,
|
|
2866
|
+
readBody,
|
|
2867
|
+
page: () => { try {
|
|
2868
|
+
return shell ? readFileSync(shell, "utf8") : null;
|
|
2869
|
+
}
|
|
2870
|
+
catch {
|
|
2871
|
+
return null;
|
|
2872
|
+
} },
|
|
2873
|
+
released: music.released,
|
|
2874
|
+
}))
|
|
2875
|
+
return;
|
|
2876
|
+
}
|
|
2847
2877
|
if (options.musicStore && options.support && isStorePath(path)) {
|
|
2848
2878
|
const support = options.support;
|
|
2849
2879
|
const accounts = options.accounts;
|
|
@@ -7147,6 +7177,19 @@ export async function serve(argv, version = "0.1.0") {
|
|
|
7147
7177
|
root: process.env["NIXAMP_LABEL_ROOT"] || (labelHome ? join(labelHome.root, "ai") : join(stateDir(), "ai-label")),
|
|
7148
7178
|
owner: options.owner || "",
|
|
7149
7179
|
mayStart: mayStartStation,
|
|
7180
|
+
// A release is told to nixamp.com as this server's owner; nixamp.com tells the artist's followers.
|
|
7181
|
+
announce: (release) => {
|
|
7182
|
+
const session = readSession();
|
|
7183
|
+
const here = stations.publicBase?.() ?? "";
|
|
7184
|
+
if (!session?.token || !/^https:\/\//.test(here))
|
|
7185
|
+
return;
|
|
7186
|
+
void fetch(`${session.site.replace(/\/+$/, "")}/api/v1/music/released`, {
|
|
7187
|
+
method: "POST",
|
|
7188
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${session.token}` },
|
|
7189
|
+
body: JSON.stringify({ ...release, server: here }),
|
|
7190
|
+
signal: AbortSignal.timeout(15_000),
|
|
7191
|
+
}).then((answer) => console.log(` ai label: nixamp.com was told of "${release.title}" (${answer.status})`)).catch(() => undefined);
|
|
7192
|
+
},
|
|
7150
7193
|
log: (line) => console.log(line),
|
|
7151
7194
|
});
|
|
7152
7195
|
aiRadio.startSchedule();
|
|
@@ -7397,18 +7440,54 @@ export async function serve(argv, version = "0.1.0") {
|
|
|
7397
7440
|
supportMonthly?.startSchedule();
|
|
7398
7441
|
// The AI label's songs for sale: purchases kept here, the music zipped by the server that holds it.
|
|
7399
7442
|
const jwtSecret = process.env["NIXAMP_JWT_SECRET"] ?? "";
|
|
7443
|
+
// The servers whose music nixamp.com sells and plays: the directory and the guide's peers.
|
|
7444
|
+
const musicServers = () => {
|
|
7445
|
+
const listed = directory ? directory.list().map((one) => peerBase(one.url)).filter(Boolean) : [];
|
|
7446
|
+
return [...new Set([...guidePeers(), ...listed])];
|
|
7447
|
+
};
|
|
7448
|
+
// nixamp.com/music: every server's label in one catalogue (music-hub.ts).
|
|
7449
|
+
const musicHub = options.directory ? new MusicHub({ peers: musicServers }) : undefined;
|
|
7400
7450
|
const musicStore = supportPayments && supportPayments.enabled && pool && jwtSecret ? new MusicStore({
|
|
7401
7451
|
db: pool,
|
|
7402
7452
|
support: supportPayments,
|
|
7403
7453
|
mail: process.env["RESEND_API_KEY"] ? { apiKey: process.env["RESEND_API_KEY"], from: process.env["NIXAMP_MAIL_FROM"] ?? "nixamp <notifications@nixamp.com>" } : null,
|
|
7404
7454
|
site: nixampSite,
|
|
7405
7455
|
secret: sha("sha256").update(`music-grant:${jwtSecret}`).digest("hex"),
|
|
7406
|
-
servers:
|
|
7407
|
-
|
|
7408
|
-
return [...new Set([...guidePeers(), ...listed])];
|
|
7409
|
-
},
|
|
7456
|
+
servers: musicServers,
|
|
7457
|
+
...(musicHub ? { resolveServer: (id) => musicHub.resolve(id) } : {}),
|
|
7410
7458
|
log: (line) => console.log(line),
|
|
7411
7459
|
}) : undefined;
|
|
7460
|
+
/**
|
|
7461
|
+
* A server says an album (or song) of its label landed: its artist's
|
|
7462
|
+
* followers are told. Only the account that owns a listed server may say
|
|
7463
|
+
* so, only for an artist that server's catalogue has, once per release.
|
|
7464
|
+
*/
|
|
7465
|
+
const announced = new Set();
|
|
7466
|
+
const musicReleased = async (request, body) => {
|
|
7467
|
+
const me = accounts ? await accounts.whoIs(tokenFrom(request.headers)).catch(() => null) : null;
|
|
7468
|
+
if (!me)
|
|
7469
|
+
return { status: 401, body: { error: "sign in as the server's owner" } };
|
|
7470
|
+
const base = peerBase(String(body["server"] ?? ""));
|
|
7471
|
+
const owns = directory?.list().some((one) => one.ownerId === me.id && peerBase(one.url) === base) ?? false;
|
|
7472
|
+
if (!base || !owns || !musicHub)
|
|
7473
|
+
return { status: 403, body: { error: "that server is not yours, or not listed" } };
|
|
7474
|
+
const catalogue = await musicHub.catalogue();
|
|
7475
|
+
const id = serverId(base);
|
|
7476
|
+
const artist = catalogue.genres.flatMap((one) => one.artists).find((one) => one.server === id && one.key === body["artist"]);
|
|
7477
|
+
const what = String(body["title"] ?? "").replace(/[\r\n]/g, " ").slice(0, 120);
|
|
7478
|
+
if (!artist || !what)
|
|
7479
|
+
return { status: 404, body: { error: "no such artist on that server" } };
|
|
7480
|
+
const key = `${id}:${artist.key}:${what}`;
|
|
7481
|
+
if (announced.has(key))
|
|
7482
|
+
return { status: 200, body: { told: false, why: "already" } };
|
|
7483
|
+
announced.add(key);
|
|
7484
|
+
tellAudienceOf(artist.follow, {
|
|
7485
|
+
title: `New from ${artist.name}`,
|
|
7486
|
+
body: body["kind"] === "song" ? `"${what}" is out. Listen free on nixamp.` : `The album "${what}" is out. Listen free on nixamp.`,
|
|
7487
|
+
url: `${nixampSite}/music/artist/${id}/${artist.key}`,
|
|
7488
|
+
});
|
|
7489
|
+
return { status: 202, body: { told: true, follow: artist.follow } };
|
|
7490
|
+
};
|
|
7412
7491
|
if (translationPasses)
|
|
7413
7492
|
void translationPasses.access().catch(() => console.error("nixamp: translation checkout could not warm; it will retry on demand"));
|
|
7414
7493
|
const liveVoice = accounts && process.env["NIXAMP_DUBBING"] !== "off" ? new LiveVoice({
|
|
@@ -7556,8 +7635,14 @@ export async function serve(argv, version = "0.1.0") {
|
|
|
7556
7635
|
body: `${what} Listen at ${DEFAULT_DIRECTORY}/directory, or call ${CALL_IN_NUMBER} and key ${listing.code}.`.trim(),
|
|
7557
7636
|
url: listing.url,
|
|
7558
7637
|
};
|
|
7638
|
+
tellAudienceOf(listing.ownerId, note);
|
|
7639
|
+
};
|
|
7640
|
+
/** Everyone following `followed` (an account, or `artist:<slug>`), by every way they asked to be told. */
|
|
7641
|
+
const tellAudienceOf = (followed, note) => {
|
|
7642
|
+
if (follows === undefined)
|
|
7643
|
+
return;
|
|
7559
7644
|
void follows
|
|
7560
|
-
.audience(
|
|
7645
|
+
.audience(followed)
|
|
7561
7646
|
.then((audience) => notifyAll(audience, note, {
|
|
7562
7647
|
...(process.env["RESEND_API_KEY"]
|
|
7563
7648
|
? {
|
|
@@ -7960,6 +8045,7 @@ export async function serve(argv, version = "0.1.0") {
|
|
|
7960
8045
|
...(supportPayments ? { support: supportPayments } : {}),
|
|
7961
8046
|
...(supportMonthly ? { supportSubscriptions: supportMonthly } : {}),
|
|
7962
8047
|
...(musicStore ? { musicStore } : {}),
|
|
8048
|
+
...(musicHub ? { music: { hub: musicHub, released: musicReleased } } : {}),
|
|
7963
8049
|
...(process.env["COINPAY_WEBHOOK_SECRET"] ? { coinpayWebhookSecret: process.env["COINPAY_WEBHOOK_SECRET"] } : {}),
|
|
7964
8050
|
...(sharedTranslations ? { sharedTranslations } : {}),
|
|
7965
8051
|
...(translator ? { translator } : {}),
|
package/dist/station-routes.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* reading English.
|
|
14
14
|
*/
|
|
15
15
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
16
|
-
import type
|
|
16
|
+
import { type Channels } from "./channels.ts";
|
|
17
17
|
import type { StationRunner } from "./station-runner.ts";
|
|
18
18
|
import { type Limits, type StationUsage } from "./station-metering.ts";
|
|
19
19
|
import { type TrackFacts } from "./track-facts.ts";
|
|
@@ -98,6 +98,14 @@ declare function links(ctx: StationContext, station: Station, base?: string): {
|
|
|
98
98
|
m3u: string;
|
|
99
99
|
state: string;
|
|
100
100
|
};
|
|
101
|
+
/** Records a connection's bytes onto its channel's, through the listener it writes to. */
|
|
102
|
+
export declare function clockedListener<T extends {
|
|
103
|
+
write(chunk: Buffer): boolean;
|
|
104
|
+
}>(key: string, out: T): T & {
|
|
105
|
+
forget(): void;
|
|
106
|
+
};
|
|
107
|
+
/** Which byte of its channel a connection's player is on, `seconds` into what it was sent; null when unknown. */
|
|
108
|
+
export declare function heardByte(key: string, seconds: number, kbps: number): number | null;
|
|
101
109
|
export declare function publicView(ctx: StationContext, station: Station): PublicStation;
|
|
102
110
|
/** Where the guide puts a station: composed by AI, shared by listeners, or the owner's radio or TV. */
|
|
103
111
|
export type GuideGroup = "ai" | "shared" | "radio" | "tv";
|
package/dist/station-routes.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { chunkStart } from "./channels.js";
|
|
1
2
|
import { alertsFor } from "./station-metering.js";
|
|
2
3
|
import { aiFromTags } from "./track-facts.js";
|
|
3
4
|
import { quietDuringBreaks } from "./break-silence.js";
|
|
@@ -6,7 +7,7 @@ import { watchBase } from "./guide-rooms.js";
|
|
|
6
7
|
import { radioPeers, radioStations } from "./radio-pages.js";
|
|
7
8
|
import { StationError, channelOf, tokensMatch, } from "./stations.js";
|
|
8
9
|
/** The three things a station's link opens. */
|
|
9
|
-
const LISTEN = /^\/api\/v1\/stations\/([a-z0-9]{10})\/(stream|state|listen\.m3u|events|now|art|lyrics)$/;
|
|
10
|
+
const LISTEN = /^\/api\/v1\/stations\/([a-z0-9]{10})\/(stream|state|listen\.m3u|events|now|art|lyrics|clock)$/;
|
|
10
11
|
/** Whether this path is one a station's own link may open, without the server's key. */
|
|
11
12
|
export function isStationListenPath(path) {
|
|
12
13
|
return LISTEN.test(path) || path === "/api/v1/stations/guide";
|
|
@@ -28,6 +29,41 @@ function links(ctx, station, base = ctx.base) {
|
|
|
28
29
|
state: `${at}/state?${query}`,
|
|
29
30
|
};
|
|
30
31
|
}
|
|
32
|
+
const clocks = new Map();
|
|
33
|
+
const MAX_CLOCKS = 5000;
|
|
34
|
+
const MAX_RUNS = 500;
|
|
35
|
+
/** Records a connection's bytes onto its channel's, through the listener it writes to. */
|
|
36
|
+
export function clockedListener(key, out) {
|
|
37
|
+
const clock = { runs: [], local: 0, next: -1 };
|
|
38
|
+
if (clocks.size >= MAX_CLOCKS)
|
|
39
|
+
clocks.delete(clocks.keys().next().value);
|
|
40
|
+
clocks.set(key, clock);
|
|
41
|
+
return Object.assign(Object.create(out), {
|
|
42
|
+
write: (chunk) => {
|
|
43
|
+
const at = chunkStart(chunk);
|
|
44
|
+
// Silence written in a break's place carries no start: it stands for the break's bytes.
|
|
45
|
+
if (at !== undefined && at !== clock.next) {
|
|
46
|
+
clock.runs.push({ local: clock.local, global: at });
|
|
47
|
+
if (clock.runs.length > MAX_RUNS)
|
|
48
|
+
clock.runs.shift();
|
|
49
|
+
}
|
|
50
|
+
clock.local += chunk.length;
|
|
51
|
+
clock.next = (at ?? clock.next) + chunk.length;
|
|
52
|
+
return out.write(chunk);
|
|
53
|
+
},
|
|
54
|
+
forget: () => { if (clocks.get(key) === clock)
|
|
55
|
+
clocks.delete(key); },
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/** Which byte of its channel a connection's player is on, `seconds` into what it was sent; null when unknown. */
|
|
59
|
+
export function heardByte(key, seconds, kbps) {
|
|
60
|
+
const clock = clocks.get(key);
|
|
61
|
+
if (!clock || !(seconds >= 0) || kbps <= 0)
|
|
62
|
+
return null;
|
|
63
|
+
const local = Math.min(clock.local, (seconds * kbps * 1000) / 8);
|
|
64
|
+
const run = clock.runs.findLast((one) => one.local <= local);
|
|
65
|
+
return run ? run.global + (local - run.local) : null;
|
|
66
|
+
}
|
|
31
67
|
/** The file on the air now, as the channel's own encoder last reported it. */
|
|
32
68
|
function nowPlayingFile(ctx, station) {
|
|
33
69
|
const info = ctx.channels.info(channelOf(station.id));
|
|
@@ -247,6 +283,26 @@ export async function handleStations(request, response, path, url, ctx) {
|
|
|
247
283
|
ctx.json(response, 200, { lyrics: { title: lyrics.title, artist: lyrics.artist, text: lyrics.text, source: lyrics.source, language: lyrics.language, ...(lyrics.synced ? { synced: lyrics.synced } : {}) } });
|
|
248
284
|
return true;
|
|
249
285
|
}
|
|
286
|
+
if (what === "clock") {
|
|
287
|
+
// ?n= the stream's nonce, ?ct= the player's currentTime: the song and second being heard.
|
|
288
|
+
const key = `${station.id}:${url.searchParams.get("n") ?? ""}`;
|
|
289
|
+
const byte = heardByte(key, Number(url.searchParams.get("ct")), station.bitrate);
|
|
290
|
+
const place = byte === null ? null : ctx.channels.placeAt(channelOf(station.id), byte);
|
|
291
|
+
if (!place) {
|
|
292
|
+
ctx.json(response, 404, { error: "no clock for that stream", code: "not_found" });
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
const track = place.file ? (place.tags ?? ctx.trackFor(place.file)) : null;
|
|
296
|
+
const duration = place.file && ctx.durationOf ? ctx.durationOf(place.file) : 0;
|
|
297
|
+
ctx.json(response, 200, {
|
|
298
|
+
station: station.id,
|
|
299
|
+
break: place.file === "",
|
|
300
|
+
position: Math.round(place.position * 1000) / 1000,
|
|
301
|
+
duration: Math.round(duration * 10) / 10,
|
|
302
|
+
nowPlaying: track && (track.title || track.artist) ? { title: track.title, artist: track.artist, album: track.album } : null,
|
|
303
|
+
});
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
250
306
|
if (what === "now") {
|
|
251
307
|
const file = ctx.runner.observed(station.id) === "live" || ctx.runner.observed(station.id) === "recovering" ? nowPlayingFile(ctx, station) : "";
|
|
252
308
|
ctx.json(response, 200, { station: station.id, facts: file && ctx.facts ? await ctx.facts(station, file).catch(() => null) : null });
|
|
@@ -315,9 +371,12 @@ export async function handleStations(request, response, path, url, ctx) {
|
|
|
315
371
|
pending: () => response.writableLength,
|
|
316
372
|
}
|
|
317
373
|
: response;
|
|
374
|
+
const nonce = /^[A-Za-z0-9_-]{1,40}$/.test(url.searchParams.get("n") ?? "") ? url.searchParams.get("n") : "";
|
|
375
|
+
const clocked = nonce && !station.video ? clockedListener(`${station.id}:${nonce}`, metered) : null;
|
|
376
|
+
const out = clocked ?? metered;
|
|
318
377
|
const detach = spared
|
|
319
|
-
? ctx.channels.listenWithoutBreaks(channelId,
|
|
320
|
-
: ctx.channels.listen(channelId,
|
|
378
|
+
? ctx.channels.listenWithoutBreaks(channelId, out, station.bitrate, (quiet) => quietDuringBreaks(quiet, station.bitrate, () => true))
|
|
379
|
+
: ctx.channels.listen(channelId, out);
|
|
321
380
|
if (detach === null) {
|
|
322
381
|
response.end();
|
|
323
382
|
return true;
|
|
@@ -332,6 +391,7 @@ export async function handleStations(request, response, path, url, ctx) {
|
|
|
332
391
|
detach();
|
|
333
392
|
untrack();
|
|
334
393
|
left?.();
|
|
394
|
+
clocked?.forget();
|
|
335
395
|
};
|
|
336
396
|
request.on("close", leave);
|
|
337
397
|
response.on("close", leave);
|
package/dist/store-routes.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { createHash } from "node:crypto";
|
|
13
13
|
import { PRICES } from "./music-store.js";
|
|
14
|
+
import { serverId } from "./music-hub.js";
|
|
14
15
|
import { SupportError } from "./support.js";
|
|
15
16
|
const PURCHASE = /^\/purchases\/([0-9a-f-]{36})$/;
|
|
16
17
|
const ONE = /^\/api\/v1\/store\/purchases\/([0-9a-f-]{36})$/;
|
|
@@ -100,7 +101,7 @@ export async function handleStoreRoutes(request, response, path, url, ctx) {
|
|
|
100
101
|
}
|
|
101
102
|
const me = await ctx.account().catch(() => null);
|
|
102
103
|
const what = item.kind === "song" ? "One song" : item.kind === "album" ? `The album, ${item.songs} songs` : `Everything by ${escape(item.artistName)}, ${item.songs} songs so far`;
|
|
103
|
-
const cover = item.kind === "artist" ? "" : `<img src="${escape(
|
|
104
|
+
const cover = item.kind === "artist" ? "" : `<img src="${escape(`/api/v1/music/file/${serverId(item.server)}/${item.artist}/${item.album}/cover.jpg`)}" alt="" width="160" height="160" style="border-radius:10px;float:right;margin:0 0 8px 12px;max-width:40%;height:auto">`;
|
|
104
105
|
html(response, 200, page(`Download ${item.title}`, `<div class="card">${cover}
|
|
105
106
|
<h1>${escape(item.title)}</h1><p class="by">${escape(item.artistName)}</p>
|
|
106
107
|
<div class="price">${price(item.amountCents)}</div>
|
|
@@ -113,8 +114,8 @@ export async function handleStoreRoutes(request, response, path, url, ctx) {
|
|
|
113
114
|
<button id="pay" type="submit">Pay ${price(item.amountCents)} with crypto</button>
|
|
114
115
|
</form>
|
|
115
116
|
<p id="status" role="status" aria-live="polite"></p>
|
|
116
|
-
<small>Payments go through <a href="https://coinpayportal.com">CoinPay</a> to nixamp.com. For small amounts pick a coin with low fees (USDC on Polygon or Solana, SOL, LTC). Listening on the live stations is always free.${me ? "" : ` <a href="/
|
|
117
|
-
</div>`, JSON.stringify({ server: item.server, kind: item.kind, artist: item.artist, album: item.album, n: item.n })), method);
|
|
117
|
+
<small>Payments go through <a href="https://coinpayportal.com">CoinPay</a> to nixamp.com. For small amounts pick a coin with low fees (USDC on Polygon or Solana, SOL, LTC). Listening on the live stations is always free.${me ? "" : ` <a href="/?redirect=${encodeURIComponent("/music/me")}#account-panel">Sign in</a> with the same email to keep everything under My music.`}</small>
|
|
118
|
+
</div>`, JSON.stringify({ server: serverId(item.server), kind: item.kind, artist: item.artist, album: item.album, n: item.n })), method);
|
|
118
119
|
return true;
|
|
119
120
|
}
|
|
120
121
|
const receipt = PURCHASE.exec(path);
|
|
@@ -127,7 +128,7 @@ export async function handleStoreRoutes(request, response, path, url, ctx) {
|
|
|
127
128
|
const body = purchase.status === "paid"
|
|
128
129
|
? `<div class="card"><h1>${escape(purchase.title)}</h1><p class="by">${escape(purchase.artistName)} · paid ${price(purchase.amountCents)}</p>
|
|
129
130
|
<a class="go" href="${escape(store.zipUrl(purchase))}" download>Download the zip</a>
|
|
130
|
-
<small>MP3s with the cover art and lyrics, plus each song's .lyrics.txt, cover.jpg and album.json. Keep this page's address (it is in your email too) to download again. Signed in to nixamp.com as ${escape(purchase.email)}, everything you bought is under <a href="/
|
|
131
|
+
<small>MP3s with the cover art and lyrics, plus each song's .lyrics.txt, cover.jpg and album.json. Keep this page's address (it is in your email too) to download again. Signed in to nixamp.com as ${escape(purchase.email)}, everything you bought is under <a href="/music/me">My music</a>, to play or download.</small></div>`
|
|
131
132
|
: `<div class="card"><h1>${escape(purchase.title)}</h1><p class="by">${escape(purchase.artistName)} · ${price(purchase.amountCents)} in ${escape(purchase.coin)}</p>
|
|
132
133
|
<p>Waiting for your payment. Once CoinPay confirms it, your download is here and in your email (${escape(purchase.email)}). This page checks again when you reload it.</p>
|
|
133
134
|
<a class="go" href="https://coinpayportal.com/pay/${escape(purchase.paymentId)}">Open the payment</a></div>`;
|
package/package.json
CHANGED
package/src/ai-label.ts
CHANGED
|
@@ -738,6 +738,8 @@ export interface AiLabelDeps {
|
|
|
738
738
|
storyVideo?: (input: { audio: string; images: string[]; seconds: number; artist: string; title: string; out: string }) => Promise<void>;
|
|
739
739
|
/** A scene's picture for this prompt, or null when nothing can draw one; Workers AI by default. */
|
|
740
740
|
image?: (prompt: string) => Promise<Buffer | null>;
|
|
741
|
+
/** Tells the world an album landed (nixamp.com tells the artist's followers); never awaited. */
|
|
742
|
+
announce?: (release: { artist: string; title: string; kind: "album" | "song" }) => void;
|
|
741
743
|
/** The day's pick (artist, genre, new or not); Math.random by default. */
|
|
742
744
|
random?: () => number;
|
|
743
745
|
now?: () => number;
|
|
@@ -1383,6 +1385,7 @@ export class AiLabel {
|
|
|
1383
1385
|
if (album.songs.every((one) => one.file)) {
|
|
1384
1386
|
album.doneAt = this.now();
|
|
1385
1387
|
this.log(`${artist.name} released "${album.title}"`);
|
|
1388
|
+
this.deps.announce?.({ artist: artist.key, title: album.title, kind: "album" });
|
|
1386
1389
|
void this.ensureProfile(artist).catch(() => undefined);
|
|
1387
1390
|
}
|
|
1388
1391
|
this.save();
|
package/src/channels.ts
CHANGED
|
@@ -282,6 +282,21 @@ export interface ChannelOptions {
|
|
|
282
282
|
through?: ThroughProvider;
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Where each chunk a channel put out begins in its byte count (ChannelInfo.bytes),
|
|
287
|
+
* so a listener's own bytes can be laid onto the channel's: a backlog, a
|
|
288
|
+
* skipped break and a redial all keep the chunk objects they were sent as.
|
|
289
|
+
*/
|
|
290
|
+
const chunkStarts = new WeakMap<Buffer, number>();
|
|
291
|
+
|
|
292
|
+
/** The byte count a chunk began at, for one a list channel put out; undefined for any other. */
|
|
293
|
+
export function chunkStart(chunk: Buffer): number | undefined {
|
|
294
|
+
return chunkStarts.get(chunk);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** A list's dial: where in the byte count it began, and its list's clock. */
|
|
298
|
+
interface Dial { base: number; input: PlaylistInputStream; kbps: number }
|
|
299
|
+
|
|
285
300
|
/**
|
|
286
301
|
* One live source, and its audience.
|
|
287
302
|
*
|
|
@@ -338,6 +353,20 @@ export class Channel {
|
|
|
338
353
|
return this.info.bytes > 0 && (!this.fragments || this.fragments.ready);
|
|
339
354
|
}
|
|
340
355
|
|
|
356
|
+
/**
|
|
357
|
+
* What was going out at this point of the byte count: the list's file (""
|
|
358
|
+
* in a break) and how far into it, with its tags. Null for a byte this
|
|
359
|
+
* channel no longer knows, or for a channel that is not a radio list.
|
|
360
|
+
*/
|
|
361
|
+
placeAt(bytes: number): { file: string; position: number; tags?: { title: string; artist: string; album: string } } | null {
|
|
362
|
+
const dial = this.dials.findLast((one) => one.base <= bytes);
|
|
363
|
+
if (!dial) return null;
|
|
364
|
+
const place = dial.input.place(((bytes - dial.base) * 8) / (dial.kbps * 1000));
|
|
365
|
+
const file = place.at >= 0 ? place.list[place.at] ?? "" : "";
|
|
366
|
+
const tags = file ? dial.input.tags.get(file) : undefined;
|
|
367
|
+
return { file, position: place.position, ...(tags ? { tags } : {}) };
|
|
368
|
+
}
|
|
369
|
+
|
|
341
370
|
/** An entry's tags, as read when it was put on. */
|
|
342
371
|
tagsOf(file: string): { title: string; artist: string; album: string } | undefined {
|
|
343
372
|
return this.playlistInput?.tags.get(file);
|
|
@@ -369,6 +398,8 @@ export class Channel {
|
|
|
369
398
|
private breakOn = false;
|
|
370
399
|
/** The last couple of minutes of a radio list without its breaks, for listenWithoutBreaks. */
|
|
371
400
|
private music: Buffer[] = [];
|
|
401
|
+
/** The last few dials of a radio list, newest last, for placeAt(). */
|
|
402
|
+
private dials: Dial[] = [];
|
|
372
403
|
private musicBytes = 0;
|
|
373
404
|
private fragmentClock = new FragmentClock();
|
|
374
405
|
private fragmentTimes = new WeakMap<Buffer, number>();
|
|
@@ -622,9 +653,16 @@ export class Channel {
|
|
|
622
653
|
if (this.child !== child) return;
|
|
623
654
|
if (!sent) this.info.error = undefined;
|
|
624
655
|
sent = true;
|
|
656
|
+
const at = this.info.bytes;
|
|
625
657
|
this.info.bytes += chunk.byteLength;
|
|
626
658
|
this.rearm(child);
|
|
627
659
|
if (kbps > 0 && playlistInput) {
|
|
660
|
+
// Constant-bitrate MP3: a byte of this dial is exactly a time on its list's clock.
|
|
661
|
+
if (written === 0) {
|
|
662
|
+
this.dials.push({ base: at, input: playlistInput, kbps });
|
|
663
|
+
if (this.dials.length > 8) this.dials.shift();
|
|
664
|
+
}
|
|
665
|
+
chunkStarts.set(chunk, at);
|
|
628
666
|
this.breakOn = playlistInput.place((written * 8) / (kbps * 1000)).at === -1;
|
|
629
667
|
written += chunk.byteLength;
|
|
630
668
|
} else this.breakOn = this.info.playlistAt === -1;
|
|
@@ -1460,6 +1498,11 @@ export class Channels {
|
|
|
1460
1498
|
return this.open.get(id)?.info.kind;
|
|
1461
1499
|
}
|
|
1462
1500
|
|
|
1501
|
+
/** What a radio list channel was putting out at a point of its byte count (Channel.placeAt). */
|
|
1502
|
+
placeAt(id: string, bytes: number): ReturnType<Channel["placeAt"]> {
|
|
1503
|
+
return this.open.get(id)?.placeAt(bytes) ?? null;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1463
1506
|
/** An entry's tags on a channel playing a list of files. */
|
|
1464
1507
|
tagsOf(id: string, file: string): { title: string; artist: string; album: string } | undefined {
|
|
1465
1508
|
return this.open.get(id)?.tagsOf(file);
|
package/src/follow-page.ts
CHANGED
|
@@ -112,7 +112,7 @@ export async function handleFollowPage(request: IncomingMessage, response: Serve
|
|
|
112
112
|
if (!me) {
|
|
113
113
|
send(response, 200, page(`Follow ${target.name}`, `<h1>Follow ${escape(target.name)}</h1>
|
|
114
114
|
<p class="by">Sign in to nixamp.com to follow the artists you hear on the radio.</p>
|
|
115
|
-
<a class="go" href="/
|
|
115
|
+
<a class="go" href="/music/me">Sign in to nixamp.com</a>
|
|
116
116
|
<small>Signed in, open this page again (or press Follow on the artist's page) to follow.</small>${back}`), method);
|
|
117
117
|
return true;
|
|
118
118
|
}
|
package/src/label-routes.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { createReadStream, statSync } from "node:fs";
|
|
|
11
11
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
12
12
|
import { ROSTER, type AiLabel, type PublicArtist } from "./ai-label.ts";
|
|
13
13
|
import { covers, PRICES, type GrantVerifier } from "./music-store.ts";
|
|
14
|
+
import { serverId } from "./music-hub.ts";
|
|
14
15
|
import { writeZip, zipSize } from "./zip-stream.ts";
|
|
15
16
|
import { StationError } from "./stations.ts";
|
|
16
17
|
import { adCsp, withPageAd, type GuideAds } from "./station-guide.ts";
|
|
@@ -30,7 +31,8 @@ export function isPublicLabelPath(path: string): boolean {
|
|
|
30
31
|
|
|
31
32
|
/** nixamp.com's page that sells this: a song, an album or everything by the artist. */
|
|
32
33
|
export function buyLink(site: string, server: string, kind: "song" | "album" | "artist", artist: string, album = "", n = 0): string {
|
|
33
|
-
|
|
34
|
+
// The server goes by its opaque id (music-hub.ts): no link names the machine the music is on.
|
|
35
|
+
const query = new URLSearchParams({ server: /^https:\/\//.test(server) ? serverId(server) : server, kind, artist, ...(kind !== "artist" ? { album } : {}), ...(kind === "song" ? { n: String(n) } : {}) });
|
|
34
36
|
return `${site}/buy?${query.toString()}`;
|
|
35
37
|
}
|
|
36
38
|
|