@ooneex/youtube 1.3.6 → 1.3.8
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 -5
- package/dist/index.d.ts +0 -3
- package/dist/index.js +1 -28
- package/dist/index.js.map +3 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -8,11 +8,7 @@ YouTube video downloader and metadata extraction library for fetching video info
|
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
✅ **
|
|
12
|
-
|
|
13
|
-
✅ **Embed URL Generation** - Convert any YouTube URL or video ID into an embeddable URL via `getEmbedUrl`
|
|
14
|
-
|
|
15
|
-
✅ **Watch URL Generation** - Convert any YouTube URL or video ID into a standard watch URL via `getWatchUrl`
|
|
11
|
+
✅ **Transcript Fetching** - Retrieve timestamped transcripts and video metadata via `Youtube#transcript`
|
|
16
12
|
|
|
17
13
|
✅ **ytdlp Integration** - Type definitions for ytdlp-nodejs including video/audio quality, format options, and download progress
|
|
18
14
|
|
|
@@ -22,6 +18,8 @@ YouTube video downloader and metadata extraction library for fetching video info
|
|
|
22
18
|
|
|
23
19
|
✅ **Type-Safe** - Full TypeScript support with `IYoutube` interface and re-exported ytdlp types
|
|
24
20
|
|
|
21
|
+
> For URL helpers like `getId`, `getEmbedUrl`, and `getWatchUrl`, see [`@ooneex/youtube-utils`](../youtube-utils).
|
|
22
|
+
|
|
25
23
|
## Installation
|
|
26
24
|
|
|
27
25
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -35,9 +35,6 @@ declare class Youtube implements IYoutube {
|
|
|
35
35
|
private readonly apiKey;
|
|
36
36
|
constructor(apiKey?: string);
|
|
37
37
|
transcript(videoId: string): Promise<YoutubeTranscriptResponseType>;
|
|
38
|
-
static getWatchId(url: string): string | null;
|
|
39
|
-
static getEmbedUrl(urlOrId: string): string | null;
|
|
40
|
-
static getWatchUrl(urlOrId: string): string | null;
|
|
41
38
|
}
|
|
42
39
|
import { Exception } from "@ooneex/exception";
|
|
43
40
|
declare class YoutubeException extends Exception {
|
package/dist/index.js
CHANGED
|
@@ -54,37 +54,10 @@ class Youtube {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
static getWatchId(url) {
|
|
58
|
-
const patterns = [
|
|
59
|
-
/(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/|youtube\.com\/v\/|youtube\.com\/watch\?.*&v=)([^&\n?#]+)/,
|
|
60
|
-
/youtube\.com\/shorts\/([^&\n?#]+)/
|
|
61
|
-
];
|
|
62
|
-
for (const pattern of patterns) {
|
|
63
|
-
const match = url.match(pattern);
|
|
64
|
-
if (match?.[1]) {
|
|
65
|
-
return match[1];
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
static getEmbedUrl(urlOrId) {
|
|
71
|
-
const videoId = Youtube.getWatchId(urlOrId) ?? urlOrId;
|
|
72
|
-
if (!/^[\w-]{10,12}$/.test(videoId)) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
return `https://www.youtube.com/embed/${videoId}`;
|
|
76
|
-
}
|
|
77
|
-
static getWatchUrl(urlOrId) {
|
|
78
|
-
const videoId = Youtube.getWatchId(urlOrId) ?? urlOrId;
|
|
79
|
-
if (!/^[\w-]{10,12}$/.test(videoId)) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
return `https://www.youtube.com/watch?v=${videoId}`;
|
|
83
|
-
}
|
|
84
57
|
}
|
|
85
58
|
export {
|
|
86
59
|
YoutubeException,
|
|
87
60
|
Youtube
|
|
88
61
|
};
|
|
89
62
|
|
|
90
|
-
//# debugId=
|
|
63
|
+
//# debugId=9014DE70D082B5E164756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"sources": ["src/YoutubeException.ts", "src/Youtube.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { Exception } from \"@ooneex/exception\";\nimport { HttpStatus } from \"@ooneex/http-status\";\n\nexport class YoutubeException extends Exception {\n constructor(message: string, key: string, data: Record<string, unknown> = {}) {\n super(message, {\n key,\n status: HttpStatus.Code.InternalServerError,\n data,\n });\n this.name = \"YoutubeException\";\n }\n}\n",
|
|
6
|
-
"import type { IYoutube, YoutubeTranscriptResponseType } from \"./types\";\nimport { YoutubeException } from \"./YoutubeException\";\n\nexport class Youtube implements IYoutube {\n private static readonly BASE_URL = \"https://transcriptapi.com/api/v2\";\n\n private readonly apiKey: string;\n\n constructor(apiKey?: string) {\n this.apiKey = apiKey ?? Bun.env.YOUTUBE_TRANSCRIPT_API_KEY ?? \"\";\n\n if (!this.apiKey) {\n throw new YoutubeException(\n \"YouTube Transcript API key is required. Please set the YOUTUBE_TRANSCRIPT_API_KEY environment variable.\",\n \"API_KEY_REQUIRED\",\n );\n }\n }\n\n public async transcript(videoId: string): Promise<YoutubeTranscriptResponseType> {\n const params = new URLSearchParams({\n video_url: videoId,\n format: \"json\",\n include_timestamp: \"true\",\n send_metadata: \"true\",\n });\n\n const response = await fetch(`${Youtube.BASE_URL}/youtube/transcript?${params}`, {\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n },\n });\n\n if (!response.ok) {\n throw new YoutubeException(\n `Transcript API error: ${response.status} ${response.statusText}`,\n \"TRANSCRIPT_FAILED\",\n { videoId, status: response.status },\n );\n }\n\n const data = await response.json();\n\n return {\n id: data.video_id,\n lang: data.language,\n transcript: data.transcript,\n metadata: {\n title: data.metadata.title,\n author: {\n name: data.metadata.author_name,\n url: data.metadata.author_url,\n },\n thumbnail: data.metadata.thumbnail_url,\n },\n };\n }\n
|
|
6
|
+
"import type { IYoutube, YoutubeTranscriptResponseType } from \"./types\";\nimport { YoutubeException } from \"./YoutubeException\";\n\nexport class Youtube implements IYoutube {\n private static readonly BASE_URL = \"https://transcriptapi.com/api/v2\";\n\n private readonly apiKey: string;\n\n constructor(apiKey?: string) {\n this.apiKey = apiKey ?? Bun.env.YOUTUBE_TRANSCRIPT_API_KEY ?? \"\";\n\n if (!this.apiKey) {\n throw new YoutubeException(\n \"YouTube Transcript API key is required. Please set the YOUTUBE_TRANSCRIPT_API_KEY environment variable.\",\n \"API_KEY_REQUIRED\",\n );\n }\n }\n\n public async transcript(videoId: string): Promise<YoutubeTranscriptResponseType> {\n const params = new URLSearchParams({\n video_url: videoId,\n format: \"json\",\n include_timestamp: \"true\",\n send_metadata: \"true\",\n });\n\n const response = await fetch(`${Youtube.BASE_URL}/youtube/transcript?${params}`, {\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n },\n });\n\n if (!response.ok) {\n throw new YoutubeException(\n `Transcript API error: ${response.status} ${response.statusText}`,\n \"TRANSCRIPT_FAILED\",\n { videoId, status: response.status },\n );\n }\n\n const data = await response.json();\n\n return {\n id: data.video_id,\n lang: data.language,\n transcript: data.transcript,\n metadata: {\n title: data.metadata.title,\n author: {\n name: data.metadata.author_name,\n url: data.metadata.author_url,\n },\n thumbnail: data.metadata.thumbnail_url,\n },\n };\n }\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";;AAAA;AACA;AAAA;AAEO,MAAM,yBAAyB,UAAU;AAAA,EAC9C,WAAW,CAAC,SAAiB,KAAa,OAAgC,CAAC,GAAG;AAAA,IAC5E,MAAM,SAAS;AAAA,MACb;AAAA,MACA,QAAQ,WAAW,KAAK;AAAA,MACxB;AAAA,IACF,CAAC;AAAA,IACD,KAAK,OAAO;AAAA;AAEhB;;;ACTO,MAAM,QAA4B;AAAA,SACf,WAAW;AAAA,EAElB;AAAA,EAEjB,WAAW,CAAC,QAAiB;AAAA,IAC3B,KAAK,SAAS,UAAU,IAAI,IAAI,8BAA8B;AAAA,IAE9D,IAAI,CAAC,KAAK,QAAQ;AAAA,MAChB,MAAM,IAAI,iBACR,2GACA,kBACF;AAAA,IACF;AAAA;AAAA,OAGW,WAAU,CAAC,SAAyD;AAAA,IAC/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A,IACF;AAAA;AAAA,OAGW,WAAU,CAAC,SAAyD;AAAA,IAC/E,MAAM,SAAS,IAAI,gBAAgB;AAAA,MACjC,WAAW;AAAA,MACX,QAAQ;AAAA,MACR,mBAAmB;AAAA,MACnB,eAAe;AAAA,IACjB,CAAC;AAAA,IAED,MAAM,WAAW,MAAM,MAAM,GAAG,QAAQ,+BAA+B,UAAU;AAAA,MAC/E,SAAS;AAAA,QACP,eAAe,UAAU,KAAK;AAAA,MAChC;AAAA,IACF,CAAC;AAAA,IAED,IAAI,CAAC,SAAS,IAAI;AAAA,MAChB,MAAM,IAAI,iBACR,yBAAyB,SAAS,UAAU,SAAS,cACrD,qBACA,EAAE,SAAS,QAAQ,SAAS,OAAO,CACrC;AAAA,IACF;AAAA,IAEA,MAAM,OAAO,MAAM,SAAS,KAAK;AAAA,IAEjC,OAAO;AAAA,MACL,IAAI,KAAK;AAAA,MACT,MAAM,KAAK;AAAA,MACX,YAAY,KAAK;AAAA,MACjB,UAAU;AAAA,QACR,OAAO,KAAK,SAAS;AAAA,QACrB,QAAQ;AAAA,UACN,MAAM,KAAK,SAAS;AAAA,UACpB,KAAK,KAAK,SAAS;AAAA,QACrB;AAAA,QACA,WAAW,KAAK,SAAS;AAAA,MAC3B;AAAA,IACF;AAAA;AAEJ;",
|
|
9
|
+
"debugId": "9014DE70D082B5E164756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ooneex/youtube",
|
|
3
3
|
"description": "YouTube video downloader and metadata extraction library for fetching video information, thumbnails, and media streams",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
"npm:publish": "bun publish --tolerate-republish --force --production --access public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@ooneex/exception": "^1.2.
|
|
32
|
-
"@ooneex/http-status": "^1.1.
|
|
31
|
+
"@ooneex/exception": "^1.2.9",
|
|
32
|
+
"@ooneex/http-status": "^1.1.11",
|
|
33
33
|
"ytdlp-nodejs": "^2.3.5"
|
|
34
34
|
},
|
|
35
35
|
"keywords": [
|
|
36
36
|
"api",
|
|
37
37
|
"bun",
|
|
38
38
|
"downloader",
|
|
39
|
-
"embed",
|
|
40
39
|
"ooneex",
|
|
40
|
+
"transcript",
|
|
41
41
|
"typescript",
|
|
42
42
|
"video",
|
|
43
43
|
"youtube",
|