nixamp 0.18.1 → 0.19.1
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/audio.d.ts +12 -0
- package/dist/audio.js +22 -2
- package/dist/channels.d.ts +15 -0
- package/dist/channels.js +50 -10
- package/dist/links.d.ts +32 -0
- package/dist/links.js +82 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.js +36 -7
- package/package.json +1 -1
- package/src/audio.ts +32 -3
- package/src/channels.ts +59 -10
- package/src/links.ts +88 -0
- package/src/server.ts +44 -6
- package/web/dist/assets/{hls-3VKVEQE3-DLpqiiG9.js → hls-3VKVEQE3-DLsUeG9Z.js} +1 -1
- package/web/dist/assets/index-CwcjINDz.js +1 -0
- package/web/dist/assets/{mpegts-LSi2IZbO.js → mpegts-Df4FZb-F.js} +1 -1
- package/web/dist/assets/{mpegts-LO6RVLD6-CdlaJXcD.js → mpegts-LO6RVLD6-CI2bOyNC.js} +1 -1
- package/web/dist/index.html +8 -12
- package/web/dist/sw.js +5 -5
- package/web/dist/assets/index-BafZs9FO.js +0 -1
package/src/channels.ts
CHANGED
|
@@ -56,6 +56,14 @@ export interface ChannelInfo {
|
|
|
56
56
|
error?: string;
|
|
57
57
|
/** How many times the source has been dialled again since it started. */
|
|
58
58
|
redials?: number;
|
|
59
|
+
/**
|
|
60
|
+
* For a channel that plays a list: the entries, in order, and which one is
|
|
61
|
+
* on. When one ends the next is dialled at once, and the last is followed
|
|
62
|
+
* by the first: a station, not a file. A restart picks up at the entry
|
|
63
|
+
* that was on.
|
|
64
|
+
*/
|
|
65
|
+
playlist?: string[];
|
|
66
|
+
playlistAt?: number;
|
|
59
67
|
/**
|
|
60
68
|
* For a pulled film: how far into it we are, in seconds, read off ffmpeg
|
|
61
69
|
* as it goes. This is what a restart and a redial go back to. A live
|
|
@@ -95,6 +103,8 @@ export interface PullResume {
|
|
|
95
103
|
live: boolean;
|
|
96
104
|
/** Seconds into a film to start from. */
|
|
97
105
|
position: number;
|
|
106
|
+
/** For a list of things rather than one: every entry, in order. */
|
|
107
|
+
playlist?: string[];
|
|
98
108
|
}
|
|
99
109
|
|
|
100
110
|
/**
|
|
@@ -246,6 +256,8 @@ export class Channel {
|
|
|
246
256
|
private fragments: Fragments | null = null;
|
|
247
257
|
/** For a pulled channel: what to run, and how many times it has failed. */
|
|
248
258
|
private redial: (() => void) | null = null;
|
|
259
|
+
/** For a channel playing a list: move to the next entry. Null when there is no list. */
|
|
260
|
+
private advance: (() => boolean) | null = null;
|
|
249
261
|
private failures = 0;
|
|
250
262
|
private timer: ReturnType<typeof setTimeout> | null = null;
|
|
251
263
|
/** Fires when a pulled source has said nothing for STALL. */
|
|
@@ -349,19 +361,37 @@ export class Channel {
|
|
|
349
361
|
this.stall = stall;
|
|
350
362
|
if (this.info.kind === "video") this.fragments = new Fragments();
|
|
351
363
|
const [command, ...prefix] = this.options.ffmpeg as [string, ...string[]];
|
|
352
|
-
const remote = /^https?:\/\//i.test(source);
|
|
353
364
|
this.info.live = resume.live;
|
|
354
365
|
if (!resume.live) this.info.position = Math.max(0, resume.position);
|
|
355
|
-
//
|
|
356
|
-
//
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
366
|
+
// A list plays entry by entry: the one that is on is what gets dialled,
|
|
367
|
+
// and an entry that ended is followed by the next, at once.
|
|
368
|
+
const list = resume.playlist && resume.playlist.length > 0 ? resume.playlist : null;
|
|
369
|
+
let at = 0;
|
|
370
|
+
if (list) {
|
|
371
|
+
this.info.playlist = list;
|
|
372
|
+
at = Math.min(Math.max(0, this.info.playlistAt ?? 0), list.length - 1);
|
|
373
|
+
this.info.playlistAt = at;
|
|
374
|
+
}
|
|
375
|
+
let current = list ? (list[at] as string) : source;
|
|
376
|
+
this.advance = list && list.length > 1
|
|
377
|
+
? () => {
|
|
378
|
+
at = (at + 1) % list.length;
|
|
379
|
+
this.info.playlistAt = at;
|
|
380
|
+
current = list[at] as string;
|
|
381
|
+
return true;
|
|
382
|
+
}
|
|
383
|
+
: null;
|
|
361
384
|
|
|
362
385
|
const dial = (): void => {
|
|
363
386
|
if (this.closing) return;
|
|
364
387
|
this.stderr = "";
|
|
388
|
+
const remote = /^https?:\/\//i.test(current);
|
|
389
|
+
// What every remote input is told: dial again when the CDN drops it, and
|
|
390
|
+
// give up on a socket that has gone quiet. Input options apply to the
|
|
391
|
+
// input that follows them, so a second input is told again.
|
|
392
|
+
const remoteArgs = remote
|
|
393
|
+
? ["-reconnect", "1", "-reconnect_streamed", "1", "-reconnect_delay_max", "5", "-rw_timeout", String(stall * 1000)]
|
|
394
|
+
: [];
|
|
365
395
|
// Where to pick a film up from: a little before where it was, since
|
|
366
396
|
// the place was written down a moment ago and a moment of it twice is
|
|
367
397
|
// better than a moment of it missing. A live source is joined as is,
|
|
@@ -421,7 +451,7 @@ export class Channel {
|
|
|
421
451
|
// and a CDN that got them from yt-dlp and not from us answers 403.
|
|
422
452
|
...input,
|
|
423
453
|
...seek,
|
|
424
|
-
"-i",
|
|
454
|
+
"-i", current,
|
|
425
455
|
// The sound, when the site keeps it apart from the picture: a
|
|
426
456
|
// second input, dialled the same way, that the encode maps in.
|
|
427
457
|
...(audio ? [...remoteArgs, ...(paced ? ["-re"] : []), ...input, ...seek, "-i", audio] : []),
|
|
@@ -584,13 +614,20 @@ export class Channel {
|
|
|
584
614
|
this.close();
|
|
585
615
|
return;
|
|
586
616
|
}
|
|
587
|
-
|
|
617
|
+
// A list moves on. An entry that played to its end is not a source that
|
|
618
|
+
// dropped: the next is dialled now, and it is not a redial. One that
|
|
619
|
+
// gave nothing is skipped the same way, counted as the failure it was,
|
|
620
|
+
// so a list of dead links gives up rather than cycling for ever.
|
|
621
|
+
const moved = this.advance?.() ?? false;
|
|
622
|
+
const ended = moved && sent;
|
|
623
|
+
if (ended) this.info.error = undefined;
|
|
624
|
+
else this.info.redials = (this.info.redials ?? 0) + 1;
|
|
588
625
|
this.startOver();
|
|
589
626
|
const dial = this.redial;
|
|
590
627
|
this.timer = setTimeout(() => {
|
|
591
628
|
this.timer = null;
|
|
592
629
|
dial();
|
|
593
|
-
}, REDIAL);
|
|
630
|
+
}, ended ? 0 : REDIAL);
|
|
594
631
|
// A redial is not a reason to keep the process alive at exit.
|
|
595
632
|
this.timer.unref?.();
|
|
596
633
|
}
|
|
@@ -1171,6 +1208,9 @@ export interface RememberedChannel {
|
|
|
1171
1208
|
live?: boolean;
|
|
1172
1209
|
/** The member who put it on, so it is still theirs after a restart. */
|
|
1173
1210
|
startedBy?: string;
|
|
1211
|
+
/** For a list: every entry, and which was on, so it carries on from there. */
|
|
1212
|
+
playlist?: string[];
|
|
1213
|
+
playlistAt?: number;
|
|
1174
1214
|
}
|
|
1175
1215
|
|
|
1176
1216
|
const REMEMBERED = "channels.json";
|
|
@@ -1207,6 +1247,11 @@ export function rememberedChannels(dir: string, port: number): RememberedChannel
|
|
|
1207
1247
|
if (typeof one["position"] === "number" && Number.isFinite(one["position"]) && one["position"] > 0) kept.position = one["position"];
|
|
1208
1248
|
if (typeof one["live"] === "boolean") kept.live = one["live"];
|
|
1209
1249
|
if (typeof one["startedBy"] === "string" && one["startedBy"] !== "") kept.startedBy = one["startedBy"];
|
|
1250
|
+
if (Array.isArray(one["playlist"])) {
|
|
1251
|
+
const entries = (one["playlist"] as unknown[]).filter((entry): entry is string => typeof entry === "string" && entry !== "");
|
|
1252
|
+
if (entries.length > 0) kept.playlist = entries;
|
|
1253
|
+
if (typeof one["playlistAt"] === "number" && Number.isInteger(one["playlistAt"]) && one["playlistAt"] >= 0) kept.playlistAt = one["playlistAt"];
|
|
1254
|
+
}
|
|
1210
1255
|
return kept;
|
|
1211
1256
|
});
|
|
1212
1257
|
} catch {
|
|
@@ -1230,6 +1275,10 @@ export function rememberedNow(channels: Channels): RememberedChannel[] {
|
|
|
1230
1275
|
if (typeof one.live === "boolean") kept.live = one.live;
|
|
1231
1276
|
if (!one.live && typeof one.position === "number" && one.position > 0) kept.position = Math.floor(one.position);
|
|
1232
1277
|
if (one.startedBy) kept.startedBy = one.startedBy;
|
|
1278
|
+
if (one.playlist && one.playlist.length > 0) {
|
|
1279
|
+
kept.playlist = one.playlist;
|
|
1280
|
+
kept.playlistAt = one.playlistAt ?? 0;
|
|
1281
|
+
}
|
|
1233
1282
|
return kept;
|
|
1234
1283
|
});
|
|
1235
1284
|
}
|
package/src/links.ts
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { createHash } from "node:crypto";
|
|
23
23
|
import { spawn } from "node:child_process";
|
|
24
|
+
import { parseCatalog } from "./catalogs.ts";
|
|
24
25
|
|
|
25
26
|
export interface ResolvedLink {
|
|
26
27
|
/** What to call it: the page's title, or the file's name for a bare file. */
|
|
@@ -50,6 +51,12 @@ export interface ResolvedLink {
|
|
|
50
51
|
ext: string;
|
|
51
52
|
/** The page it came from. */
|
|
52
53
|
page: string;
|
|
54
|
+
/**
|
|
55
|
+
* For a pasted .m3u: every entry in it, in order. The channel plays them
|
|
56
|
+
* one after another and starts over at the end, a station rather than a
|
|
57
|
+
* file; `media` is the first, for the probe that decides what it holds.
|
|
58
|
+
*/
|
|
59
|
+
playlist?: string[];
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
/**
|
|
@@ -71,6 +78,86 @@ export function isDirectMedia(url: string): boolean {
|
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
80
|
|
|
81
|
+
/**
|
|
82
|
+
* A plain m3u: a list of things to play, one per line, which is not a thing
|
|
83
|
+
* ffmpeg reads. The .m3u8 of HLS is a list of segments of one thing, which
|
|
84
|
+
* it does, and stays in DIRECT above.
|
|
85
|
+
*/
|
|
86
|
+
const PLAYLIST = /\.m3u(\?.*)?$/i;
|
|
87
|
+
|
|
88
|
+
export function isPlaylistLink(url: string): boolean {
|
|
89
|
+
try {
|
|
90
|
+
const parsed = new URL(url);
|
|
91
|
+
return PLAYLIST.test(parsed.pathname + parsed.search);
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** How much of a playlist is worth reading: a list, not a library dump. */
|
|
98
|
+
export const PLAYLIST_MAX_BYTES = 2_000_000;
|
|
99
|
+
export const PLAYLIST_MAX_ENTRIES = 1000;
|
|
100
|
+
export const PLAYLIST_FETCH_TIMEOUT_MS = 15_000;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* What a playlist's text holds: the entries, in order, resolved against
|
|
104
|
+
* where the list was fetched from. Some things called .m3u are HLS after
|
|
105
|
+
* all -- a segment list with #EXT-X- tags -- and those are one stream for
|
|
106
|
+
* ffmpeg to read as it is, not a list of streams.
|
|
107
|
+
*/
|
|
108
|
+
export function playlistFrom(text: string, base: string): { hls: boolean; sources: string[] } {
|
|
109
|
+
if (/^#EXT-X-/m.test(text)) return { hls: true, sources: [] };
|
|
110
|
+
const sources = parseCatalog(text, base)
|
|
111
|
+
.map((entry) => entry.source)
|
|
112
|
+
.filter((source) => /^(https?|rtmps?):\/\//i.test(source))
|
|
113
|
+
.slice(0, PLAYLIST_MAX_ENTRIES);
|
|
114
|
+
return { hls: false, sources };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A pasted .m3u, read and turned into a channel's worth of entries. Fetched
|
|
119
|
+
* here rather than by yt-dlp, which would take the first entry and stop, or
|
|
120
|
+
* by ffmpeg, which does not read a plain list at all.
|
|
121
|
+
*/
|
|
122
|
+
export async function resolvePlaylist(
|
|
123
|
+
url: string,
|
|
124
|
+
options: { timeoutMs?: number; fetcher?: typeof fetch } = {},
|
|
125
|
+
): Promise<ResolvedLink | { error: string }> {
|
|
126
|
+
const get = options.fetcher ?? fetch;
|
|
127
|
+
const abort = new AbortController();
|
|
128
|
+
const timer = setTimeout(() => abort.abort(), options.timeoutMs ?? PLAYLIST_FETCH_TIMEOUT_MS);
|
|
129
|
+
let text = "";
|
|
130
|
+
try {
|
|
131
|
+
const answer = await get(url, { signal: abort.signal, headers: { "user-agent": "nixamp" }, redirect: "follow" });
|
|
132
|
+
if (!answer.ok) return { error: `that playlist could not be fetched (HTTP ${answer.status})` };
|
|
133
|
+
text = (await answer.text()).slice(0, PLAYLIST_MAX_BYTES);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
const why = abort.signal.aborted ? "took too long to answer" : ((error as Error).message || "could not be fetched");
|
|
136
|
+
return { error: `that playlist ${why}` };
|
|
137
|
+
} finally {
|
|
138
|
+
clearTimeout(timer);
|
|
139
|
+
}
|
|
140
|
+
const list = playlistFrom(text, url);
|
|
141
|
+
if (list.hls) return directLink(url);
|
|
142
|
+
const [first] = list.sources;
|
|
143
|
+
if (!first) return { error: "that playlist has nothing in it this can play" };
|
|
144
|
+
return {
|
|
145
|
+
title: fileNameOf(url).replace(/\.m3u$/i, "") || "Playlist",
|
|
146
|
+
media: first,
|
|
147
|
+
audio: "",
|
|
148
|
+
// A station: joined where it is, never seeked, and with no end to save.
|
|
149
|
+
live: true,
|
|
150
|
+
duration: 0,
|
|
151
|
+
// Whether there is a picture is the first entry's to say; ffprobe settles it.
|
|
152
|
+
video: true,
|
|
153
|
+
headers: {},
|
|
154
|
+
extractor: "playlist",
|
|
155
|
+
ext: "",
|
|
156
|
+
page: url,
|
|
157
|
+
playlist: list.sources,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
74
161
|
/** A link somebody pasted, or "" when it is not one this can play. */
|
|
75
162
|
export function playableLink(entered: unknown): string {
|
|
76
163
|
if (typeof entered !== "string") return "";
|
|
@@ -313,6 +400,7 @@ export async function resolveLink(
|
|
|
313
400
|
options: { cookies?: string; timeoutMs?: number; format?: string } = {},
|
|
314
401
|
): Promise<ResolvedLink | { error: string }> {
|
|
315
402
|
if (isDirectMedia(url)) return directLink(url);
|
|
403
|
+
if (isPlaylistLink(url)) return resolvePlaylist(url, { timeoutMs: options.timeoutMs });
|
|
316
404
|
// Without yt-dlp, a link is taken as the media it may well be: an IPTV
|
|
317
405
|
// feed has no extension and no page behind it, and ffprobe -- asked next,
|
|
318
406
|
// before anything goes on the air -- tells a stream from a web page in a
|
package/src/server.ts
CHANGED
|
@@ -1052,6 +1052,9 @@ export interface KnownSource {
|
|
|
1052
1052
|
codecs?: Codecs;
|
|
1053
1053
|
position?: number;
|
|
1054
1054
|
live?: boolean;
|
|
1055
|
+
/** A list of entries to play in turn, and which one was on. */
|
|
1056
|
+
playlist?: string[];
|
|
1057
|
+
playlistAt?: number;
|
|
1055
1058
|
}
|
|
1056
1059
|
|
|
1057
1060
|
/** How many times a source that answers nothing is asked, and how far apart. */
|
|
@@ -1117,7 +1120,9 @@ export async function pullChannel(
|
|
|
1117
1120
|
const kind = codecs.video !== "" ? "video" : codecs.audio !== "" ? "audio" : (known.kind ?? "video");
|
|
1118
1121
|
if (assumed) console.log(` "${id}": the source would not say what it holds; carrying it as ${kind}.`);
|
|
1119
1122
|
// A film has a length and a place to go back to; a live source has neither.
|
|
1120
|
-
|
|
1123
|
+
// A list is a station: joined where it is, and never seeked.
|
|
1124
|
+
const playlist = known.playlist && known.playlist.length > 0 ? known.playlist : null;
|
|
1125
|
+
const live = playlist ? true : (known.live ?? !((codecs.duration ?? 0) > 0));
|
|
1121
1126
|
const encode = kind === "video"
|
|
1122
1127
|
? [
|
|
1123
1128
|
// Which streams from which input, when there are two: the picture
|
|
@@ -1135,12 +1140,13 @@ export async function pullChannel(
|
|
|
1135
1140
|
const opening = [...transportInputArgs(source, codecs.container), ...input];
|
|
1136
1141
|
const channel = channels.pull(
|
|
1137
1142
|
id, name, source, encode, kind, true, undefined, opening, kind === "video" ? audio : "",
|
|
1138
|
-
{ live, position: known.position ?? 0 },
|
|
1143
|
+
{ live, position: known.position ?? 0, ...(playlist ? { playlist } : {}) },
|
|
1139
1144
|
// Known before the first dial: whether the source is a transport stream
|
|
1140
1145
|
// decides whether it can be read here for a source-boundary relay.
|
|
1141
1146
|
assumed ? undefined : codecs,
|
|
1142
1147
|
);
|
|
1143
1148
|
if (channel && !assumed) channel.info.codecs = codecs;
|
|
1149
|
+
if (channel && playlist && known.playlistAt !== undefined) channel.info.playlistAt = known.playlistAt;
|
|
1144
1150
|
// What comes out, as opposed to what went in. An H.265 source copied
|
|
1145
1151
|
// through stays H.265; one re-encoded arrives as H.264, and a packager
|
|
1146
1152
|
// told otherwise would cut fMP4 segments for a stream that did not need
|
|
@@ -1184,11 +1190,16 @@ function shownLink(channelId: string, link: ResolvedLink, channel?: ChannelInfo)
|
|
|
1184
1190
|
channel: channelId,
|
|
1185
1191
|
name: channel?.name ?? link.title,
|
|
1186
1192
|
live,
|
|
1187
|
-
|
|
1193
|
+
// Whether there is a picture is the channel's answer where there is one:
|
|
1194
|
+
// a list is guessed at as video until its first entry has been probed,
|
|
1195
|
+
// and a station of podcasts opened a video element for nothing.
|
|
1196
|
+
video: channel?.kind ? channel.kind !== "audio" : link.video,
|
|
1188
1197
|
duration: link.duration,
|
|
1189
1198
|
extractor: link.extractor,
|
|
1190
1199
|
// A live has no whole to keep; a bare file can be fetched by the browser itself.
|
|
1191
1200
|
download: !live && link.extractor !== "direct",
|
|
1201
|
+
// How many things a list holds, for the page to say.
|
|
1202
|
+
entries: link.playlist?.length ?? 0,
|
|
1192
1203
|
};
|
|
1193
1204
|
}
|
|
1194
1205
|
|
|
@@ -1434,6 +1445,12 @@ export interface HandlerOptions {
|
|
|
1434
1445
|
ffmpeg?: string[];
|
|
1435
1446
|
/** Where ffprobe is, for asking what is inside a file before re-encoding it. */
|
|
1436
1447
|
ffprobe?: string[];
|
|
1448
|
+
/**
|
|
1449
|
+
* Whether this server can carry a channel at all: false where no ffmpeg
|
|
1450
|
+
* was found, as on the hosted directory, which then says so instead of
|
|
1451
|
+
* resolving a link, probing it, and blaming the site.
|
|
1452
|
+
*/
|
|
1453
|
+
carries?: boolean;
|
|
1437
1454
|
/** yt-dlp, which turns a pasted page into a media address. Null when there is none. */
|
|
1438
1455
|
ytdlp?: string[] | null;
|
|
1439
1456
|
/** Channels as HLS, for Safari on a phone, which plays a live stream no other way. */
|
|
@@ -2973,6 +2990,10 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
2973
2990
|
// one nobody can dial is not worth showing.
|
|
2974
2991
|
code: state?.code ?? "",
|
|
2975
2992
|
url: state?.url ?? "",
|
|
2993
|
+
// Whether a link can go live here at all. The hosted directory
|
|
2994
|
+
// has no ffmpeg, and a page that offered to go live on it was
|
|
2995
|
+
// offering something that always failed.
|
|
2996
|
+
carries: options.carries !== false && Boolean(options.channels),
|
|
2976
2997
|
},
|
|
2977
2998
|
channels: (options.channels?.list() ?? []).map((one) => ({
|
|
2978
2999
|
id: one.id,
|
|
@@ -2989,6 +3010,8 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
2989
3010
|
// How it has been going, for whoever may do something about it.
|
|
2990
3011
|
redials: one.redials ?? 0,
|
|
2991
3012
|
error: one.error ?? "",
|
|
3013
|
+
// For a list: how long it is, and which entry is on, from 0.
|
|
3014
|
+
...(one.playlist ? { entries: one.playlist.length, entry: one.playlistAt ?? 0 } : {}),
|
|
2992
3015
|
// The member who put it on, when one did: theirs to take off.
|
|
2993
3016
|
startedBy: one.startedBy ?? "",
|
|
2994
3017
|
})),
|
|
@@ -3163,7 +3186,12 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
3163
3186
|
options.channels.keep(channelId);
|
|
3164
3187
|
options.rememberChannels?.(rememberedNow(options.channels));
|
|
3165
3188
|
void options.live?.announce?.();
|
|
3166
|
-
|
|
3189
|
+
// Whether there is a picture, so the page can join it in the right
|
|
3190
|
+
// element straight away rather than guessing.
|
|
3191
|
+
json(response, 200, {
|
|
3192
|
+
channel: channelId, name: entry.title, kind: entry.live ? "live" : "vod",
|
|
3193
|
+
video: options.channels.kindOf(channelId) !== "audio",
|
|
3194
|
+
});
|
|
3167
3195
|
return;
|
|
3168
3196
|
}
|
|
3169
3197
|
|
|
@@ -3258,6 +3286,12 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
3258
3286
|
json(response, 503, { error: "this server cannot carry channels" });
|
|
3259
3287
|
return;
|
|
3260
3288
|
}
|
|
3289
|
+
if (options.carries === false) {
|
|
3290
|
+
json(response, 503, {
|
|
3291
|
+
error: `${options.serverName ?? "this server"} has no ffmpeg, so it cannot carry a link. Pick a server to go live on.`,
|
|
3292
|
+
});
|
|
3293
|
+
return;
|
|
3294
|
+
}
|
|
3261
3295
|
const channelId = linkChannelId(link);
|
|
3262
3296
|
const known = links.get(link);
|
|
3263
3297
|
// A member's is always a live: a decoder started on somebody else's
|
|
@@ -3333,6 +3367,7 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
3333
3367
|
const started = await pullChannel(
|
|
3334
3368
|
options.channels, options.ffprobe ?? ["ffprobe"], channelId, resolved.title, resolved.media,
|
|
3335
3369
|
inputArgsFor(resolved.headers), resolved.audio,
|
|
3370
|
+
resolved.playlist ? { playlist: resolved.playlist } : {},
|
|
3336
3371
|
);
|
|
3337
3372
|
if (!started) {
|
|
3338
3373
|
json(response, 409, { error: "that link is already starting" });
|
|
@@ -3464,7 +3499,7 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
3464
3499
|
options.channels.keep(channelId);
|
|
3465
3500
|
options.rememberChannels?.(rememberedNow(options.channels));
|
|
3466
3501
|
void options.live?.announce?.();
|
|
3467
|
-
json(response, 200, { channel: channelId, name });
|
|
3502
|
+
json(response, 200, { channel: channelId, name, video: options.channels.kindOf(channelId) !== "audio" });
|
|
3468
3503
|
return;
|
|
3469
3504
|
}
|
|
3470
3505
|
|
|
@@ -4848,6 +4883,7 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
4848
4883
|
...(one.codecs ? { codecs: one.codecs } : {}),
|
|
4849
4884
|
...(one.position !== undefined ? { position: one.position } : {}),
|
|
4850
4885
|
...(one.live !== undefined ? { live: one.live } : {}),
|
|
4886
|
+
...(one.playlist ? { playlist: one.playlist, playlistAt: one.playlistAt ?? 0 } : {}),
|
|
4851
4887
|
}).then((channel) => {
|
|
4852
4888
|
if (!channel) console.log(` "${one.id}" is already on.`);
|
|
4853
4889
|
});
|
|
@@ -4859,7 +4895,8 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
4859
4895
|
let lastRemembered = "";
|
|
4860
4896
|
setInterval(() => {
|
|
4861
4897
|
const now = rememberedNow(channels);
|
|
4862
|
-
|
|
4898
|
+
// A list moves on without a position: which entry is on is the thing to keep.
|
|
4899
|
+
if (!now.some((one) => one.position !== undefined || one.playlist)) return;
|
|
4863
4900
|
const text = JSON.stringify(now);
|
|
4864
4901
|
if (text === lastRemembered) return;
|
|
4865
4902
|
lastRemembered = text;
|
|
@@ -5290,6 +5327,7 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
5290
5327
|
// A cookie jar beside the state, when the operator has put one there,
|
|
5291
5328
|
// for the sites that will not talk to a datacenter without one.
|
|
5292
5329
|
ytdlp: tools.ytdlp ?? null,
|
|
5330
|
+
carries: tools.carries !== false,
|
|
5293
5331
|
cookies: cookiesFile(),
|
|
5294
5332
|
hls,
|
|
5295
5333
|
compression,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./index-
|
|
1
|
+
import{t as e}from"./index-CwcjINDz.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};
|