@ooneex/youtube 1.1.1 → 1.1.3
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/index.js +48 -2
- package/dist/index.js.map +2 -2
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,50 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
2
|
+
// src/Youtube.ts
|
|
3
|
+
class Youtube {
|
|
4
|
+
getWatchId(url) {
|
|
5
|
+
const patterns = [
|
|
6
|
+
/(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/|youtube\.com\/v\/|youtube\.com\/watch\?.*&v=)([^&\n?#]+)/,
|
|
7
|
+
/youtube\.com\/shorts\/([^&\n?#]+)/
|
|
8
|
+
];
|
|
9
|
+
for (const pattern of patterns) {
|
|
10
|
+
const match = url.match(pattern);
|
|
11
|
+
if (match?.[1]) {
|
|
12
|
+
return match[1];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
getEmbedUrl(urlOrId) {
|
|
18
|
+
const videoId = this.getWatchId(urlOrId) ?? urlOrId;
|
|
19
|
+
if (!/^[\w-]{10,12}$/.test(videoId)) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return `https://www.youtube.com/embed/${videoId}`;
|
|
23
|
+
}
|
|
24
|
+
getWatchUrl(urlOrId) {
|
|
25
|
+
const videoId = this.getWatchId(urlOrId) ?? urlOrId;
|
|
26
|
+
if (!/^[\w-]{10,12}$/.test(videoId)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return `https://www.youtube.com/watch?v=${videoId}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// src/YoutubeException.ts
|
|
33
|
+
import { Exception } from "@ooneex/exception";
|
|
34
|
+
import { HttpStatus } from "@ooneex/http-status";
|
|
3
35
|
|
|
4
|
-
|
|
36
|
+
class YoutubeException extends Exception {
|
|
37
|
+
constructor(message, data = {}) {
|
|
38
|
+
super(message, {
|
|
39
|
+
status: HttpStatus.Code.InternalServerError,
|
|
40
|
+
data
|
|
41
|
+
});
|
|
42
|
+
this.name = "YoutubeException";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
YoutubeException,
|
|
47
|
+
Youtube
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
//# debugId=7091406D01C6357564756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"import type { IYoutube } from \"./types\";\n\nexport class Youtube implements IYoutube {\n public getWatchId(url: string): string | null {\n const patterns = [\n /(?:youtube\\.com\\/watch\\?v=|youtu\\.be\\/|youtube\\.com\\/embed\\/|youtube\\.com\\/v\\/|youtube\\.com\\/watch\\?.*&v=)([^&\\n?#]+)/,\n /youtube\\.com\\/shorts\\/([^&\\n?#]+)/,\n ];\n\n for (const pattern of patterns) {\n const match = url.match(pattern);\n if (match?.[1]) {\n return match[1];\n }\n }\n\n return null;\n }\n\n public getEmbedUrl(urlOrId: string): string | null {\n const videoId = this.getWatchId(urlOrId) ?? urlOrId;\n\n if (!/^[\\w-]{10,12}$/.test(videoId)) {\n return null;\n }\n\n return `https://www.youtube.com/embed/${videoId}`;\n }\n\n public getWatchUrl(urlOrId: string): string | null {\n const videoId = this.getWatchId(urlOrId) ?? urlOrId;\n\n if (!/^[\\w-]{10,12}$/.test(videoId)) {\n return null;\n }\n\n return `https://www.youtube.com/watch?v=${videoId}`;\n }\n}\n",
|
|
6
6
|
"import { Exception } from \"@ooneex/exception\";\nimport { HttpStatus } from \"@ooneex/http-status\";\n\nexport class YoutubeException extends Exception {\n constructor(message: string, data: Record<string, unknown> = {}) {\n super(message, {\n status: HttpStatus.Code.InternalServerError,\n data,\n });\n this.name = \"YoutubeException\";\n }\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": "
|
|
9
|
-
"debugId": "
|
|
8
|
+
"mappings": ";;AAEO,MAAM,QAA4B;AAAA,EAChC,UAAU,CAAC,KAA4B;AAAA,IAC5C,MAAM,WAAW;AAAA,MACf;AAAA,MACA;AAAA,IACF;AAAA,IAEA,WAAW,WAAW,UAAU;AAAA,MAC9B,MAAM,QAAQ,IAAI,MAAM,OAAO;AAAA,MAC/B,IAAI,QAAQ,IAAI;AAAA,QACd,OAAO,MAAM;AAAA,MACf;AAAA,IACF;AAAA,IAEA,OAAO;AAAA;AAAA,EAGF,WAAW,CAAC,SAAgC;AAAA,IACjD,MAAM,UAAU,KAAK,WAAW,OAAO,KAAK;AAAA,IAE5C,IAAI,CAAC,iBAAiB,KAAK,OAAO,GAAG;AAAA,MACnC,OAAO;AAAA,IACT;AAAA,IAEA,OAAO,iCAAiC;AAAA;AAAA,EAGnC,WAAW,CAAC,SAAgC;AAAA,IACjD,MAAM,UAAU,KAAK,WAAW,OAAO,KAAK;AAAA,IAE5C,IAAI,CAAC,iBAAiB,KAAK,OAAO,GAAG;AAAA,MACnC,OAAO;AAAA,IACT;AAAA,IAEA,OAAO,mCAAmC;AAAA;AAE9C;;ACtCA;AACA;AAAA;AAEO,MAAM,yBAAyB,UAAU;AAAA,EAC9C,WAAW,CAAC,SAAiB,OAAgC,CAAC,GAAG;AAAA,IAC/D,MAAM,SAAS;AAAA,MACb,QAAQ,WAAW,KAAK;AAAA,MACxB;AAAA,IACF,CAAC;AAAA,IACD,KAAK,OAAO;AAAA;AAEhB;",
|
|
9
|
+
"debugId": "7091406D01C6357564756E2164756E21",
|
|
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.1.
|
|
4
|
+
"version": "1.1.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"npm:publish": "bun publish --tolerate-republish --force --production --access public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@ooneex/exception": "1.1.
|
|
32
|
-
"@ooneex/http-status": "1.1.
|
|
31
|
+
"@ooneex/exception": "1.1.2",
|
|
32
|
+
"@ooneex/http-status": "1.1.2",
|
|
33
33
|
"ytdlp-nodejs": "^2.3.5"
|
|
34
34
|
},
|
|
35
35
|
"keywords": [
|