@boy-offi9-inc/tidepull 0.4.2 → 0.6.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 +3 -3
- package/dist/cliutil.d.ts +0 -8
- package/dist/cliutil.js +0 -10
- package/dist/cookies.d.ts +0 -5
- package/dist/cookies.js +0 -10
- package/dist/core/downloader.d.ts +9 -8
- package/dist/core/downloader.js +56 -14
- package/dist/core/errors.d.ts +0 -2
- package/dist/core/errors.js +0 -2
- package/dist/core/events.d.ts +0 -2
- package/dist/core/hls.d.ts +8 -0
- package/dist/core/hls.js +43 -5
- package/dist/core/http.d.ts +0 -13
- package/dist/core/http.js +0 -7
- package/dist/core/meter.d.ts +0 -1
- package/dist/core/meter.js +0 -1
- package/dist/core/pipeline.d.ts +1 -13
- package/dist/core/pipeline.js +16 -8
- package/dist/core/selector.d.ts +0 -10
- package/dist/core/selector.js +0 -1
- package/dist/core/template.d.ts +0 -1
- package/dist/core/template.js +0 -1
- package/dist/core/types.d.ts +7 -13
- package/dist/dash/index.js +1 -6
- package/dist/dash/parse.d.ts +0 -3
- package/dist/dash/parse.js +1 -3
- package/dist/dash/xml.js +0 -1
- package/dist/extractors/direct.js +0 -1
- package/dist/extractors/generic.d.ts +0 -1
- package/dist/extractors/generic.js +0 -2
- package/dist/extractors/hls.js +6 -3
- package/dist/extractors/index.d.ts +0 -1
- package/dist/extractors/index.js +0 -1
- package/dist/feeds.d.ts +0 -2
- package/dist/feeds.js +0 -9
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/loader.d.ts +0 -2
- package/dist/loader.js +0 -3
- package/dist/main.d.ts +0 -1
- package/dist/main.js +3 -8
- package/dist/playlist.d.ts +0 -18
- package/dist/playlist.js +0 -15
- package/dist/plugins.d.ts +0 -2
- package/dist/plugins.js +0 -2
- package/dist/tidepull.d.ts +0 -21
- package/dist/tidepull.js +0 -18
- package/dist/ui/banner.d.ts +0 -1
- package/dist/ui/banner.js +0 -2
- package/dist/ui/format.d.ts +0 -1
- package/dist/ui/format.js +0 -1
- package/dist/ui/log.d.ts +0 -2
- package/dist/ui/log.js +0 -2
- package/dist/ui/render.d.ts +0 -2
- package/dist/ui/render.js +0 -3
- package/dist/ui/spinner.d.ts +0 -5
- package/dist/ui/spinner.js +0 -5
- package/dist/ui/theme.d.ts +0 -5
- package/dist/ui/theme.js +0 -2
- package/package.json +1 -1
package/dist/core/pipeline.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mkdir, rename, rm, stat } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { downloadDash, downloadHls, downloadHttp, RateLimiter } from "./downloader.js";
|
|
3
|
+
import { downloadDash, downloadHls, downloadHlsSubtitles, downloadHttp, RateLimiter } from "./downloader.js";
|
|
4
4
|
import { TidepullError } from "./errors.js";
|
|
5
5
|
import { findFfmpeg, mergeStreams, remux } from "./ffmpeg.js";
|
|
6
6
|
import { Meter } from "./meter.js";
|
|
@@ -8,7 +8,6 @@ import { selectFormats } from "./selector.js";
|
|
|
8
8
|
import { renderTemplate } from "./template.js";
|
|
9
9
|
export const DEFAULT_OUTPUT = "%(title)s [%(id)s].%(ext)s";
|
|
10
10
|
export const isPlaylist = (x) => x.kind === "playlist";
|
|
11
|
-
/** Resolves a URL with the first matching extractor: a single item (Info) or a Playlist. */
|
|
12
11
|
export async function resolveUrl(rawUrl, ctx) {
|
|
13
12
|
let url;
|
|
14
13
|
try {
|
|
@@ -32,7 +31,6 @@ export async function resolveUrl(rawUrl, ctx) {
|
|
|
32
31
|
throw new TidepullError(`Extractor "${ex.name}" returned no formats`);
|
|
33
32
|
return result;
|
|
34
33
|
}
|
|
35
|
-
/** Like resolveUrl, but a playlist is an error (callers that need one item). */
|
|
36
34
|
export async function extractInfo(rawUrl, ctx) {
|
|
37
35
|
const result = await resolveUrl(rawUrl, ctx);
|
|
38
36
|
if (isPlaylist(result)) {
|
|
@@ -40,14 +38,15 @@ export async function extractInfo(rawUrl, ctx) {
|
|
|
40
38
|
}
|
|
41
39
|
return result;
|
|
42
40
|
}
|
|
43
|
-
/** Drops undefined keys so events serialize cleanly. */
|
|
44
41
|
const compact = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
|
|
45
42
|
const scalars = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => ["string", "number", "boolean"].includes(typeof v)));
|
|
46
|
-
/** Selects formats per opts.format, downloads them, merges/remuxes with ffmpeg if needed. Returns the final file path. */
|
|
47
43
|
export async function downloadInfo(info, opts, ctx) {
|
|
48
44
|
const chosen = selectFormats(opts.format, info.formats);
|
|
49
45
|
if (!chosen)
|
|
50
46
|
throw new TidepullError(`Requested format is not available: ${opts.format} (try --list-formats)`);
|
|
47
|
+
if (opts.writeSubs && !info.subtitles?.length) {
|
|
48
|
+
ctx.log.info("download", "no subtitle tracks are available for this media");
|
|
49
|
+
}
|
|
51
50
|
const ffmpeg = findFfmpeg(opts.ffmpeg);
|
|
52
51
|
const merging = chosen.length > 1;
|
|
53
52
|
if (merging && !ffmpeg) {
|
|
@@ -62,7 +61,6 @@ export async function downloadInfo(info, opts, ctx) {
|
|
|
62
61
|
resolution: chosen[0].height ? `${chosen[0].width ?? "?"}x${chosen[0].height}` : "audio only",
|
|
63
62
|
ext: predictedExt,
|
|
64
63
|
};
|
|
65
|
-
// Default name: just the title when it equals the id (direct files); playlist items get their number in front.
|
|
66
64
|
const defaultName = String(info.title) === String(info.id) ? "%(title)s.%(ext)s" : DEFAULT_OUTPUT;
|
|
67
65
|
const template = opts.output ?? (opts.fields?.playlist_index !== undefined ? `%(playlist_index)02d - ${defaultName}` : defaultName);
|
|
68
66
|
let target = path.resolve(opts.paths, renderTemplate(template, fields));
|
|
@@ -106,7 +104,7 @@ export async function downloadInfo(info, opts, ctx) {
|
|
|
106
104
|
if (!merging) {
|
|
107
105
|
const ext = await fetchOne(chosen[0], target);
|
|
108
106
|
if (ext !== path.extname(target).slice(1)) {
|
|
109
|
-
const fixed = `${base}.${ext}`;
|
|
107
|
+
const fixed = `${base}.${ext}`;
|
|
110
108
|
await rename(target, fixed);
|
|
111
109
|
target = fixed;
|
|
112
110
|
}
|
|
@@ -119,7 +117,6 @@ export async function downloadInfo(info, opts, ctx) {
|
|
|
119
117
|
tmp.push(dest);
|
|
120
118
|
await fetchOne(f, dest);
|
|
121
119
|
}
|
|
122
|
-
// video stream first, audio second
|
|
123
120
|
const [v, a] = chosen[0].vcodec !== "none" ? [tmp[0], tmp[1]] : [tmp[1], tmp[0]];
|
|
124
121
|
ctx.emit({ type: "merge", output: target });
|
|
125
122
|
await mergeStreams(ffmpeg, v, a, target);
|
|
@@ -141,5 +138,16 @@ export async function downloadInfo(info, opts, ctx) {
|
|
|
141
138
|
await rm(target, { force: true });
|
|
142
139
|
target = out;
|
|
143
140
|
}
|
|
141
|
+
if (opts.writeSubs && info.subtitles?.length) {
|
|
142
|
+
const stemBase = target.slice(0, target.length - path.extname(target).length);
|
|
143
|
+
for (const sub of info.subtitles) {
|
|
144
|
+
const dest = `${stemBase}.${sub.lang.replace(/\W+/g, "_")}.vtt`;
|
|
145
|
+
ctx.emit({ type: "start", format_id: `subtitle-${sub.lang}`, dest });
|
|
146
|
+
await downloadHlsSubtitles(sub.url, dest, {
|
|
147
|
+
http: ctx.http, headers: opts.headers, signal: ctx.signal, onProgress: () => { }, concurrency: 1,
|
|
148
|
+
});
|
|
149
|
+
ctx.emit({ type: "finish", format_id: `subtitle-${sub.lang}`, bytes: 0, seconds: 0 });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
144
152
|
return target;
|
|
145
153
|
}
|
package/dist/core/selector.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Format selector syntax.
|
|
3
|
-
* b / best best pre-merged format bv / bestvideo best video-only
|
|
4
|
-
* w / worst worst pre-merged format ba / bestaudio best audio-only
|
|
5
|
-
* bv* / ba* best with video / with audio <format_id> exact id
|
|
6
|
-
* a+b merge two formats a/b fallback if a unavailable
|
|
7
|
-
* x[height<=720] filters: <= >= < > = != (add ? after the op to also accept missing fields)
|
|
8
|
-
* (a/b)+c grouping
|
|
9
|
-
*/
|
|
10
1
|
import type { Format } from "./types.js";
|
|
11
2
|
export declare const DEFAULT_FORMAT = "bv*+ba/b";
|
|
12
3
|
interface Filter {
|
|
@@ -27,6 +18,5 @@ type Node = {
|
|
|
27
18
|
options: Node[];
|
|
28
19
|
};
|
|
29
20
|
export declare function parseSelector(sel: string): Node;
|
|
30
|
-
/** Returns the chosen formats (2+ means "merge these"), or undefined if nothing matches. */
|
|
31
21
|
export declare function selectFormats(selector: string, formats: Format[]): Format[] | undefined;
|
|
32
22
|
export {};
|
package/dist/core/selector.js
CHANGED
|
@@ -160,7 +160,6 @@ function evaluate(n, fs) {
|
|
|
160
160
|
return undefined;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
/** Returns the chosen formats (2+ means "merge these"), or undefined if nothing matches. */
|
|
164
163
|
export function selectFormats(selector, formats) {
|
|
165
164
|
return evaluate(parseSelector(selector), formats);
|
|
166
165
|
}
|
package/dist/core/template.d.ts
CHANGED
package/dist/core/template.js
CHANGED
package/dist/core/types.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Emit, Log } from "./events.js";
|
|
2
2
|
import type { Http } from "./http.js";
|
|
3
3
|
export type Protocol = "https" | "hls" | "dash";
|
|
4
|
-
/** One downloadable stream. */
|
|
5
4
|
export interface Format {
|
|
6
5
|
format_id: string;
|
|
7
6
|
url: string;
|
|
@@ -10,50 +9,46 @@ export interface Format {
|
|
|
10
9
|
width?: number;
|
|
11
10
|
height?: number;
|
|
12
11
|
fps?: number;
|
|
13
|
-
/** "none" = no video track. "unknown" = present but codec not known. */
|
|
14
12
|
vcodec: string;
|
|
15
|
-
/** "none" = no audio track. */
|
|
16
13
|
acodec: string;
|
|
17
|
-
/** total bitrate, kbit/s */
|
|
18
14
|
tbr?: number;
|
|
19
|
-
/** audio bitrate, kbit/s */
|
|
20
15
|
abr?: number;
|
|
21
16
|
filesize?: number;
|
|
22
17
|
format_note?: string;
|
|
23
18
|
http_headers?: Record<string, string>;
|
|
24
|
-
/** dash: init segment URL (written first) */
|
|
25
19
|
init?: string;
|
|
26
|
-
/** dash: media segment URLs in order */
|
|
27
20
|
fragments?: string[];
|
|
28
21
|
}
|
|
29
|
-
|
|
22
|
+
export interface Subtitle {
|
|
23
|
+
lang: string;
|
|
24
|
+
url: string;
|
|
25
|
+
protocol: "hls";
|
|
26
|
+
isDefault?: boolean;
|
|
27
|
+
}
|
|
30
28
|
export interface Info {
|
|
31
29
|
id: string;
|
|
32
30
|
title: string;
|
|
33
31
|
extractor: string;
|
|
34
32
|
webpage_url: string;
|
|
35
33
|
formats: Format[];
|
|
34
|
+
subtitles?: Subtitle[];
|
|
36
35
|
thumbnail?: string;
|
|
37
36
|
duration?: number;
|
|
38
37
|
uploader?: string;
|
|
39
38
|
upload_date?: string;
|
|
40
39
|
[key: string]: unknown;
|
|
41
40
|
}
|
|
42
|
-
/** Passed to every extractor call. */
|
|
43
41
|
export interface Ctx {
|
|
44
42
|
http: Http;
|
|
45
43
|
log: Log;
|
|
46
44
|
emit: Emit;
|
|
47
|
-
/** Ordered extractor list (plugins, built-ins, generic last). */
|
|
48
45
|
extractors: readonly Extractor[];
|
|
49
46
|
signal?: AbortSignal;
|
|
50
47
|
}
|
|
51
|
-
/** One item of a playlist. It is extracted on its own when it is downloaded. */
|
|
52
48
|
export interface PlaylistEntry {
|
|
53
49
|
url: string;
|
|
54
50
|
title?: string;
|
|
55
51
|
}
|
|
56
|
-
/** A list of items found at one URL (a feed, a playlist file). */
|
|
57
52
|
export interface Playlist {
|
|
58
53
|
kind: "playlist";
|
|
59
54
|
id: string;
|
|
@@ -62,7 +57,6 @@ export interface Playlist {
|
|
|
62
57
|
webpage_url: string;
|
|
63
58
|
entries: PlaylistEntry[];
|
|
64
59
|
}
|
|
65
|
-
/** The extractor contract. One file per site. */
|
|
66
60
|
export interface Extractor {
|
|
67
61
|
readonly name: string;
|
|
68
62
|
suitable(url: URL): boolean;
|
package/dist/dash/index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Opt-in DASH (VOD) support.
|
|
3
|
-
* import dash from "@boy-offi9-inc/tidepull/dash";
|
|
4
|
-
* createTidepull({ plugins: [dash] });
|
|
5
|
-
*/
|
|
6
1
|
import { TidepullError } from "../core/errors.js";
|
|
7
2
|
import { extOf, splitCodecs, stem } from "../extractors/util.js";
|
|
8
3
|
import { definePlugin } from "../plugins.js";
|
|
@@ -36,7 +31,7 @@ export async function extractDash(url, ctx) {
|
|
|
36
31
|
const formats = [];
|
|
37
32
|
for (const r of mpd.reps) {
|
|
38
33
|
if (r.kind === "other")
|
|
39
|
-
continue;
|
|
34
|
+
continue;
|
|
40
35
|
const { v, a } = splitCodecs(r.codecs);
|
|
41
36
|
const video = r.kind === "video";
|
|
42
37
|
const f = {
|
package/dist/dash/parse.d.ts
CHANGED
|
@@ -8,10 +8,8 @@ export interface DashRep {
|
|
|
8
8
|
height?: number;
|
|
9
9
|
fps?: number;
|
|
10
10
|
lang?: string;
|
|
11
|
-
/** fragmented: init segment + media segments */
|
|
12
11
|
init?: string;
|
|
13
12
|
fragments?: string[];
|
|
14
|
-
/** whole-file representation (SegmentBase / plain BaseURL) */
|
|
15
13
|
single?: string;
|
|
16
14
|
}
|
|
17
15
|
export interface DashManifest {
|
|
@@ -21,7 +19,6 @@ export interface DashManifest {
|
|
|
21
19
|
skipped: string[];
|
|
22
20
|
}
|
|
23
21
|
export declare function parseIsoDuration(s?: string): number | undefined;
|
|
24
|
-
/** $RepresentationID$, $Number$, $Bandwidth$, $Time$ (+ %0Nd width), $$ */
|
|
25
22
|
export declare function fillTemplate(tpl: string, v: {
|
|
26
23
|
RepresentationID: string;
|
|
27
24
|
Bandwidth: number;
|
package/dist/dash/parse.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Static (VOD) MPEG-DASH: SegmentTemplate (number / timeline), SegmentList, single-file SegmentBase. No DRM, no live. */
|
|
2
1
|
import { TidepullError } from "../core/errors.js";
|
|
3
2
|
import { child, kids, parseXml } from "./xml.js";
|
|
4
3
|
const MAX_FRAGMENTS = 50_000;
|
|
@@ -23,7 +22,6 @@ function resolve(base, rel) {
|
|
|
23
22
|
throw new TidepullError(`Refusing non-http(s) URL in manifest: ${u.protocol}`);
|
|
24
23
|
return u.href;
|
|
25
24
|
}
|
|
26
|
-
/** $RepresentationID$, $Number$, $Bandwidth$, $Time$ (+ %0Nd width), $$ */
|
|
27
25
|
export function fillTemplate(tpl, v) {
|
|
28
26
|
return tpl.replace(/\$(RepresentationID|Number|Bandwidth|Time)(?:%0(\d+)d)?\$|\$\$/g, (m, key, width) => {
|
|
29
27
|
if (m === "$$")
|
|
@@ -127,7 +125,7 @@ export function parseMpd(text, manifestUrl) {
|
|
|
127
125
|
r.fragments = kids(listNode, "SegmentURL").map((u) => resolve(baseR, u.attrs.media));
|
|
128
126
|
}
|
|
129
127
|
else {
|
|
130
|
-
r.single = baseR;
|
|
128
|
+
r.single = baseR;
|
|
131
129
|
}
|
|
132
130
|
out.reps.push(r);
|
|
133
131
|
}
|
package/dist/dash/xml.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Minimal XML parser: elements, attributes and text. DTDs and custom entities are not expanded; namespace prefixes are dropped. */
|
|
2
1
|
import { TidepullError } from "../core/errors.js";
|
|
3
2
|
const ENT = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
|
|
4
3
|
const decode = (s) => s.replace(/&(?:#x([0-9a-f]+)|#(\d+)|(\w+));/gi, (m, hex, dec, name) => {
|
|
@@ -9,7 +9,6 @@ export const directExtractor = {
|
|
|
9
9
|
};
|
|
10
10
|
export async function extractDirect(url, ctx) {
|
|
11
11
|
const ext = extOf(url.pathname);
|
|
12
|
-
// Try HEAD first; some servers reject it, so fall back to a 1-byte ranged GET.
|
|
13
12
|
let res = await ctx.http.request(url.href, { method: "HEAD" });
|
|
14
13
|
let size = res.ok ? Number(res.headers.get("content-length")) || undefined : undefined;
|
|
15
14
|
if (!res.ok) {
|
|
@@ -33,7 +33,6 @@ function findCandidates(html, base) {
|
|
|
33
33
|
found.push(new URL(decodeEntities(u).trim(), base).href);
|
|
34
34
|
}
|
|
35
35
|
catch {
|
|
36
|
-
/* ignore bad URLs */
|
|
37
36
|
}
|
|
38
37
|
};
|
|
39
38
|
for (const m of html.matchAll(/<meta\b[^>]*>/gi)) {
|
|
@@ -58,7 +57,6 @@ async function extractOne(u, ctx) {
|
|
|
58
57
|
throw new TidepullError(`${u.href} is a playlist, not a single media item`);
|
|
59
58
|
return result;
|
|
60
59
|
}
|
|
61
|
-
/** Fallback: look at the page itself (media content-type, og:video, <video>, bare media URLs). */
|
|
62
60
|
export const genericExtractor = {
|
|
63
61
|
name: "generic",
|
|
64
62
|
suitable: () => true,
|
package/dist/extractors/hls.js
CHANGED
|
@@ -11,8 +11,9 @@ export async function extractHls(url, ctx) {
|
|
|
11
11
|
if (!text.trimStart().startsWith("#EXTM3U"))
|
|
12
12
|
throw new TidepullError(`Not an HLS playlist: ${url.href}`);
|
|
13
13
|
const formats = [];
|
|
14
|
+
let master;
|
|
14
15
|
if (isMasterPlaylist(text)) {
|
|
15
|
-
|
|
16
|
+
master = parseMaster(text, finalUrl);
|
|
16
17
|
const audioGroups = new Map();
|
|
17
18
|
for (const r of master.renditions)
|
|
18
19
|
if (r.type === "AUDIO" && r.uri)
|
|
@@ -28,7 +29,6 @@ export async function extractHls(url, ctx) {
|
|
|
28
29
|
let audioCodec;
|
|
29
30
|
for (const v of master.variants) {
|
|
30
31
|
const { v: vc, a: ac } = splitCodecs(v.codecs);
|
|
31
|
-
// Variant points at an external audio group and lists no audio codec => video-only stream.
|
|
32
32
|
const external = !!v.audioGroup && audioGroups.has(v.audioGroup) && !ac && !!v.codecs;
|
|
33
33
|
if (ac)
|
|
34
34
|
audioCodec ??= ac;
|
|
@@ -64,9 +64,12 @@ export async function extractHls(url, ctx) {
|
|
|
64
64
|
else {
|
|
65
65
|
formats.push({ format_id: "hls", url: finalUrl, ext: "ts", protocol: "hls", vcodec: "unknown", acodec: "unknown" });
|
|
66
66
|
}
|
|
67
|
+
const subtitles = master?.renditions
|
|
68
|
+
.filter((r) => r.type === "SUBTITLES" && r.uri)
|
|
69
|
+
.map((r) => ({ lang: r.language || r.name, url: r.uri, protocol: "hls", isDefault: r.isDefault }));
|
|
67
70
|
let name = stem(url.pathname);
|
|
68
71
|
if (/^(index|master|playlist|manifest|stream|main)$/i.test(name)) {
|
|
69
72
|
name = url.pathname.split("/").filter(Boolean).slice(-2, -1)[0] ?? url.hostname;
|
|
70
73
|
}
|
|
71
|
-
return { id: name || url.hostname, title: name || url.hostname, extractor: "hls", webpage_url: url.href, formats };
|
|
74
|
+
return { id: name || url.hostname, title: name || url.hostname, extractor: "hls", webpage_url: url.href, formats, ...(subtitles?.length ? { subtitles } : {}) };
|
|
72
75
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Extractor } from "../core/types.js";
|
|
2
2
|
import type { TidepullPlugin } from "../plugins.js";
|
|
3
3
|
export declare const builtinExtractors: readonly Extractor[];
|
|
4
|
-
/** First `suitable()` match wins: plugin extractors (in order), then built-ins, with the generic fallback always last. */
|
|
5
4
|
export declare function buildRegistry(plugins?: readonly TidepullPlugin[]): Extractor[];
|
package/dist/extractors/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { directExtractor } from "./direct.js";
|
|
|
2
2
|
import { genericExtractor } from "./generic.js";
|
|
3
3
|
import { hlsExtractor } from "./hls.js";
|
|
4
4
|
export const builtinExtractors = [hlsExtractor, directExtractor, genericExtractor];
|
|
5
|
-
/** First `suitable()` match wins: plugin extractors (in order), then built-ins, with the generic fallback always last. */
|
|
6
5
|
export function buildRegistry(plugins = []) {
|
|
7
6
|
const specific = builtinExtractors.filter((e) => e !== genericExtractor);
|
|
8
7
|
return [...plugins.flatMap((p) => p.extractors ?? []), ...specific, genericExtractor];
|
package/dist/feeds.d.ts
CHANGED
|
@@ -3,9 +3,7 @@ export interface ParsedList {
|
|
|
3
3
|
title: string;
|
|
4
4
|
entries: PlaylistEntry[];
|
|
5
5
|
}
|
|
6
|
-
/** Items with a media enclosure from an RSS 2.0, RSS 1.0 or Atom feed. URLs are resolved against `base`. */
|
|
7
6
|
export declare function parseFeed(text: string, base: string): ParsedList;
|
|
8
|
-
/** Entries of an .m3u playlist file (#EXTINF titles, #PLAYLIST name). Only http(s) URLs are kept. */
|
|
9
7
|
export declare function parseM3u(text: string, base: string): ParsedList;
|
|
10
8
|
export declare const rssExtractor: {
|
|
11
9
|
name: string;
|
package/dist/feeds.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Playlist sources (opt-in: "@boy-offi9-inc/tidepull/feeds"): RSS/Atom feeds with media enclosures, and .m3u playlist files.
|
|
3
|
-
* import feeds from "@boy-offi9-inc/tidepull/feeds";
|
|
4
|
-
* createTidepull({ plugins: [feeds] });
|
|
5
|
-
* Each media URL becomes one playlist entry, extracted on its own when it is downloaded.
|
|
6
|
-
*/
|
|
7
1
|
import { TidepullError } from "./core/errors.js";
|
|
8
2
|
import { child, kids, parseXml } from "./dash/xml.js";
|
|
9
3
|
import { extOf, stem } from "./extractors/util.js";
|
|
@@ -11,7 +5,6 @@ import { definePlugin } from "./plugins.js";
|
|
|
11
5
|
const MAX_BYTES = 10 * 1024 * 1024;
|
|
12
6
|
const MAX_ENTRIES = 10_000;
|
|
13
7
|
const isMedia = (type) => !type || /^(audio|video)\//i.test(type) || /octet-stream/i.test(type);
|
|
14
|
-
/** The media URL of an RSS item or Atom entry: <enclosure>, an Atom rel="enclosure" link, or Media RSS <media:content>. */
|
|
15
8
|
function mediaUrl(item) {
|
|
16
9
|
const candidates = [
|
|
17
10
|
...kids(item, "enclosure").map((e) => ({ url: e.attrs.url, type: e.attrs.type })),
|
|
@@ -38,7 +31,6 @@ function toEntry(raw, title, base, seen) {
|
|
|
38
31
|
seen.add(url);
|
|
39
32
|
return title ? { url, title } : { url };
|
|
40
33
|
}
|
|
41
|
-
/** Items with a media enclosure from an RSS 2.0, RSS 1.0 or Atom feed. URLs are resolved against `base`. */
|
|
42
34
|
export function parseFeed(text, base) {
|
|
43
35
|
const root = parseXml(text);
|
|
44
36
|
let title;
|
|
@@ -63,7 +55,6 @@ export function parseFeed(text, base) {
|
|
|
63
55
|
}
|
|
64
56
|
return { title: title.trim(), entries };
|
|
65
57
|
}
|
|
66
|
-
/** Entries of an .m3u playlist file (#EXTINF titles, #PLAYLIST name). Only http(s) URLs are kept. */
|
|
67
58
|
export function parseM3u(text, base) {
|
|
68
59
|
let title = "";
|
|
69
60
|
let pending;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Public library API. Everything not exported here is internal. */
|
|
2
1
|
export { Tidepull, createTidepull } from "./tidepull.js";
|
|
3
2
|
export type { TidepullOptions, CallOptions, Listener } from "./tidepull.js";
|
|
4
3
|
export { definePlugin, PLUGIN_API_VERSION } from "./plugins.js";
|
package/dist/index.js
CHANGED
package/dist/loader.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { type TidepullPlugin } from "./plugins.js";
|
|
2
2
|
export declare function validatePlugin(p: unknown, source: string): TidepullPlugin;
|
|
3
|
-
/** SECURITY: this executes the file's code with your privileges. Only load plugins you trust. */
|
|
4
3
|
export declare function loadPlugin(file: string): Promise<TidepullPlugin>;
|
|
5
|
-
/** Each path may be a plugin file, or a directory of plugin files and/or `<name>/index.*` folders (not recursive). */
|
|
6
4
|
export declare function loadPlugins(paths: string[]): Promise<TidepullPlugin[]>;
|
|
7
5
|
export declare function defaultPluginDir(env?: NodeJS.ProcessEnv): string;
|
package/dist/loader.js
CHANGED
|
@@ -6,7 +6,6 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
6
6
|
}
|
|
7
7
|
return path;
|
|
8
8
|
};
|
|
9
|
-
/** Loads plugins from disk (Node only). Opt-in: `import { loadPlugins } from "@boy-offi9-inc/tidepull/loader"`. */
|
|
10
9
|
import { readdir, stat } from "node:fs/promises";
|
|
11
10
|
import os from "node:os";
|
|
12
11
|
import path from "node:path";
|
|
@@ -29,7 +28,6 @@ export function validatePlugin(p, source) {
|
|
|
29
28
|
}
|
|
30
29
|
return o;
|
|
31
30
|
}
|
|
32
|
-
/** SECURITY: this executes the file's code with your privileges. Only load plugins you trust. */
|
|
33
31
|
export async function loadPlugin(file) {
|
|
34
32
|
let mod;
|
|
35
33
|
try {
|
|
@@ -42,7 +40,6 @@ export async function loadPlugin(file) {
|
|
|
42
40
|
}
|
|
43
41
|
const FILE_RE = /\.(?:m?js|cjs|mts|ts)$/;
|
|
44
42
|
const INDEX_RE = /^index\.(?:m?js|mts|ts)$/;
|
|
45
|
-
/** Each path may be a plugin file, or a directory of plugin files and/or `<name>/index.*` folders (not recursive). */
|
|
46
43
|
export async function loadPlugins(paths) {
|
|
47
44
|
const out = [];
|
|
48
45
|
for (const p of paths) {
|
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -16,7 +16,6 @@ import { humanRenderer, jsonRenderer } from "./ui/render.js";
|
|
|
16
16
|
import { renderBanner } from "./ui/banner.js";
|
|
17
17
|
import { pickTheme, THEME_NAMES } from "./ui/theme.js";
|
|
18
18
|
import { Spinner } from "./ui/spinner.js";
|
|
19
|
-
/** Package version, read from package.json. */
|
|
20
19
|
export const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
21
20
|
const HELP = `tidepull ${VERSION}: a minimal media downloader
|
|
22
21
|
|
|
@@ -59,6 +58,7 @@ Config:
|
|
|
59
58
|
|
|
60
59
|
Network:
|
|
61
60
|
--limit-rate RATE Maximum download speed per file, e.g. 500K or 1.5M
|
|
61
|
+
--write-subs Download subtitle tracks (HLS SUBTITLES renditions) as .vtt next to the media
|
|
62
62
|
--cookies FILE Send cookies from a Netscape cookies.txt file, only to the hosts they belong to
|
|
63
63
|
-N, --concurrent-fragments N HLS segments fetched in parallel (default: 4)
|
|
64
64
|
-R, --retries N Retries per request (default: 3)
|
|
@@ -141,6 +141,7 @@ export async function main(argv) {
|
|
|
141
141
|
"batch-file": { type: "string", short: "a" },
|
|
142
142
|
"download-archive": { type: "string" },
|
|
143
143
|
"limit-rate": { type: "string" },
|
|
144
|
+
"write-subs": { type: "boolean" },
|
|
144
145
|
cookies: { type: "string" },
|
|
145
146
|
"config-location": { type: "string" },
|
|
146
147
|
"no-config": { type: "boolean" },
|
|
@@ -179,8 +180,6 @@ export async function main(argv) {
|
|
|
179
180
|
process.stderr.write(`ERROR: ${errMsg(e)}\n`);
|
|
180
181
|
return 2;
|
|
181
182
|
}
|
|
182
|
-
// Banner: interactive terminals only. Anything machine-facing (quiet, json,
|
|
183
|
-
// get-url, simulate, progress-json) or non-TTY stdout suppresses it.
|
|
184
183
|
const machineMode = values.quiet || values["dump-json"] || values["get-url"] || values.simulate || values["progress-json"];
|
|
185
184
|
if (process.stdout.isTTY && !machineMode) {
|
|
186
185
|
process.stderr.write(renderBanner(VERSION, theme, !values["no-color"] && shouldUseColor()) + "\n");
|
|
@@ -227,7 +226,6 @@ export async function main(argv) {
|
|
|
227
226
|
headers[h.slice(0, i).trim()] = h.slice(i + 1).trim();
|
|
228
227
|
}
|
|
229
228
|
const num = (v, d) => (v !== undefined && Number.isFinite(Number(v)) && Number(v) >= 0 ? Number(v) : d);
|
|
230
|
-
// plugins: explicit --plugin paths, plus the default dir unless disabled
|
|
231
229
|
const pluginPaths = [...(values.plugin ?? [])];
|
|
232
230
|
const defDir = defaultPluginDir();
|
|
233
231
|
if (!values["no-plugins"] && existsSync(defDir))
|
|
@@ -263,11 +261,11 @@ export async function main(argv) {
|
|
|
263
261
|
remuxVideo: values["remux-video"],
|
|
264
262
|
headers,
|
|
265
263
|
limitRate,
|
|
264
|
+
writeSubs: !!values["write-subs"],
|
|
266
265
|
};
|
|
267
266
|
for (const k of Object.keys(opts))
|
|
268
267
|
if (opts[k] === undefined)
|
|
269
268
|
delete opts[k];
|
|
270
|
-
// Ctrl-C cancels in-flight work cleanly (partial .part files are kept for resume)
|
|
271
269
|
const ctl = new AbortController();
|
|
272
270
|
const onSigint = () => ctl.abort();
|
|
273
271
|
process.once("SIGINT", onSigint);
|
|
@@ -280,7 +278,6 @@ export async function main(argv) {
|
|
|
280
278
|
process.stderr.write(e.stack + "\n");
|
|
281
279
|
code = Math.max(code, e instanceof TidepullError ? e.exitCode : 1);
|
|
282
280
|
};
|
|
283
|
-
// Spinner for the resolve/extract phase: TTY stderr only, machine modes never see it.
|
|
284
281
|
const interactive = process.stdout.isTTY && !machineMode && !values["no-progress"];
|
|
285
282
|
const spinner = new Spinner({ text: "extracting…", env: process.env });
|
|
286
283
|
const spin = () => {
|
|
@@ -288,7 +285,6 @@ export async function main(argv) {
|
|
|
288
285
|
spinner.start();
|
|
289
286
|
};
|
|
290
287
|
const stopSpin = (final) => spinner.stop(final);
|
|
291
|
-
/** What to do with one extracted item: print info, list formats, print URLs, or download it. */
|
|
292
288
|
const handle = async (info, fields) => {
|
|
293
289
|
if (values["dump-json"])
|
|
294
290
|
process.stdout.write(JSON.stringify(info) + "\n");
|
|
@@ -323,7 +319,6 @@ export async function main(argv) {
|
|
|
323
319
|
const resolved = await tp.resolve(url, { signal: ctl.signal });
|
|
324
320
|
if (isPlaylist(resolved) && (values["dump-json"] || values["list-formats"])) {
|
|
325
321
|
stopSpin(`${resolved.title}: ${resolved.entries.length} item(s)`);
|
|
326
|
-
// listing a playlist needs no request per entry
|
|
327
322
|
if (values["dump-json"])
|
|
328
323
|
process.stdout.write(JSON.stringify(resolved) + "\n");
|
|
329
324
|
else {
|
package/dist/playlist.d.ts
CHANGED
|
@@ -1,40 +1,22 @@
|
|
|
1
1
|
import { type DownloadOptions } from "./core/pipeline.js";
|
|
2
2
|
import type { Info, Playlist, PlaylistEntry } from "./core/types.js";
|
|
3
3
|
import type { CallOptions, Tidepull } from "./tidepull.js";
|
|
4
|
-
/** Item numbers from a spec like "1-3,7,10-" (1-based, in the order given, no duplicates). Empty spec selects everything. */
|
|
5
4
|
export declare function parseItems(spec: string | undefined, total: number): number[];
|
|
6
5
|
export interface PlaylistItem {
|
|
7
|
-
/** 1-based position in the playlist */
|
|
8
6
|
index: number;
|
|
9
|
-
/** 1-based position among the selected items */
|
|
10
7
|
position: number;
|
|
11
|
-
/** number of selected items */
|
|
12
8
|
total: number;
|
|
13
|
-
/** undefined when the URL was a single item */
|
|
14
9
|
playlist?: Playlist;
|
|
15
10
|
entry?: PlaylistEntry;
|
|
16
11
|
info?: Info;
|
|
17
|
-
/** why this entry could not be extracted */
|
|
18
12
|
error?: Error;
|
|
19
13
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Template fields for an item: playlist, playlist_id, playlist_index, playlist_count. Empty for a single item.
|
|
22
|
-
* When the extractor's own title is just the id (a bare file name), the entry's title from the playlist is used instead.
|
|
23
|
-
*/
|
|
24
14
|
export declare const playlistFields: (item: PlaylistItem) => Record<string, string | number>;
|
|
25
|
-
/**
|
|
26
|
-
* One item for a single URL, or one per selected entry of a playlist (extracted lazily, in order).
|
|
27
|
-
* An entry that fails to extract is reported on the item instead of ending the iteration.
|
|
28
|
-
* `source` may be a URL or an already resolved Info/Playlist.
|
|
29
|
-
*/
|
|
30
15
|
export declare function resolveItems(tp: Tidepull, source: string | Info | Playlist, o?: CallOptions & {
|
|
31
16
|
items?: string;
|
|
32
17
|
}): AsyncGenerator<PlaylistItem>;
|
|
33
18
|
export interface PullAllOptions extends Partial<DownloadOptions>, CallOptions {
|
|
34
|
-
/** which playlist items to download, e.g. "1-3,7,10-" (default: all) */
|
|
35
19
|
items?: string;
|
|
36
|
-
/** called for an item that fails; without it the first failure is thrown */
|
|
37
20
|
onError?: (error: Error, item: PlaylistItem) => void;
|
|
38
21
|
}
|
|
39
|
-
/** Downloads a single item, or every selected entry of a playlist, and returns the files in order. */
|
|
40
22
|
export declare function pullAll(tp: Tidepull, source: string, o?: PullAllOptions): Promise<string[]>;
|
package/dist/playlist.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Playlist helpers (opt-in: "@boy-offi9-inc/tidepull/playlist"): choose items and download every entry of a playlist.
|
|
3
|
-
* Entries are extracted one at a time with `trust: false`, so secret headers never go to hosts named inside a feed.
|
|
4
|
-
*/
|
|
5
1
|
import { TidepullError } from "./core/errors.js";
|
|
6
2
|
import { isPlaylist } from "./core/pipeline.js";
|
|
7
|
-
/** Item numbers from a spec like "1-3,7,10-" (1-based, in the order given, no duplicates). Empty spec selects everything. */
|
|
8
3
|
export function parseItems(spec, total) {
|
|
9
4
|
if (!spec?.trim())
|
|
10
5
|
return Array.from({ length: total }, (_, i) => i + 1);
|
|
@@ -27,10 +22,6 @@ export function parseItems(spec, total) {
|
|
|
27
22
|
}
|
|
28
23
|
return out;
|
|
29
24
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Template fields for an item: playlist, playlist_id, playlist_index, playlist_count. Empty for a single item.
|
|
32
|
-
* When the extractor's own title is just the id (a bare file name), the entry's title from the playlist is used instead.
|
|
33
|
-
*/
|
|
34
25
|
export const playlistFields = (item) => {
|
|
35
26
|
if (!item.playlist)
|
|
36
27
|
return {};
|
|
@@ -44,11 +35,6 @@ export const playlistFields = (item) => {
|
|
|
44
35
|
fields.title = item.entry.title;
|
|
45
36
|
return fields;
|
|
46
37
|
};
|
|
47
|
-
/**
|
|
48
|
-
* One item for a single URL, or one per selected entry of a playlist (extracted lazily, in order).
|
|
49
|
-
* An entry that fails to extract is reported on the item instead of ending the iteration.
|
|
50
|
-
* `source` may be a URL or an already resolved Info/Playlist.
|
|
51
|
-
*/
|
|
52
38
|
export async function* resolveItems(tp, source, o = {}) {
|
|
53
39
|
const first = typeof source === "string" ? await tp.resolve(source, o) : source;
|
|
54
40
|
if (!isPlaylist(first)) {
|
|
@@ -71,7 +57,6 @@ export async function* resolveItems(tp, source, o = {}) {
|
|
|
71
57
|
}
|
|
72
58
|
}
|
|
73
59
|
}
|
|
74
|
-
/** Downloads a single item, or every selected entry of a playlist, and returns the files in order. */
|
|
75
60
|
export async function pullAll(tp, source, o = {}) {
|
|
76
61
|
const { items, onError, ...rest } = o;
|
|
77
62
|
const files = [];
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { Extractor } from "./core/types.js";
|
|
2
|
-
/** Bump when the plugin contract changes in a breaking way. Plugins declare which version they target. */
|
|
3
2
|
export declare const PLUGIN_API_VERSION = 1;
|
|
4
3
|
export interface TidepullPlugin {
|
|
5
4
|
name: string;
|
|
6
5
|
apiVersion: number;
|
|
7
6
|
extractors?: Extractor[];
|
|
8
7
|
}
|
|
9
|
-
/** Typed identity helper for plugin authors: `export default definePlugin({...})` */
|
|
10
8
|
export declare const definePlugin: (p: TidepullPlugin) => TidepullPlugin;
|
package/dist/plugins.js
CHANGED