@ziplayer/ytexecplug 0.0.3 → 0.0.4
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.d.ts +0 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -75
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +3 -84
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { BasePlugin } from "ziplayer";
|
|
2
2
|
import { Track, SearchResult, StreamInfo } from "ziplayer";
|
|
3
|
-
import { Readable } from "stream";
|
|
4
|
-
/**
|
|
5
|
-
* Converts a Web ReadableStream to a Node.js Readable stream
|
|
6
|
-
*/
|
|
7
|
-
export declare function webStreamToNodeStream(webStream: ReadableStream, highWaterMark?: number, seekBytes?: number): Promise<Readable>;
|
|
8
3
|
export declare class YTexec extends BasePlugin {
|
|
9
4
|
name: string;
|
|
10
5
|
version: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AA6C3D,qBAAa,MAAO,SAAQ,UAAU;IACrC,IAAI,SAAY;IAChB,OAAO,SAAW;IAElB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAe3B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAIjE,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,UAAU,CAAC;CAgBlD"}
|
package/dist/index.js
CHANGED
|
@@ -4,76 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.YTexec = void 0;
|
|
7
|
-
exports.webStreamToNodeStream = webStreamToNodeStream;
|
|
8
7
|
const ziplayer_1 = require("ziplayer");
|
|
9
|
-
const stream_1 = require("stream");
|
|
10
8
|
const youtube_dl_exec_1 = __importDefault(require("youtube-dl-exec"));
|
|
11
|
-
/**
|
|
12
|
-
* Converts a Web ReadableStream to a Node.js Readable stream
|
|
13
|
-
*/
|
|
14
|
-
async function webStreamToNodeStream(webStream, highWaterMark = 64 * 1024, seekBytes = 0) {
|
|
15
|
-
const reader = webStream.getReader();
|
|
16
|
-
let bytesSkipped = 0;
|
|
17
|
-
let streamEnded = false;
|
|
18
|
-
const nodeStream = new stream_1.Readable({
|
|
19
|
-
highWaterMark,
|
|
20
|
-
async read() {
|
|
21
|
-
if (streamEnded) {
|
|
22
|
-
this.push(null);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
while (true) {
|
|
27
|
-
const { done, value } = await reader.read();
|
|
28
|
-
if (done) {
|
|
29
|
-
streamEnded = true;
|
|
30
|
-
this.push(null);
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
if (!value)
|
|
34
|
-
continue;
|
|
35
|
-
// Handle seek
|
|
36
|
-
if (seekBytes > 0 && bytesSkipped < seekBytes) {
|
|
37
|
-
const remaining = seekBytes - bytesSkipped;
|
|
38
|
-
if (value.length <= remaining) {
|
|
39
|
-
bytesSkipped += value.length;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
const partial = value.subarray(remaining);
|
|
44
|
-
bytesSkipped = seekBytes;
|
|
45
|
-
const buffer = Buffer.from(partial);
|
|
46
|
-
if (!this.push(buffer)) {
|
|
47
|
-
// Backpressure
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const buffer = Buffer.from(value);
|
|
54
|
-
if (!this.push(buffer)) {
|
|
55
|
-
// Backpressure
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
console.error("Stream read error:", err);
|
|
63
|
-
streamEnded = true;
|
|
64
|
-
this.destroy(err);
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
// Cleanup handlers
|
|
69
|
-
nodeStream.on("close", () => {
|
|
70
|
-
reader.releaseLock();
|
|
71
|
-
});
|
|
72
|
-
nodeStream.on("error", () => {
|
|
73
|
-
reader.releaseLock();
|
|
74
|
-
});
|
|
75
|
-
return nodeStream;
|
|
76
|
-
}
|
|
77
9
|
function extractVideoId(input) {
|
|
78
10
|
try {
|
|
79
11
|
const u = new URL(input);
|
|
@@ -141,14 +73,9 @@ class YTexec extends ziplayer_1.BasePlugin {
|
|
|
141
73
|
if (!youtubeUrl) {
|
|
142
74
|
throw new Error("Failed to get YouTube stream URL");
|
|
143
75
|
}
|
|
144
|
-
const response = await fetch(youtubeUrl);
|
|
145
|
-
if (!response.ok || !response.body) {
|
|
146
|
-
throw new Error("Failed to fetch YouTube stream");
|
|
147
|
-
}
|
|
148
|
-
const stream = webStreamToNodeStream(response.body);
|
|
149
76
|
return {
|
|
150
|
-
|
|
151
|
-
type: "
|
|
77
|
+
url: youtubeUrl,
|
|
78
|
+
type: "url",
|
|
152
79
|
metadata: track.metadata,
|
|
153
80
|
};
|
|
154
81
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts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gBACZ,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,WAAmB;QAC9C,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,KAAY;QAC3B,IAAI,CAAC;YACJ,MAAM,UAAU,GAAG,MAAM,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACrD,IAAI,CAAC,UAAU,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;YACrD,CAAC;YAED,OAAO;gBACN,GAAG,EAAE,UAAU;gBACf,IAAI,EAAE,KAAK;gBACX,QAAQ,EAAE,KAAK,CAAC,QAAQ;aACxB,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,iCAAiC,KAAK,EAAE,CAAC,CAAC;QAC3D,CAAC;IACF,CAAC;CACD;AAvCD,wBAuCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ziplayer/ytexecplug",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "A modular Discord voice player with plugin system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ZiPlayer",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"youtube-dl-exec": "^3.1.1",
|
|
32
|
-
"ziplayer": "^0.
|
|
32
|
+
"ziplayer": "^0.3.11"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "^20.0.0",
|
package/src/index.ts
CHANGED
|
@@ -2,83 +2,7 @@ import { BasePlugin } from "ziplayer";
|
|
|
2
2
|
import { Track, SearchResult, StreamInfo } from "ziplayer";
|
|
3
3
|
import { Readable } from "stream";
|
|
4
4
|
import youtubedl from "youtube-dl-exec";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Converts a Web ReadableStream to a Node.js Readable stream
|
|
8
|
-
*/
|
|
9
|
-
export async function webStreamToNodeStream(
|
|
10
|
-
webStream: ReadableStream,
|
|
11
|
-
highWaterMark: number = 64 * 1024,
|
|
12
|
-
seekBytes: number = 0,
|
|
13
|
-
): Promise<Readable> {
|
|
14
|
-
const reader = webStream.getReader();
|
|
15
|
-
let bytesSkipped = 0;
|
|
16
|
-
let streamEnded = false;
|
|
17
|
-
|
|
18
|
-
const nodeStream = new Readable({
|
|
19
|
-
highWaterMark,
|
|
20
|
-
async read() {
|
|
21
|
-
if (streamEnded) {
|
|
22
|
-
this.push(null);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
while (true) {
|
|
28
|
-
const { done, value } = await reader.read();
|
|
29
|
-
|
|
30
|
-
if (done) {
|
|
31
|
-
streamEnded = true;
|
|
32
|
-
this.push(null);
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!value) continue;
|
|
37
|
-
|
|
38
|
-
// Handle seek
|
|
39
|
-
if (seekBytes > 0 && bytesSkipped < seekBytes) {
|
|
40
|
-
const remaining = seekBytes - bytesSkipped;
|
|
41
|
-
if (value.length <= remaining) {
|
|
42
|
-
bytesSkipped += value.length;
|
|
43
|
-
continue;
|
|
44
|
-
} else {
|
|
45
|
-
const partial = value.subarray(remaining);
|
|
46
|
-
bytesSkipped = seekBytes;
|
|
47
|
-
const buffer = Buffer.from(partial);
|
|
48
|
-
if (!this.push(buffer)) {
|
|
49
|
-
// Backpressure
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const buffer = Buffer.from(value);
|
|
57
|
-
if (!this.push(buffer)) {
|
|
58
|
-
// Backpressure
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
} catch (err) {
|
|
64
|
-
console.error("Stream read error:", err);
|
|
65
|
-
streamEnded = true;
|
|
66
|
-
this.destroy(err as Error);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// Cleanup handlers
|
|
72
|
-
nodeStream.on("close", () => {
|
|
73
|
-
reader.releaseLock();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
nodeStream.on("error", () => {
|
|
77
|
-
reader.releaseLock();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
return nodeStream;
|
|
81
|
-
}
|
|
5
|
+
import { url } from "inspector/promises";
|
|
82
6
|
|
|
83
7
|
function extractVideoId(input: string): string | null {
|
|
84
8
|
try {
|
|
@@ -149,15 +73,10 @@ export class YTexec extends BasePlugin {
|
|
|
149
73
|
if (!youtubeUrl) {
|
|
150
74
|
throw new Error("Failed to get YouTube stream URL");
|
|
151
75
|
}
|
|
152
|
-
const response = await fetch(youtubeUrl);
|
|
153
|
-
if (!response.ok || !response.body) {
|
|
154
|
-
throw new Error("Failed to fetch YouTube stream");
|
|
155
|
-
}
|
|
156
|
-
const stream = webStreamToNodeStream(response.body as ReadableStream) as unknown as Readable;
|
|
157
76
|
|
|
158
77
|
return {
|
|
159
|
-
|
|
160
|
-
type: "
|
|
78
|
+
url: youtubeUrl,
|
|
79
|
+
type: "url",
|
|
161
80
|
metadata: track.metadata,
|
|
162
81
|
};
|
|
163
82
|
} catch (error) {
|