@tacone/prosey 0.9.0 → 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/bin/prosey +21 -20
- package/package.json +1 -1
- package/src/channel-description.test.ts +50 -0
- package/src/channel-description.ts +22 -0
- package/src/index.ts +1 -24
package/bin/prosey
CHANGED
|
@@ -103317,10 +103317,30 @@ function openInBrowser(htmlPath) {
|
|
|
103317
103317
|
setTimeout(() => resolve(), 5000);
|
|
103318
103318
|
});
|
|
103319
103319
|
}
|
|
103320
|
+
|
|
103321
|
+
// src/channel-description.ts
|
|
103322
|
+
async function fetchChannelDescription(channelId) {
|
|
103323
|
+
try {
|
|
103324
|
+
const resp = await fetch(`https://www.youtube.com/youtubei/v1/browse`, {
|
|
103325
|
+
method: "POST",
|
|
103326
|
+
headers: { "Content-Type": "application/json" },
|
|
103327
|
+
body: JSON.stringify({
|
|
103328
|
+
context: {
|
|
103329
|
+
client: { clientName: "WEB", clientVersion: "2.20240101.00.00" }
|
|
103330
|
+
},
|
|
103331
|
+
browseId: channelId
|
|
103332
|
+
})
|
|
103333
|
+
});
|
|
103334
|
+
const data = await resp.json();
|
|
103335
|
+
return data?.metadata?.channelMetadataRenderer?.description;
|
|
103336
|
+
} catch {
|
|
103337
|
+
return;
|
|
103338
|
+
}
|
|
103339
|
+
}
|
|
103320
103340
|
// package.json
|
|
103321
103341
|
var package_default = {
|
|
103322
103342
|
name: "@tacone/prosey",
|
|
103323
|
-
version: "0.9.
|
|
103343
|
+
version: "0.9.1",
|
|
103324
103344
|
description: "Download YouTube video transcripts from the CLI",
|
|
103325
103345
|
module: "src/index.ts",
|
|
103326
103346
|
type: "module",
|
|
@@ -121947,25 +121967,6 @@ var debugApis = {
|
|
|
121947
121967
|
};
|
|
121948
121968
|
|
|
121949
121969
|
// src/index.ts
|
|
121950
|
-
var YT_INNERTUBE_API_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8";
|
|
121951
|
-
async function fetchChannelDescription(channelId) {
|
|
121952
|
-
try {
|
|
121953
|
-
const resp = await fetch(`https://www.youtube.com/youtubei/v1/browse?key=${YT_INNERTUBE_API_KEY}`, {
|
|
121954
|
-
method: "POST",
|
|
121955
|
-
headers: { "Content-Type": "application/json" },
|
|
121956
|
-
body: JSON.stringify({
|
|
121957
|
-
context: {
|
|
121958
|
-
client: { clientName: "WEB", clientVersion: "2.20240101.00.00" }
|
|
121959
|
-
},
|
|
121960
|
-
browseId: channelId
|
|
121961
|
-
})
|
|
121962
|
-
});
|
|
121963
|
-
const data = await resp.json();
|
|
121964
|
-
return data?.metadata?.channelMetadataRenderer?.description;
|
|
121965
|
-
} catch {
|
|
121966
|
-
return;
|
|
121967
|
-
}
|
|
121968
|
-
}
|
|
121969
121970
|
process.stdout.on("error", (err) => {
|
|
121970
121971
|
if (err.code === "EPIPE")
|
|
121971
121972
|
process.exit(0);
|
package/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { describe, expect, test, mock } from "bun:test";
|
|
2
|
+
import { fetchChannelDescription } from "./channel-description";
|
|
3
|
+
|
|
4
|
+
function mockFetchResponse(data: unknown): void {
|
|
5
|
+
globalThis.fetch = mock(() =>
|
|
6
|
+
Promise.resolve({
|
|
7
|
+
ok: true,
|
|
8
|
+
json: () => Promise.resolve(data),
|
|
9
|
+
}),
|
|
10
|
+
) as unknown as typeof fetch;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe("fetchChannelDescription", () => {
|
|
14
|
+
test("calls the browse endpoint without an API key", async () => {
|
|
15
|
+
let capturedUrl = "";
|
|
16
|
+
let capturedInit: RequestInit | undefined;
|
|
17
|
+
globalThis.fetch = ((url: any, init: any) => {
|
|
18
|
+
capturedUrl = String(url);
|
|
19
|
+
capturedInit = init;
|
|
20
|
+
return Promise.resolve({
|
|
21
|
+
ok: true,
|
|
22
|
+
json: () =>
|
|
23
|
+
Promise.resolve({
|
|
24
|
+
metadata: {
|
|
25
|
+
channelMetadataRenderer: { description: "Channel bio" },
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
}) as unknown as typeof fetch;
|
|
30
|
+
|
|
31
|
+
const desc = await fetchChannelDescription("UC123");
|
|
32
|
+
expect(desc).toBe("Channel bio");
|
|
33
|
+
|
|
34
|
+
expect(capturedUrl).toBe("https://www.youtube.com/youtubei/v1/browse");
|
|
35
|
+
expect(capturedUrl).not.toContain("key=");
|
|
36
|
+
expect(capturedInit!.method).toBe("POST");
|
|
37
|
+
const body = JSON.parse(String(capturedInit!.body));
|
|
38
|
+
expect(body.browseId).toBe("UC123");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("returns undefined when response has no description", async () => {
|
|
42
|
+
mockFetchResponse({ metadata: {} });
|
|
43
|
+
expect(await fetchChannelDescription("UC123")).toBeUndefined();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("returns undefined on network error", async () => {
|
|
47
|
+
globalThis.fetch = mock(() => Promise.reject(new Error("boom"))) as unknown as typeof fetch;
|
|
48
|
+
expect(await fetchChannelDescription("UC123")).toBeUndefined();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface ChannelDescriptionResult {
|
|
2
|
+
description?: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export async function fetchChannelDescription(channelId: string): Promise<string | undefined> {
|
|
6
|
+
try {
|
|
7
|
+
const resp = await fetch(`https://www.youtube.com/youtubei/v1/browse`, {
|
|
8
|
+
method: "POST",
|
|
9
|
+
headers: { "Content-Type": "application/json" },
|
|
10
|
+
body: JSON.stringify({
|
|
11
|
+
context: {
|
|
12
|
+
client: { clientName: "WEB", clientVersion: "2.20240101.00.00" },
|
|
13
|
+
},
|
|
14
|
+
browseId: channelId,
|
|
15
|
+
}),
|
|
16
|
+
});
|
|
17
|
+
const data: ChannelDescriptionResult = (await resp.json()) as ChannelDescriptionResult;
|
|
18
|
+
return (data as any)?.metadata?.channelMetadataRenderer?.description;
|
|
19
|
+
} catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -21,34 +21,11 @@ import {
|
|
|
21
21
|
import { cacheDir, readCache, writeCache, extractVideoId } from "./cache";
|
|
22
22
|
import { extractChapters, formatChaptersAsText, formatChaptersAsJson } from "./extract-chapters";
|
|
23
23
|
import { generateHtml, openInBrowser } from "./html";
|
|
24
|
+
import { fetchChannelDescription } from "./channel-description";
|
|
24
25
|
import { checkVersion } from "./version-check";
|
|
25
26
|
import pkg from "../package.json";
|
|
26
27
|
import prettier from "prettier";
|
|
27
28
|
|
|
28
|
-
const YT_INNERTUBE_API_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8";
|
|
29
|
-
|
|
30
|
-
async function fetchChannelDescription(channelId: string): Promise<string | undefined> {
|
|
31
|
-
try {
|
|
32
|
-
const resp = await fetch(
|
|
33
|
-
`https://www.youtube.com/youtubei/v1/browse?key=${YT_INNERTUBE_API_KEY}`,
|
|
34
|
-
{
|
|
35
|
-
method: "POST",
|
|
36
|
-
headers: { "Content-Type": "application/json" },
|
|
37
|
-
body: JSON.stringify({
|
|
38
|
-
context: {
|
|
39
|
-
client: { clientName: "WEB", clientVersion: "2.20240101.00.00" },
|
|
40
|
-
},
|
|
41
|
-
browseId: channelId,
|
|
42
|
-
}),
|
|
43
|
-
},
|
|
44
|
-
);
|
|
45
|
-
const data: any = await resp.json();
|
|
46
|
-
return data?.metadata?.channelMetadataRenderer?.description;
|
|
47
|
-
} catch {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
29
|
process.stdout.on("error", (err: NodeJS.ErrnoException) => {
|
|
53
30
|
if (err.code === "EPIPE") process.exit(0);
|
|
54
31
|
});
|