@boy-offi9-inc/tidepull 0.22.0 → 0.23.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.
@@ -4,7 +4,7 @@ import { rename, rm, stat } from "node:fs/promises";
4
4
  import { setTimeout as sleep } from "node:timers/promises";
5
5
  import { Readable, Transform } from "node:stream";
6
6
  import { pipeline } from "node:stream/promises";
7
- import { TidepullError } from "./errors.js";
7
+ import { TidepullError, codedError, httpErrorCode } from "./errors.js";
8
8
  import { isMasterPlaylist, parseMedia } from "./hls.js";
9
9
  export class RateLimiter {
10
10
  rate;
@@ -41,10 +41,10 @@ export async function downloadHttp(url, dest, o) {
41
41
  }
42
42
  if (!res.ok) {
43
43
  await res.body?.cancel();
44
- throw new TidepullError(`HTTP ${res.status} ${res.statusText} for ${url}`);
44
+ throw codedError(httpErrorCode(res.status), `HTTP ${res.status} ${res.statusText} for ${url}`);
45
45
  }
46
46
  if (!res.body)
47
- throw new TidepullError(`Empty response body for ${url}`);
47
+ throw codedError("UPSTREAM_FAILED", `Empty response body for ${url}`);
48
48
  let append = false;
49
49
  let total;
50
50
  if (res.status === 206 && offset > 0) {
@@ -79,7 +79,7 @@ export async function downloadHttp(url, dest, o) {
79
79
  });
80
80
  await pipeline(Readable.fromWeb(res.body), throttle, counter, createWriteStream(part, { flags: append ? "a" : "w" }), { signal: o.signal });
81
81
  if (total !== undefined && done !== total) {
82
- throw new TidepullError(`Incomplete download (${done}/${total} bytes). Re-run to resume.`);
82
+ throw codedError("UPSTREAM_FAILED", `Incomplete download (${done}/${total} bytes)`, "Re-run the same command to resume from where it stopped");
83
83
  }
84
84
  await rename(part, dest);
85
85
  }
@@ -116,7 +116,7 @@ export function makeSegmentFetcher(o) {
116
116
  if (!p) {
117
117
  p = o.http.request(uri, { headers: o.headers, signal: o.signal }).then(async (r) => {
118
118
  if (!r.ok)
119
- throw new TidepullError(`HTTP ${r.status} fetching HLS key`);
119
+ throw codedError(httpErrorCode(r.status), `HTTP ${r.status} fetching HLS key`);
120
120
  return Buffer.from(await r.arrayBuffer());
121
121
  });
122
122
  keyCache.set(uri, p);
@@ -130,7 +130,7 @@ export function makeSegmentFetcher(o) {
130
130
  const r = await o.http.request(u, { headers, signal: o.signal });
131
131
  if (!r.ok) {
132
132
  await r.body?.cancel();
133
- throw new TidepullError(`HTTP ${r.status} for segment ${u}`);
133
+ throw codedError(httpErrorCode(r.status), `HTTP ${r.status} for segment ${u}`);
134
134
  }
135
135
  const buf = Buffer.from(await r.arrayBuffer());
136
136
  if (range && buf.length !== range.length) {
package/dist/playlist.js CHANGED
@@ -1,4 +1,4 @@
1
- import { TidepullError } from "./core/errors.js";
1
+ import { TidepullError, codedError } from "./core/errors.js";
2
2
  import { isPlaylist } from "./core/pipeline.js";
3
3
  export function parseItems(spec, total) {
4
4
  if (!spec?.trim())
@@ -42,6 +42,9 @@ export async function* resolveItems(tp, source, o = {}) {
42
42
  return;
43
43
  }
44
44
  const picked = parseItems(o.items, first.entries.length);
45
+ if (picked.length === 0) {
46
+ throw codedError("UNSUPPORTED", `Playlist item selection matched nothing (spec "${o.items}" against ${first.entries.length} item(s))`, "Check --playlist-items: ranges like 5-2 select nothing, and items past the end are skipped");
47
+ }
45
48
  tp.emit({ type: "playlist", title: first.title, count: first.entries.length, selected: picked.length });
46
49
  for (const [i, index] of picked.entries()) {
47
50
  const entry = first.entries[index - 1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boy-offi9-inc/tidepull",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
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",