@boy-offi9-inc/tidepull 0.6.0 → 0.7.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/README.md +3 -3
- package/dist/dash/index.js +42 -3
- package/dist/dash/parse.d.ts +1 -0
- package/dist/dash/parse.js +83 -81
- package/dist/ui/banner.js +12 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -183,7 +183,7 @@ From a clone, `node src/cli.ts <args>` runs the TypeScript source directly (Node
|
|
|
183
183
|
- No site-specific extractors are built in. Platforms such as YouTube hide their media behind scripts and tokens and need a plugin
|
|
184
184
|
- No DRM: protected streams (Widevine, PlayReady, FairPlay, encrypted DASH) are not supported and will not be
|
|
185
185
|
- No circumvention: it cannot get past logins, paywalls or geo-blocks. With `--cookies` it only fetches what your own session can already see
|
|
186
|
-
- Not implemented yet: live streams,
|
|
186
|
+
- Not implemented yet: live streams, SAMPLE-AES, fMP4 subtitle tracks (WebVTT segment playlists only), playlists from video sites (they need a plugin), a proxy option
|
|
187
187
|
- Cookies are read-only: `Set-Cookie` responses are not stored
|
|
188
188
|
|
|
189
189
|
### Details
|
|
@@ -191,7 +191,7 @@ From a clone, `node src/cli.ts <args>` runs the TypeScript source directly (Node
|
|
|
191
191
|
|---|---|
|
|
192
192
|
| Direct files | resumable (`.part` + `Range`), retries with backoff |
|
|
193
193
|
| HLS VOD | master + media playlists, parallel segments written in order, AES-128 (explicit/default IV), fMP4 init maps, `EXT-X-BYTERANGE` segments and ranged init maps, separate audio renditions, `SUBTITLES` renditions with `--write-subs` (WebVTT segments joined into one `.vtt` per language) |
|
|
194
|
-
| DASH VOD (`.mpd`), opt-in via `@boy-offi9-inc/tidepull/dash` (built into the CLI) | `SegmentTemplate` (`$Number%05d$`, `$Time$`, timelines, durations), `SegmentList`, single-file `SegmentBase`, nested `BaseURL`; encrypted (`ContentProtection`) representations are skipped, never decrypted |
|
|
194
|
+
| DASH VOD (`.mpd`), opt-in via `@boy-offi9-inc/tidepull/dash` (built into the CLI) | `SegmentTemplate` (`$Number%05d$`, `$Time$`, timelines, durations), `SegmentList`, single-file `SegmentBase`, nested `BaseURL`; multiple `Period`s merged by representation (fragments concatenated in order, init from the first period); encrypted (`ContentProtection`) representations are skipped, never decrypted |
|
|
195
195
|
| Generic page extractor | `og:video`, `<video>/<source>`, bare media URLs in HTML/JSON |
|
|
196
196
|
| Format selector | `b bv bv* ba ba* w wv wa`, `+` merge, `/` fallback, `()` groups, `[height<=720]` `[filesize<?50M]` `[ext=mp4]` |
|
|
197
197
|
| Output templates | `%(title)s`, `%(x\|default)s`, `%(title).50s`, `%(n)02d`, sanitized |
|
|
@@ -206,7 +206,7 @@ The core does only what every user needs: extract → select → download, event
|
|
|
206
206
|
| Import | Files | Raw | Gzip | Minified (gzip) |
|
|
207
207
|
|---|---|---|---|---|
|
|
208
208
|
| `@boy-offi9-inc/tidepull` (core: direct, HLS, generic page, selector, templates, resume, merge, playlists contract) | 18 | 49.6 KB | 13.7 KB | 23 KB (9.7 KB) |
|
|
209
|
-
| `@boy-offi9-inc/tidepull/dash` (adds XML + MPD parsing) | +6 | +14 KB | +4.7 KB | +
|
|
209
|
+
| `@boy-offi9-inc/tidepull/dash` (adds XML + MPD parsing) | +6 | +14 KB | +4.7 KB | +7.1 KB (+3.3 KB) |
|
|
210
210
|
| `@boy-offi9-inc/tidepull/feeds` (RSS/Atom + .m3u; shares the XML parser with dash) | +5 | +9 KB | +3.3 KB | +3.8 KB (+1.9 KB) |
|
|
211
211
|
| `@boy-offi9-inc/tidepull/playlist` (`pullAll`, item selection) | +1 | +3.9 KB | +1.5 KB | +1.9 KB (+1.0 KB) |
|
|
212
212
|
| `@boy-offi9-inc/tidepull/cookies` (cookies.txt) | +2 | +3.8 KB | +1.6 KB | +1.6 KB (+0.9 KB) |
|
package/dist/dash/index.js
CHANGED
|
@@ -16,10 +16,9 @@ export async function extractDash(url, ctx) {
|
|
|
16
16
|
const mpd = parseMpd(text, finalUrl);
|
|
17
17
|
if (mpd.dynamic)
|
|
18
18
|
throw new TidepullError("Live DASH streams are not supported yet");
|
|
19
|
-
if (mpd.periods > 1)
|
|
20
|
-
ctx.log.warn(`Manifest has ${mpd.periods} periods; only the first is used`);
|
|
21
19
|
for (const s of mpd.skipped)
|
|
22
20
|
ctx.log.warn(`Skipping representation ${s}`);
|
|
21
|
+
const reps = mergePeriods(mpd.reps, mpd.periods, ctx);
|
|
23
22
|
const seen = new Set();
|
|
24
23
|
const uniq = (id) => {
|
|
25
24
|
let out = id;
|
|
@@ -29,7 +28,7 @@ export async function extractDash(url, ctx) {
|
|
|
29
28
|
return out;
|
|
30
29
|
};
|
|
31
30
|
const formats = [];
|
|
32
|
-
for (const r of
|
|
31
|
+
for (const r of reps) {
|
|
33
32
|
if (r.kind === "other")
|
|
34
33
|
continue;
|
|
35
34
|
const { v, a } = splitCodecs(r.codecs);
|
|
@@ -61,5 +60,45 @@ export async function extractDash(url, ctx) {
|
|
|
61
60
|
name = url.pathname.split("/").filter(Boolean).slice(-2, -1)[0] ?? url.hostname;
|
|
62
61
|
return { id: name || url.hostname, title: name || url.hostname, extractor: "dash", webpage_url: url.href, formats };
|
|
63
62
|
}
|
|
63
|
+
function mergePeriods(reps, periods, ctx) {
|
|
64
|
+
if (periods <= 1)
|
|
65
|
+
return reps;
|
|
66
|
+
const byId = new Map();
|
|
67
|
+
for (const r of reps) {
|
|
68
|
+
const list = byId.get(r.id) ?? [];
|
|
69
|
+
list.push(r);
|
|
70
|
+
byId.set(r.id, list);
|
|
71
|
+
}
|
|
72
|
+
const merged = [];
|
|
73
|
+
for (const [, list] of byId) {
|
|
74
|
+
if (list.length !== periods) {
|
|
75
|
+
ctx.log.warn(`Skipping representation ${list[0].id}: it does not appear in every period (${list.length}/${periods})`);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
list.sort((a, b) => a.period - b.period);
|
|
79
|
+
const [first, ...rest] = list;
|
|
80
|
+
if (rest.some((r) => r.mime !== first.mime || r.codecs !== first.codecs)) {
|
|
81
|
+
ctx.log.warn(`Skipping representation ${first.id}: codecs or mime type change between periods`);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (first.single) {
|
|
85
|
+
ctx.log.warn(`Skipping representation ${first.id}: whole-file representations cannot span periods`);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const fragments = [];
|
|
89
|
+
for (const r of list) {
|
|
90
|
+
if (!r.fragments?.length || !r.init) {
|
|
91
|
+
ctx.log.warn(`Skipping representation ${first.id}: a period has no fragment list`);
|
|
92
|
+
fragments.length = 0;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
fragments.push(...r.fragments);
|
|
96
|
+
}
|
|
97
|
+
if (!fragments.length)
|
|
98
|
+
continue;
|
|
99
|
+
merged.push({ ...first, fragments, init: first.init });
|
|
100
|
+
}
|
|
101
|
+
return merged;
|
|
102
|
+
}
|
|
64
103
|
export { parseMpd };
|
|
65
104
|
export default definePlugin({ name: "dash", apiVersion: 1, extractors: [dashExtractor] });
|
package/dist/dash/parse.d.ts
CHANGED
package/dist/dash/parse.js
CHANGED
|
@@ -42,95 +42,97 @@ export function parseMpd(text, manifestUrl) {
|
|
|
42
42
|
const out = { reps: [], dynamic, periods: periods.length, skipped: [] };
|
|
43
43
|
if (dynamic || !periods.length)
|
|
44
44
|
return out;
|
|
45
|
-
const period = periods[0];
|
|
46
45
|
const mpdDur = parseIsoDuration(root.attrs.mediaPresentationDuration);
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
for (const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const tplNode = child(rep, "SegmentTemplate") ?? child(aset, "SegmentTemplate");
|
|
74
|
-
const listNode = child(rep, "SegmentList") ?? child(aset, "SegmentList");
|
|
75
|
-
if (tplNode) {
|
|
76
|
-
const tpl = { ...child(aset, "SegmentTemplate")?.attrs, ...child(rep, "SegmentTemplate")?.attrs };
|
|
77
|
-
if (!tpl.media)
|
|
78
|
-
throw new TidepullError("SegmentTemplate without @media");
|
|
79
|
-
if (tpl.initialization)
|
|
80
|
-
r.init = resolve(baseR, fillTemplate(tpl.initialization, vars));
|
|
81
|
-
const timescale = Number(tpl.timescale ?? 1) || 1;
|
|
82
|
-
let n = Number(tpl.startNumber ?? 1);
|
|
83
|
-
const frags = [];
|
|
84
|
-
const push = (num, time) => {
|
|
85
|
-
if (frags.length >= MAX_FRAGMENTS)
|
|
86
|
-
throw new TidepullError(`Too many fragments (>${MAX_FRAGMENTS})`);
|
|
87
|
-
frags.push(resolve(baseR, fillTemplate(tpl.media, { ...vars, Number: num, Time: time })));
|
|
46
|
+
const baseMpd = resolve(manifestUrl, child(root, "BaseURL")?.text);
|
|
47
|
+
for (const [pi, period] of periods.entries()) {
|
|
48
|
+
const periodDur = parseIsoDuration(period.attrs.duration) ?? (periods.length === 1 ? mpdDur : undefined);
|
|
49
|
+
const baseP = resolve(baseMpd, child(period, "BaseURL")?.text);
|
|
50
|
+
for (const aset of kids(period, "AdaptationSet")) {
|
|
51
|
+
const baseA = resolve(baseP, child(aset, "BaseURL")?.text);
|
|
52
|
+
for (const rep of kids(aset, "Representation")) {
|
|
53
|
+
const id = rep.attrs.id ?? String(out.reps.length);
|
|
54
|
+
const mime = rep.attrs.mimeType ?? aset.attrs.mimeType ?? "";
|
|
55
|
+
const ctype = aset.attrs.contentType ?? rep.attrs.contentType ?? mime.split("/")[0];
|
|
56
|
+
const kind = ctype === "video" ? "video" : ctype === "audio" ? "audio" : "other";
|
|
57
|
+
if (child(aset, "ContentProtection") || child(rep, "ContentProtection")) {
|
|
58
|
+
out.skipped.push(`${id}: encrypted (ContentProtection), cannot be downloaded`);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const baseR = resolve(baseA, child(rep, "BaseURL")?.text);
|
|
63
|
+
const bandwidth = Number(rep.attrs.bandwidth ?? 0);
|
|
64
|
+
const r = {
|
|
65
|
+
id, period: pi, kind, mime,
|
|
66
|
+
codecs: rep.attrs.codecs ?? aset.attrs.codecs,
|
|
67
|
+
bandwidth,
|
|
68
|
+
width: Number(rep.attrs.width ?? aset.attrs.width) || undefined,
|
|
69
|
+
height: Number(rep.attrs.height ?? aset.attrs.height) || undefined,
|
|
70
|
+
fps: parseRate(rep.attrs.frameRate ?? aset.attrs.frameRate),
|
|
71
|
+
lang: aset.attrs.lang,
|
|
88
72
|
};
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
73
|
+
const vars = { RepresentationID: id, Bandwidth: bandwidth };
|
|
74
|
+
const tplNode = child(rep, "SegmentTemplate") ?? child(aset, "SegmentTemplate");
|
|
75
|
+
const listNode = child(rep, "SegmentList") ?? child(aset, "SegmentList");
|
|
76
|
+
if (tplNode) {
|
|
77
|
+
const tpl = { ...child(aset, "SegmentTemplate")?.attrs, ...child(rep, "SegmentTemplate")?.attrs };
|
|
78
|
+
if (!tpl.media)
|
|
79
|
+
throw new TidepullError("SegmentTemplate without @media");
|
|
80
|
+
if (tpl.initialization)
|
|
81
|
+
r.init = resolve(baseR, fillTemplate(tpl.initialization, vars));
|
|
82
|
+
const timescale = Number(tpl.timescale ?? 1) || 1;
|
|
83
|
+
let n = Number(tpl.startNumber ?? 1);
|
|
84
|
+
const frags = [];
|
|
85
|
+
const push = (num, time) => {
|
|
86
|
+
if (frags.length >= MAX_FRAGMENTS)
|
|
87
|
+
throw new TidepullError(`Too many fragments (>${MAX_FRAGMENTS})`);
|
|
88
|
+
frags.push(resolve(baseR, fillTemplate(tpl.media, { ...vars, Number: num, Time: time })));
|
|
89
|
+
};
|
|
90
|
+
const timeline = child(tplNode, "SegmentTimeline") ?? child(aset, "SegmentTimeline");
|
|
91
|
+
if (timeline) {
|
|
92
|
+
let t = 0;
|
|
93
|
+
for (const s of kids(timeline, "S")) {
|
|
94
|
+
if (s.attrs.t !== undefined)
|
|
95
|
+
t = Number(s.attrs.t);
|
|
96
|
+
const d = Number(s.attrs.d);
|
|
97
|
+
if (!(d > 0))
|
|
98
|
+
throw new TidepullError("SegmentTimeline entry without a positive @d");
|
|
99
|
+
let rep_ = Number(s.attrs.r ?? 0);
|
|
100
|
+
if (rep_ < 0) {
|
|
101
|
+
if (!periodDur)
|
|
102
|
+
throw new TidepullError("Open-ended SegmentTimeline repeat needs a known duration");
|
|
103
|
+
rep_ = Math.ceil((periodDur * timescale - t) / d) - 1;
|
|
104
|
+
}
|
|
105
|
+
for (let i = 0; i <= rep_; i++, n++, t += d)
|
|
106
|
+
push(n, t);
|
|
103
107
|
}
|
|
104
|
-
for (let i = 0; i <= rep_; i++, n++, t += d)
|
|
105
|
-
push(n, t);
|
|
106
108
|
}
|
|
109
|
+
else if (tpl.duration) {
|
|
110
|
+
if (!periodDur)
|
|
111
|
+
throw new TidepullError("Duration-based SegmentTemplate needs a known presentation duration");
|
|
112
|
+
const count = Math.ceil(periodDur / (Number(tpl.duration) / timescale));
|
|
113
|
+
for (let i = 0; i < count; i++)
|
|
114
|
+
push(n + i);
|
|
115
|
+
}
|
|
116
|
+
else
|
|
117
|
+
throw new TidepullError("SegmentTemplate has neither SegmentTimeline nor @duration");
|
|
118
|
+
r.fragments = frags;
|
|
107
119
|
}
|
|
108
|
-
else if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
else if (listNode) {
|
|
121
|
+
const init = child(listNode, "Initialization");
|
|
122
|
+
if (init?.attrs.range || kids(listNode, "SegmentURL").some((u) => u.attrs.mediaRange))
|
|
123
|
+
throw new TidepullError("Byte-range SegmentList is not supported yet");
|
|
124
|
+
if (init?.attrs.sourceURL)
|
|
125
|
+
r.init = resolve(baseR, init.attrs.sourceURL);
|
|
126
|
+
r.fragments = kids(listNode, "SegmentURL").map((u) => resolve(baseR, u.attrs.media));
|
|
114
127
|
}
|
|
115
|
-
else
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
else if (listNode) {
|
|
120
|
-
const init = child(listNode, "Initialization");
|
|
121
|
-
if (init?.attrs.range || kids(listNode, "SegmentURL").some((u) => u.attrs.mediaRange))
|
|
122
|
-
throw new TidepullError("Byte-range SegmentList is not supported yet");
|
|
123
|
-
if (init?.attrs.sourceURL)
|
|
124
|
-
r.init = resolve(baseR, init.attrs.sourceURL);
|
|
125
|
-
r.fragments = kids(listNode, "SegmentURL").map((u) => resolve(baseR, u.attrs.media));
|
|
128
|
+
else {
|
|
129
|
+
r.single = baseR;
|
|
130
|
+
}
|
|
131
|
+
out.reps.push(r);
|
|
126
132
|
}
|
|
127
|
-
|
|
128
|
-
|
|
133
|
+
catch (e) {
|
|
134
|
+
out.skipped.push(`${id}: ${e instanceof Error ? e.message : String(e)}`);
|
|
129
135
|
}
|
|
130
|
-
out.reps.push(r);
|
|
131
|
-
}
|
|
132
|
-
catch (e) {
|
|
133
|
-
out.skipped.push(`${id}: ${e instanceof Error ? e.message : String(e)}`);
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
}
|
package/dist/ui/banner.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
const GLYPHS = {
|
|
2
|
-
t: ["
|
|
3
|
-
i: ["
|
|
4
|
-
d: ["
|
|
5
|
-
e: ["
|
|
6
|
-
p: ["
|
|
7
|
-
u: ["
|
|
8
|
-
l: ["
|
|
2
|
+
t: ["▀█▀ ", " █ ", " ▀ "],
|
|
3
|
+
i: ["█ ", "█ ", "▀ "],
|
|
4
|
+
d: ["█▀▀▄ ", "█ █ ", "▀▀▀▀ "],
|
|
5
|
+
e: ["█▀▀▀ ", "█▀▀ ", "▀▀▀▀ "],
|
|
6
|
+
p: ["█▀▀▄ ", "█▀▀ ", "▀ ▀ "],
|
|
7
|
+
u: ["█ █ ", "█ █ ", "▀▀▀▀ "],
|
|
8
|
+
l: ["█ ", "█ ", "▀▀▀▀ "],
|
|
9
9
|
};
|
|
10
10
|
function logo() {
|
|
11
|
-
const rows = ["", "", ""
|
|
11
|
+
const rows = ["", "", ""];
|
|
12
12
|
for (const ch of "tidepull") {
|
|
13
13
|
const g = GLYPHS[ch];
|
|
14
|
-
for (let r = 0; r <
|
|
15
|
-
rows[r] += g[r]
|
|
14
|
+
for (let r = 0; r < 3; r++)
|
|
15
|
+
rows[r] += g[r];
|
|
16
16
|
}
|
|
17
17
|
return rows.map((r) => r.trimEnd());
|
|
18
18
|
}
|
|
@@ -21,6 +21,6 @@ export function renderBanner(version, theme, color = true) {
|
|
|
21
21
|
const paint = (c, s) => (plain ? s : c + s + theme.reset);
|
|
22
22
|
const dim = (s) => (plain ? s : theme.dim + s + theme.reset);
|
|
23
23
|
const rows = logo();
|
|
24
|
-
rows[
|
|
25
|
-
return rows.map((r, i) => (i ===
|
|
24
|
+
rows[2] = paint(theme.accent, rows[2]) + " " + dim(`v${version}`);
|
|
25
|
+
return rows.map((r, i) => (i === 2 ? r : paint(theme.accent, r))).join("\n");
|
|
26
26
|
}
|
package/package.json
CHANGED