@talosjs/youtube 1.0.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.
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +11 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Talos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @talosjs/youtube
|
|
2
|
+
|
|
3
|
+
YouTube video downloader and metadata extraction library for fetching video information, thumbnails, and media streams.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
✅ **Transcript Fetching** - Retrieve timestamped transcripts and video metadata via `Youtube#transcript`
|
|
12
|
+
|
|
13
|
+
✅ **ytdlp Integration** - Type definitions for ytdlp-nodejs including video/audio quality, format options, and download progress
|
|
14
|
+
|
|
15
|
+
✅ **Quality Types** - `YoutubeVideoQualityType` (144p to 2160p) and `YoutubeAudioQualityType` for stream selection
|
|
16
|
+
|
|
17
|
+
✅ **Error Handling** - Custom `YoutubeException` for YouTube-specific error scenarios
|
|
18
|
+
|
|
19
|
+
✅ **Type-Safe** - Full TypeScript support with `IYoutube` interface and re-exported ytdlp types
|
|
20
|
+
|
|
21
|
+
> For URL helpers like `getId`, `getEmbedUrl`, and `getWatchUrl`, see [`@talosjs/youtube-utils`](../youtube-utils).
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
bun add @talosjs/youtube
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
36
|
+
|
|
37
|
+
### Development Setup
|
|
38
|
+
|
|
39
|
+
1. Clone the repository
|
|
40
|
+
2. Install dependencies: `bun install`
|
|
41
|
+
3. Run tests: `bun run test`
|
|
42
|
+
4. Build the project: `bun run build`
|
|
43
|
+
|
|
44
|
+
### Guidelines
|
|
45
|
+
|
|
46
|
+
- Write tests for new features
|
|
47
|
+
- Follow the existing code style
|
|
48
|
+
- Update documentation for API changes
|
|
49
|
+
- Ensure all tests pass before submitting PR
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
Made with ❤️ by the Talos team
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ArgsOptions, FormatOptions, QualityOptions, VideoFormat, VideoProgress } from "ytdlp-nodejs";
|
|
2
|
+
type YoutubeVideoFormatType = VideoFormat;
|
|
3
|
+
type YoutubeVideoProgressType = VideoProgress;
|
|
4
|
+
type YoutubeArgsOptionsType = ArgsOptions;
|
|
5
|
+
type YoutubeFormatOptionsType<F extends YoutubeFormatKeyWordType> = FormatOptions<F>;
|
|
6
|
+
type YoutubeQualityOptionsType = QualityOptions;
|
|
7
|
+
type YoutubeFormatKeyWordType = keyof QualityOptions;
|
|
8
|
+
type YoutubeVideoQualityType = "2160p" | "1440p" | "1080p" | "720p" | "480p" | "360p" | "240p" | "144p" | "highest" | "lowest";
|
|
9
|
+
type YoutubeAudioQualityType = "highest" | "lowest";
|
|
10
|
+
type YoutubeTranscriptSegmentType = {
|
|
11
|
+
text: string;
|
|
12
|
+
start: number;
|
|
13
|
+
duration: number;
|
|
14
|
+
};
|
|
15
|
+
type YoutubeTranscriptAuthorType = {
|
|
16
|
+
name: string;
|
|
17
|
+
url: string;
|
|
18
|
+
};
|
|
19
|
+
type YoutubeTranscriptMetadataType = {
|
|
20
|
+
title: string;
|
|
21
|
+
author: YoutubeTranscriptAuthorType;
|
|
22
|
+
thumbnail: string;
|
|
23
|
+
};
|
|
24
|
+
type YoutubeTranscriptResponseType = {
|
|
25
|
+
id: string;
|
|
26
|
+
lang: string;
|
|
27
|
+
transcript: YoutubeTranscriptSegmentType[];
|
|
28
|
+
metadata: YoutubeTranscriptMetadataType;
|
|
29
|
+
};
|
|
30
|
+
interface IYoutube {
|
|
31
|
+
transcript(videoId: string): Promise<YoutubeTranscriptResponseType>;
|
|
32
|
+
}
|
|
33
|
+
declare class Youtube implements IYoutube {
|
|
34
|
+
private static readonly BASE_URL;
|
|
35
|
+
private readonly apiKey;
|
|
36
|
+
constructor(apiKey?: string);
|
|
37
|
+
transcript(videoId: string): Promise<YoutubeTranscriptResponseType>;
|
|
38
|
+
}
|
|
39
|
+
import { Exception } from "@talosjs/exception";
|
|
40
|
+
declare class YoutubeException extends Exception {
|
|
41
|
+
constructor(message: string, key: string, data?: Record<string, unknown>);
|
|
42
|
+
}
|
|
43
|
+
export { YoutubeVideoQualityType, YoutubeVideoProgressType, YoutubeVideoFormatType, YoutubeTranscriptSegmentType, YoutubeTranscriptResponseType, YoutubeTranscriptMetadataType, YoutubeTranscriptAuthorType, YoutubeQualityOptionsType, YoutubeFormatOptionsType, YoutubeFormatKeyWordType, YoutubeException, YoutubeAudioQualityType, YoutubeArgsOptionsType, Youtube, IYoutube };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/YoutubeException.ts
|
|
3
|
+
import { Exception } from "@talosjs/exception";
|
|
4
|
+
import { HttpStatus } from "@talosjs/http-status";
|
|
5
|
+
|
|
6
|
+
class YoutubeException extends Exception {
|
|
7
|
+
constructor(message, key, data = {}) {
|
|
8
|
+
super(message, {
|
|
9
|
+
key,
|
|
10
|
+
status: HttpStatus.Code.InternalServerError,
|
|
11
|
+
data
|
|
12
|
+
});
|
|
13
|
+
this.name = "YoutubeException";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/Youtube.ts
|
|
18
|
+
class Youtube {
|
|
19
|
+
static BASE_URL = "https://transcriptapi.com/api/v2";
|
|
20
|
+
apiKey;
|
|
21
|
+
constructor(apiKey) {
|
|
22
|
+
this.apiKey = apiKey ?? Bun.env.YOUTUBE_TRANSCRIPT_API_KEY ?? "";
|
|
23
|
+
if (!this.apiKey) {
|
|
24
|
+
throw new YoutubeException("YouTube Transcript API key is required. Please set the YOUTUBE_TRANSCRIPT_API_KEY environment variable.", "API_KEY_REQUIRED");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async transcript(videoId) {
|
|
28
|
+
const params = new URLSearchParams({
|
|
29
|
+
video_url: videoId,
|
|
30
|
+
format: "json",
|
|
31
|
+
include_timestamp: "true",
|
|
32
|
+
send_metadata: "true"
|
|
33
|
+
});
|
|
34
|
+
const response = await fetch(`${Youtube.BASE_URL}/youtube/transcript?${params}`, {
|
|
35
|
+
headers: {
|
|
36
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new YoutubeException(`Transcript API error: ${response.status} ${response.statusText}`, "TRANSCRIPT_FAILED", { videoId, status: response.status });
|
|
41
|
+
}
|
|
42
|
+
const data = await response.json();
|
|
43
|
+
return {
|
|
44
|
+
id: data.video_id,
|
|
45
|
+
lang: data.language,
|
|
46
|
+
transcript: data.transcript,
|
|
47
|
+
metadata: {
|
|
48
|
+
title: data.metadata.title,
|
|
49
|
+
author: {
|
|
50
|
+
name: data.metadata.author_name,
|
|
51
|
+
url: data.metadata.author_url
|
|
52
|
+
},
|
|
53
|
+
thumbnail: data.metadata.thumbnail_url
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
YoutubeException,
|
|
60
|
+
Youtube
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//# debugId=025B276CE136CF8364756E2164756E21
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/YoutubeException.ts", "src/Youtube.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { Exception } from \"@talosjs/exception\";\nimport { HttpStatus } from \"@talosjs/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}\n"
|
|
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/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": "025B276CE136CF8364756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@talosjs/youtube",
|
|
3
|
+
"description": "YouTube video downloader and metadata extraction library for fetching video information, thumbnails, and media streams",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"README.md",
|
|
10
|
+
"package.json"
|
|
11
|
+
],
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "bun test tests",
|
|
26
|
+
"build": "bunup",
|
|
27
|
+
"lint": "tsgo --noEmit && bunx biome lint",
|
|
28
|
+
"npm:publish": "bun publish --tolerate-republish --force --production --access public"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@talosjs/exception": "^1.2.10",
|
|
32
|
+
"@talosjs/http-status": "^1.1.11",
|
|
33
|
+
"ytdlp-nodejs": "^2.3.5"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"api",
|
|
37
|
+
"bun",
|
|
38
|
+
"downloader",
|
|
39
|
+
"talos",
|
|
40
|
+
"transcript",
|
|
41
|
+
"typescript",
|
|
42
|
+
"video",
|
|
43
|
+
"youtube",
|
|
44
|
+
"ytdlp"
|
|
45
|
+
]
|
|
46
|
+
}
|