@pagepocket/plugin-yt-dlp 0.8.6 → 0.9.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/setup.js
CHANGED
|
@@ -21,7 +21,7 @@ const writeJsonAtomic = async (filePath, value) => {
|
|
|
21
21
|
const dir = path.dirname(filePath);
|
|
22
22
|
await fs.promises.mkdir(dir, { recursive: true });
|
|
23
23
|
const tmpPath = `${filePath}.tmp`;
|
|
24
|
-
await fs.promises.writeFile(tmpPath, `${JSON.stringify(value,
|
|
24
|
+
await fs.promises.writeFile(tmpPath, `${JSON.stringify(value, undefined, 2)}\n`, "utf8");
|
|
25
25
|
await fs.promises.rename(tmpPath, filePath);
|
|
26
26
|
};
|
|
27
27
|
export const resolveBinaryPathJsonFilePath = () => {
|
|
@@ -3,5 +3,5 @@ type FindExecutableOptions = {
|
|
|
3
3
|
pathExtEnv?: string;
|
|
4
4
|
cwd?: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const findExecutable: (command: string, options?: FindExecutableOptions) => Promise<string |
|
|
6
|
+
export declare const findExecutable: (command: string, options?: FindExecutableOptions) => Promise<string | undefined>;
|
|
7
7
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import nodeFs from "node:fs";
|
|
1
2
|
import fs from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
const hasPathSeparator = (value) => value.includes("/") || value.includes("\\");
|
|
@@ -23,7 +24,7 @@ const isExecutableFile = async (absPath) => {
|
|
|
23
24
|
if (process.platform === "win32") {
|
|
24
25
|
return true;
|
|
25
26
|
}
|
|
26
|
-
await fs.access(absPath,
|
|
27
|
+
await fs.access(absPath, nodeFs.constants.X_OK);
|
|
27
28
|
return true;
|
|
28
29
|
}
|
|
29
30
|
catch {
|
|
@@ -43,12 +44,12 @@ const buildCandidateNames = (command, options) => {
|
|
|
43
44
|
export const findExecutable = async (command, options = {}) => {
|
|
44
45
|
const trimmed = command.trim();
|
|
45
46
|
if (!trimmed) {
|
|
46
|
-
return
|
|
47
|
+
return undefined;
|
|
47
48
|
}
|
|
48
49
|
const cwd = options.cwd ?? process.cwd();
|
|
49
50
|
if (hasPathSeparator(trimmed)) {
|
|
50
51
|
const abs = path.isAbsolute(trimmed) ? trimmed : path.resolve(cwd, trimmed);
|
|
51
|
-
return (await isExecutableFile(abs)) ? abs :
|
|
52
|
+
return (await isExecutableFile(abs)) ? abs : undefined;
|
|
52
53
|
}
|
|
53
54
|
const pathEnv = options.pathEnv ?? process.env.PATH ?? "";
|
|
54
55
|
const dirs = pathEnv
|
|
@@ -64,5 +65,5 @@ export const findExecutable = async (command, options = {}) => {
|
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
|
-
return
|
|
68
|
+
return undefined;
|
|
68
69
|
};
|
|
@@ -10,7 +10,7 @@ export type YoutubeJob = {
|
|
|
10
10
|
export declare const parseYoutubeEmbedSrc: (src: string) => {
|
|
11
11
|
id: string;
|
|
12
12
|
url: string;
|
|
13
|
-
} |
|
|
13
|
+
} | undefined;
|
|
14
14
|
export declare class YtDlpJobManager {
|
|
15
15
|
createSetupValue(now?: Date): SetupValue;
|
|
16
16
|
buildVideoRelPath(setupValue: SetupValue, videoId: string): string;
|
|
@@ -4,21 +4,21 @@ export const parseYoutubeEmbedSrc = (src) => {
|
|
|
4
4
|
const url = new URL(src, "https://www.youtube.com");
|
|
5
5
|
const host = url.hostname;
|
|
6
6
|
if (!host.endsWith("youtube.com") && !host.endsWith("youtube-nocookie.com")) {
|
|
7
|
-
return
|
|
7
|
+
return undefined;
|
|
8
8
|
}
|
|
9
9
|
const parts = url.pathname.split("/").filter(Boolean);
|
|
10
10
|
const embedIndex = parts.indexOf("embed");
|
|
11
11
|
if (embedIndex === -1) {
|
|
12
|
-
return
|
|
12
|
+
return undefined;
|
|
13
13
|
}
|
|
14
14
|
const id = parts[embedIndex + 1];
|
|
15
15
|
if (!id) {
|
|
16
|
-
return
|
|
16
|
+
return undefined;
|
|
17
17
|
}
|
|
18
18
|
return { id, url: `https://www.youtube.com/watch?v=${id}` };
|
|
19
19
|
}
|
|
20
20
|
catch {
|
|
21
|
-
return
|
|
21
|
+
return undefined;
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
const uniqueById = (jobs) => {
|
package/dist/utils/ytdlp.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import pathMod from "node:path";
|
|
1
4
|
import { YtDlp, helpers } from "ytdlp-nodejs";
|
|
2
5
|
import { resolveBinaryPathJsonFilePath } from "../setup.js";
|
|
3
6
|
const isBinaryPathJson = (value) => {
|
|
@@ -9,20 +12,16 @@ const isBinaryPathJson = (value) => {
|
|
|
9
12
|
};
|
|
10
13
|
const readBinaryPathJson = async () => {
|
|
11
14
|
try {
|
|
12
|
-
const fs = await import("node:fs/promises");
|
|
13
15
|
const filePath = resolveBinaryPathJsonFilePath();
|
|
14
16
|
const text = await fs.readFile(filePath, "utf8");
|
|
15
17
|
const parsed = JSON.parse(text);
|
|
16
|
-
return isBinaryPathJson(parsed) ? parsed :
|
|
18
|
+
return isBinaryPathJson(parsed) ? parsed : undefined;
|
|
17
19
|
}
|
|
18
20
|
catch {
|
|
19
|
-
return
|
|
21
|
+
return undefined;
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
24
|
export const downloadVideosAsBytes = async (jobs) => {
|
|
23
|
-
const fs = await import("node:fs/promises");
|
|
24
|
-
const pathMod = await import("node:path");
|
|
25
|
-
const os = await import("node:os");
|
|
26
25
|
const binaryPathJson = await readBinaryPathJson();
|
|
27
26
|
if (!binaryPathJson) {
|
|
28
27
|
console.info("binary-path.json missing/invalid; downloading yt-dlp/ffmpeg via ytdlp-nodejs...");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagepocket/plugin-yt-dlp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "PagePocket plugin: download YouTube embeds and replace with <video>",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"ytdlp-nodejs": "^3.4.2",
|
|
14
|
-
"@pagepocket/
|
|
15
|
-
"@pagepocket/
|
|
16
|
-
"@pagepocket/shared": "0.
|
|
14
|
+
"@pagepocket/contracts": "0.9.1",
|
|
15
|
+
"@pagepocket/lib": "0.9.1",
|
|
16
|
+
"@pagepocket/shared": "0.9.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
+
"@types/node": "^20.17.12",
|
|
19
20
|
"typescript": "^5.4.5"
|
|
20
21
|
},
|
|
21
22
|
"scripts": {
|