@boy-offi9-inc/tidepull 0.2.0-rc.0 → 0.2.0-rc.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/LICENSE +1 -1
- package/README.md +27 -5
- package/dist/cookies.d.ts +21 -0
- package/dist/cookies.js +67 -0
- package/dist/core/http.d.ts +3 -0
- package/dist/core/http.js +9 -0
- package/dist/main.js +11 -1
- package/package.json +5 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ Cap the speed with `limitRate` (bytes per second, applied to each file): `g.down
|
|
|
44
44
|
| `definePlugin`, `PLUGIN_API_VERSION` | write extractor plugins |
|
|
45
45
|
| `@boy-offi9-inc/tidepull/dash` *(opt-in)* | DASH VOD: `createTidepull({ plugins: [dash] })` |
|
|
46
46
|
| `@boy-offi9-inc/tidepull/loader` *(opt-in)* | `loadPlugins(paths)` / `loadPlugin(file)`: load plugins from disk |
|
|
47
|
+
| `@boy-offi9-inc/tidepull/cookies` *(opt-in)* | `parseCookies`, `loadCookieFile`, `cookieJar`: `createTidepull({ http: { cookies: cookieJar(cookies) } })` |
|
|
47
48
|
| `selectFormats`, `renderTemplate`, `parseHlsMaster/Media` | the building blocks, usable standalone |
|
|
48
49
|
| `Http`, `TidepullError` | redirect-safe, header-scoped HTTP client; error type |
|
|
49
50
|
| types | `Info`, `Format`, `Extractor`, `TidepullEvent`, `DownloadOptions`, `TidepullPlugin`, ... |
|
|
@@ -76,16 +77,36 @@ tidepull -o "%(title).60s [%(id)s].%(ext)s" -P ~/Videos URL
|
|
|
76
77
|
tidepull -j URL | jq .formats # data on stdout, logs on stderr
|
|
77
78
|
tidepull -a urls.txt --download-archive done.txt # batch input; skip what you already downloaded
|
|
78
79
|
tidepull --limit-rate 1M URL # cap the speed (500K, 1.5M, ...)
|
|
80
|
+
tidepull --cookies cookies.txt URL # use your own logged-in session
|
|
79
81
|
```
|
|
80
82
|
|
|
83
|
+
**Cookies.** `--cookies FILE` reads a Netscape `cookies.txt` (the format browser extensions export). Each cookie is sent only to the host, path and scheme it was issued for. Keep the file private (`chmod 600`); you get a warning if other users can read it.
|
|
84
|
+
|
|
81
85
|
**Batch and archive.** `-a FILE` reads one URL per line (`#` starts a comment, `-` reads stdin). `--download-archive FILE` records each finished item and skips it on later runs.
|
|
82
86
|
|
|
83
87
|
**Config file.** Defaults go in `~/.config/tidepull/config` (or `--config-location FILE`): one or more options per line, `#` for comments, for example `-P ~/Videos` and `--limit-rate 2M`. Options on the command line win; `--no-config` ignores the file.
|
|
84
88
|
|
|
85
89
|
From a clone, `node src/cli.ts <args>` runs the TypeScript source directly (Node >= 22.18); `npm run build` emits JS + `.d.ts`.
|
|
86
90
|
|
|
87
|
-
##
|
|
88
|
-
|
|
91
|
+
## Capabilities and limits
|
|
92
|
+
|
|
93
|
+
**What Tidepull does**
|
|
94
|
+
- Downloads direct media files, HLS (VOD, AES-128) and DASH (VOD) streams, and pages that embed them
|
|
95
|
+
- Resumes interrupted downloads, caps speed, retries with backoff and cancels cleanly
|
|
96
|
+
- Merges separate video and audio, or remuxes, with ffmpeg
|
|
97
|
+
- Selects formats (`bv*[height<=720]+ba/b`) and names files from templates
|
|
98
|
+
- Uses your own cookies (`--cookies`) and headers, sending them only to the hosts they belong to
|
|
99
|
+
- Works as a CLI or a typed library with JSON events; support for a specific site is added through plugins
|
|
100
|
+
|
|
101
|
+
**What it does not do**
|
|
102
|
+
- No site-specific extractors are built in. Platforms such as YouTube hide their media behind scripts and tokens and need a plugin
|
|
103
|
+
- No DRM: protected streams (Widevine, PlayReady, FairPlay, encrypted DASH) are not supported and will not be
|
|
104
|
+
- No circumvention: it cannot get past logins, paywalls or geo-blocks. With `--cookies` it only fetches what your own session can already see
|
|
105
|
+
- Not implemented yet: live streams, multi-period DASH (first period only), SAMPLE-AES, byte-range HLS/DASH, subtitles, playlists, a proxy option
|
|
106
|
+
- Cookies are read-only: `Set-Cookie` responses are not stored
|
|
107
|
+
|
|
108
|
+
### Details
|
|
109
|
+
| Area | Behavior |
|
|
89
110
|
|---|---|
|
|
90
111
|
| Direct files | resumable (`.part` + `Range`), retries with backoff |
|
|
91
112
|
| HLS VOD | master + media playlists, parallel segments written in order, AES-128 (explicit/default IV), fMP4 init maps, separate audio renditions |
|
|
@@ -93,9 +114,9 @@ From a clone, `node src/cli.ts <args>` runs the TypeScript source directly (Node
|
|
|
93
114
|
| Generic page extractor | `og:video`, `<video>/<source>`, bare media URLs in HTML/JSON |
|
|
94
115
|
| Format selector | `b bv bv* ba ba* w wv wa`, `+` merge, `/` fallback, `()` groups, `[height<=720]` `[filesize<?50M]` `[ext=mp4]` |
|
|
95
116
|
| Output templates | `%(title)s`, `%(x\|default)s`, `%(title).50s`, sanitized |
|
|
117
|
+
| Cookies | Netscape `cookies.txt`; matched by domain, path, `Secure` and expiry; re-evaluated on every redirect hop |
|
|
118
|
+
| CLI conveniences | `-a` batch input, `--download-archive`, `--limit-rate`, `--config-location` |
|
|
96
119
|
| Merge / remux | ffmpeg |
|
|
97
|
-
| Site-specific extractors | none built in. Platforms such as YouTube hide their media behind scripts and tokens and need a plugin (see Plugins) |
|
|
98
|
-
| Not yet | live HLS/DASH, multi-period DASH, SAMPLE-AES, byte-range HLS/DASH, playlists, subtitles, cookies |
|
|
99
120
|
|
|
100
121
|
## Footprint (enforced in CI)
|
|
101
122
|
The core does only what every user needs: extract → select → download, events, cancellation. Everything else is a plugin or an opt-in subpath.
|
|
@@ -110,8 +131,9 @@ The core does only what every user needs: extract → select → download, event
|
|
|
110
131
|
|
|
111
132
|
## Security model
|
|
112
133
|
- **No shell, ever.** ffmpeg is spawned with argv arrays. There is deliberately no `--exec` and no `--netrc-cmd`-style hook; the command-injection CVEs in this space came from exactly those features.
|
|
113
|
-
- **Redirect-safe HTTP.** Redirects are followed manually
|
|
134
|
+
- **Redirect-safe HTTP.** Redirects are followed manually and headers are recomputed on every hop: secrets and per-request headers stay with their own host, non-http(s) targets are refused, loops are capped.
|
|
114
135
|
- **Origin-scoped secrets.** Custom headers like `Authorization`, `Cookie` or API tokens (`--header` / `http.headers`) are sent only to the origins you pass to `extract()`/`pull()`, plus any `--header-host` / `http.headerHosts` patterns (`cdn.example.com`, `*.example.com`). `Referer`, `Origin`, `Accept*`, `User-Agent` and `Range` are never treated as secret. Using one `Tidepull` instance for several sites trusts all of them, so use one instance per credential. The low-level `Http` class (without `headerHosts`) sends headers to each request's start origin only.
|
|
136
|
+
- **Per-host cookies.** `--cookies` sends each cookie only to the host, path and scheme it was issued for (`Secure` cookies never go over http). A cookie with a single-label domain such as `.com` is treated as host-only. Cookie values are never logged and never appear in `-j` output.
|
|
115
137
|
- Output filenames are built from sanitized fields only. Only `http(s)` URLs are accepted.
|
|
116
138
|
|
|
117
139
|
## Legal
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface Cookie {
|
|
2
|
+
domain: string;
|
|
3
|
+
/** also valid for subdomains of `domain` */
|
|
4
|
+
subdomains: boolean;
|
|
5
|
+
path: string;
|
|
6
|
+
secure: boolean;
|
|
7
|
+
/** seconds since epoch, 0 for a session cookie */
|
|
8
|
+
expires: number;
|
|
9
|
+
name: string;
|
|
10
|
+
value: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function parseCookies(text: string): Cookie[];
|
|
13
|
+
/** The Cookie header value for `url`, or undefined when no cookie applies. */
|
|
14
|
+
export declare function cookieHeader(cookies: readonly Cookie[], url: URL, now?: number): string | undefined;
|
|
15
|
+
/** Plug into the HTTP client: `createTidepull({ http: { cookies: cookieJar(cookies) } })`. */
|
|
16
|
+
export declare const cookieJar: (cookies: readonly Cookie[]) => (url: URL) => string | undefined;
|
|
17
|
+
/** Reads a cookies.txt file. The warning (if any) says the file is readable by other users. */
|
|
18
|
+
export declare function loadCookieFile(file: string): {
|
|
19
|
+
cookies: Cookie[];
|
|
20
|
+
warning?: string;
|
|
21
|
+
};
|
package/dist/cookies.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Netscape cookies.txt support (opt-in: "@boy-offi9-inc/tidepull/cookies").
|
|
3
|
+
* Cookies are sent only to the hosts, paths and schemes they were issued for, and are re-evaluated on every redirect hop.
|
|
4
|
+
* Read-only: Set-Cookie responses are not stored. No public-suffix list: only a single-label domain guard.
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync, statSync } from "node:fs";
|
|
7
|
+
import { TidepullError, errMsg } from "./core/errors.js";
|
|
8
|
+
export function parseCookies(text) {
|
|
9
|
+
const out = [];
|
|
10
|
+
for (const raw of text.split("\n")) {
|
|
11
|
+
let line = raw.replace(/\r$/, "");
|
|
12
|
+
if (!line.trim())
|
|
13
|
+
continue;
|
|
14
|
+
if (line.startsWith("#HttpOnly_"))
|
|
15
|
+
line = line.slice("#HttpOnly_".length);
|
|
16
|
+
else if (line.startsWith("#"))
|
|
17
|
+
continue;
|
|
18
|
+
const f = line.split("\t");
|
|
19
|
+
if (f.length < 6)
|
|
20
|
+
continue;
|
|
21
|
+
const [domain, flag, path, secure, expires, name, ...rest] = f;
|
|
22
|
+
const bare = domain.replace(/^\./, "").toLowerCase();
|
|
23
|
+
if (!bare || !name)
|
|
24
|
+
continue;
|
|
25
|
+
// A domain without a dot ("com") must not match every site under it.
|
|
26
|
+
const subdomains = (flag.toUpperCase() === "TRUE" || domain.startsWith(".")) && bare.includes(".");
|
|
27
|
+
out.push({ domain: bare, subdomains, path: path || "/", secure: secure.toUpperCase() === "TRUE", expires: Number(expires) || 0, name, value: rest.join("\t") });
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
const pathMatch = (reqPath, cookiePath) => reqPath === cookiePath || (reqPath.startsWith(cookiePath) && (cookiePath.endsWith("/") || reqPath[cookiePath.length] === "/"));
|
|
32
|
+
/** The Cookie header value for `url`, or undefined when no cookie applies. */
|
|
33
|
+
export function cookieHeader(cookies, url, now = Date.now() / 1000) {
|
|
34
|
+
const host = url.hostname.toLowerCase();
|
|
35
|
+
const isIp = /^[\d.]+$/.test(host) || host.includes(":");
|
|
36
|
+
const hits = cookies.filter((c) => (host === c.domain || (c.subdomains && !isIp && host.endsWith("." + c.domain))) &&
|
|
37
|
+
pathMatch(url.pathname || "/", c.path) &&
|
|
38
|
+
(!c.secure || url.protocol === "https:") &&
|
|
39
|
+
(c.expires === 0 || c.expires > now));
|
|
40
|
+
if (!hits.length)
|
|
41
|
+
return undefined;
|
|
42
|
+
return hits.sort((a, b) => b.path.length - a.path.length).map((c) => `${c.name}=${c.value}`).join("; ");
|
|
43
|
+
}
|
|
44
|
+
/** Plug into the HTTP client: `createTidepull({ http: { cookies: cookieJar(cookies) } })`. */
|
|
45
|
+
export const cookieJar = (cookies) => (url) => cookieHeader(cookies, url);
|
|
46
|
+
/** Reads a cookies.txt file. The warning (if any) says the file is readable by other users. */
|
|
47
|
+
export function loadCookieFile(file) {
|
|
48
|
+
let text;
|
|
49
|
+
try {
|
|
50
|
+
text = readFileSync(file, "utf8");
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
throw new TidepullError(`Cannot read cookie file ${file}: ${errMsg(e)}`, 2);
|
|
54
|
+
}
|
|
55
|
+
const cookies = parseCookies(text);
|
|
56
|
+
if (!cookies.length)
|
|
57
|
+
throw new TidepullError(`No cookies found in ${file} (expected the Netscape cookies.txt format)`, 2);
|
|
58
|
+
let warning;
|
|
59
|
+
try {
|
|
60
|
+
if (process.platform !== "win32" && (statSync(file).mode & 0o077) !== 0)
|
|
61
|
+
warning = `${file} is readable by other users; run: chmod 600 ${file}`;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
/* permissions are advisory */
|
|
65
|
+
}
|
|
66
|
+
return { cookies, warning };
|
|
67
|
+
}
|
package/dist/core/http.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export interface HttpOptions {
|
|
|
12
12
|
* Referer, Origin, User-Agent, Accept-* and Range are never considered secret and are always sent.
|
|
13
13
|
*/
|
|
14
14
|
headerHosts?: string[];
|
|
15
|
+
/** Returns the Cookie header value for a URL (see "@boy-offi9-inc/tidepull/cookies"). Called on every request and redirect hop. */
|
|
16
|
+
cookies?: (url: URL) => string | undefined;
|
|
15
17
|
}
|
|
16
18
|
export interface RequestInitLite {
|
|
17
19
|
method?: string;
|
|
@@ -25,6 +27,7 @@ export declare class Http {
|
|
|
25
27
|
private secret;
|
|
26
28
|
private scopedMode;
|
|
27
29
|
private hostPatterns;
|
|
30
|
+
private cookies?;
|
|
28
31
|
private trusted;
|
|
29
32
|
retries: number;
|
|
30
33
|
timeoutMs: number;
|
package/dist/core/http.js
CHANGED
|
@@ -11,6 +11,7 @@ export class Http {
|
|
|
11
11
|
secret;
|
|
12
12
|
scopedMode;
|
|
13
13
|
hostPatterns;
|
|
14
|
+
cookies;
|
|
14
15
|
trusted = new Set();
|
|
15
16
|
retries;
|
|
16
17
|
timeoutMs;
|
|
@@ -30,6 +31,7 @@ export class Http {
|
|
|
30
31
|
}
|
|
31
32
|
this.scopedMode = o.headerHosts !== undefined;
|
|
32
33
|
this.hostPatterns = (o.headerHosts ?? []).map((h) => h.toLowerCase());
|
|
34
|
+
this.cookies = o.cookies;
|
|
33
35
|
this.retries = o.retries ?? 3;
|
|
34
36
|
this.timeoutMs = o.timeoutMs ?? 30_000;
|
|
35
37
|
this.maxRedirects = o.maxRedirects ?? 10;
|
|
@@ -82,6 +84,13 @@ export class Http {
|
|
|
82
84
|
// per-request headers (Range, extractor-supplied Referer/Cookie...) only travel with the start origin; Range goes everywhere
|
|
83
85
|
const own = Object.fromEntries(Object.entries(init.headers ?? {}).filter(([k]) => cur.origin === start.origin || k.toLowerCase() === "range"));
|
|
84
86
|
const headers = { ...this.headersFor(cur, start), ...own };
|
|
87
|
+
const cookie = this.cookies?.(cur);
|
|
88
|
+
if (cookie) {
|
|
89
|
+
for (const k of Object.keys(headers))
|
|
90
|
+
if (k.toLowerCase() === "cookie")
|
|
91
|
+
delete headers[k];
|
|
92
|
+
headers.Cookie = cookie;
|
|
93
|
+
}
|
|
85
94
|
const ctl = new AbortController();
|
|
86
95
|
const timer = setTimeout(() => ctl.abort(), this.timeoutMs);
|
|
87
96
|
const signal = init.signal ? AbortSignal.any([ctl.signal, init.signal]) : ctl.signal;
|
package/dist/main.js
CHANGED
|
@@ -3,6 +3,7 @@ import { DEFAULT_FORMAT, selectFormats } from "./core/selector.js";
|
|
|
3
3
|
import { TidepullError, errMsg } from "./core/errors.js";
|
|
4
4
|
import { existsSync, readFileSync } from "node:fs";
|
|
5
5
|
import { Archive, configArgs, parseRate, readUrlList } from "./cliutil.js";
|
|
6
|
+
import { cookieJar, loadCookieFile } from "./cookies.js";
|
|
6
7
|
import { createTidepull } from "./tidepull.js";
|
|
7
8
|
import dash from "./dash/index.js";
|
|
8
9
|
import { defaultPluginDir, loadPlugins } from "./loader.js";
|
|
@@ -51,6 +52,7 @@ Config:
|
|
|
51
52
|
|
|
52
53
|
Network:
|
|
53
54
|
--limit-rate RATE Maximum download speed per file, e.g. 500K or 1.5M
|
|
55
|
+
--cookies FILE Send cookies from a Netscape cookies.txt file, only to the hosts they belong to
|
|
54
56
|
-N, --concurrent-fragments N HLS segments fetched in parallel (default: 4)
|
|
55
57
|
-R, --retries N Retries per request (default: 3)
|
|
56
58
|
--header "Name: value" Extra request header (repeatable). Secret-looking headers (Authorization,
|
|
@@ -126,6 +128,7 @@ export async function main(argv) {
|
|
|
126
128
|
"batch-file": { type: "string", short: "a" },
|
|
127
129
|
"download-archive": { type: "string" },
|
|
128
130
|
"limit-rate": { type: "string" },
|
|
131
|
+
cookies: { type: "string" },
|
|
129
132
|
"config-location": { type: "string" },
|
|
130
133
|
"no-config": { type: "boolean" },
|
|
131
134
|
"no-color": { type: "boolean" },
|
|
@@ -161,6 +164,7 @@ export async function main(argv) {
|
|
|
161
164
|
const urls = [...positionals];
|
|
162
165
|
let limitRate;
|
|
163
166
|
let archive;
|
|
167
|
+
let cookies;
|
|
164
168
|
try {
|
|
165
169
|
if (values["batch-file"])
|
|
166
170
|
urls.push(...readUrlList(values["batch-file"]));
|
|
@@ -168,6 +172,12 @@ export async function main(argv) {
|
|
|
168
172
|
limitRate = parseRate(values["limit-rate"]);
|
|
169
173
|
if (values["download-archive"])
|
|
170
174
|
archive = new Archive(values["download-archive"]);
|
|
175
|
+
if (values.cookies) {
|
|
176
|
+
const loaded = loadCookieFile(values.cookies);
|
|
177
|
+
if (loaded.warning)
|
|
178
|
+
log.warn(loaded.warning);
|
|
179
|
+
cookies = cookieJar(loaded.cookies);
|
|
180
|
+
}
|
|
171
181
|
}
|
|
172
182
|
catch (e) {
|
|
173
183
|
log.error(errMsg(e));
|
|
@@ -201,7 +211,7 @@ export async function main(argv) {
|
|
|
201
211
|
return e instanceof TidepullError ? e.exitCode : 1;
|
|
202
212
|
}
|
|
203
213
|
const tp = createTidepull({
|
|
204
|
-
http: { headers, headerHosts: values["header-host"] ?? [], userAgent: values["user-agent"], retries: num(values.retries, 3) },
|
|
214
|
+
http: { headers, headerHosts: values["header-host"] ?? [], userAgent: values["user-agent"], retries: num(values.retries, 3), cookies },
|
|
205
215
|
plugins: [...plugins, dash],
|
|
206
216
|
ffmpeg: values["ffmpeg-location"],
|
|
207
217
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boy-offi9-inc/tidepull",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.1",
|
|
4
4
|
"description": "A minimal, from-scratch media downloader library: extractor plugins, yt-dlp-style format selection, resumable downloads.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,6 +45,10 @@
|
|
|
45
45
|
"./loader": {
|
|
46
46
|
"types": "./dist/loader.d.ts",
|
|
47
47
|
"import": "./dist/loader.js"
|
|
48
|
+
},
|
|
49
|
+
"./cookies": {
|
|
50
|
+
"types": "./dist/cookies.d.ts",
|
|
51
|
+
"import": "./dist/cookies.js"
|
|
48
52
|
}
|
|
49
53
|
},
|
|
50
54
|
"files": [
|