-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
230 lines (184 loc) · 6.89 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
var markdown = `# Documentation
**[Discord YTDL Core](https://ytdl.snowflakedev.xyz "Discord YTDL Core")**
# Installing
\`\`\`sh
npm i discord-ytdl-core
\`\`\`
[https://www.npmjs.com/package/discord-ytdl-core](https://www.npmjs.com/package/discord-ytdl-core)
# Opus [optional]
> Please install opus engine if you want to encode the stream to opus format.
## **Supported Opus Engines**
- **[@discordjs/opus](https://npmjs.com/package/@discordjs/opus)**
- **[node-opus](https://npmjs.com/package/node-opus)**
- **[opusscript](https://npmjs.com/package/opusscript)**
# Options
This package provides 4 extra options excluding ytdl-core options.
- seek: This option takes the time in seconds.
If this option is provided, it will return the stream from that frame.
Seek option is provided here because discord.js seek doesn't work for \`ogg/opus\` & \`webm/opus\` stream.
This option is ignored when the supplied parameter type isn't a number.
- encoderArgs: This option takes the Array of FFmpeg arguments.
Invalid args will throw error and crash the process.
This option is ignored when the supplied parameter type isn't array. Invalid FFmpeg args might crash the process.
- opusEncoded: This option takes a Boolean value. If true, it returns \`opus encoded\` stream.
If \`fmt\` option isn't provided, it returns \`converted\` stream type of discord.js. Other values returns \`unknown\` stream if \`opusEncoded\` is false.
- fmt: Forcefully changes the stream format. Don't use this option for default value. Even though this option changes the format,
it returns \`opus\` stream if \`opusEncoded\` is set to \`true\`.
- Other options are the options for **[ytdl-core](https://npmjs.com/package/ytdl-core)**.
# API
## YTDL.arbitraryStream(source, options)
This method allows you to play the stream from other sources rather than just \`youtube\`. Stream source must be a string.
Example Stream Source: **[https://listen.moe/kpop/opus](https://listen.moe/kpop/opus)**. Options are listed above.
# Example
## Playing Opus Encoded Stream
\`\`\`js
const ytdl = require("discord-ytdl-core");
const Discord = require("discord.js");
const client = new Discord.Client();
client.on("ready", () => {
console.log("ready")
});
client.on("message", msg => {
if (msg.author.bot || !msg.guild) return;
if (msg.content === "!play") {
if (!msg.member.voice.channel) return msg.channel.send("You're not in a voice channel?");
let stream = ytdl("https://youtube.com/watch?v=ERu6jh_1gR0", {
filter: "audioonly",
opusEncoded: true,
encoderArgs: ['-af', 'bass=g=10,dynaudnorm=f=200']
});
msg.member.voice.channel.join()
.then(connection => {
let dispatcher = connection.play(stream, {
type: "opus"
})
.on("finish", () => {
msg.guild.me.voice.channel.leave();
})
});
}
});
client.login("TOKEN");
\`\`\`
## Unknown Stream
\`\`\`js
const ytdl = require("discord-ytdl-core");
const Discord = require("discord.js");
const client = new Discord.Client();
client.on("ready", () => {
console.log("ready")
});
client.on("message", msg => {
if (msg.author.bot || !msg.guild) return;
if (msg.content === "!play") {
if (!msg.member.voice.channel) return msg.channel.send("You're not in a voice channel?");
let stream = ytdl("https://youtube.com/watch?v=ERu6jh_1gR0", {
filter: "audioonly",
opusEncoded: false,
fmt: "mp3",
encoderArgs: ['-af', 'bass=g=10,dynaudnorm=f=200']
});
msg.member.voice.channel.join()
.then(connection => {
let dispatcher = connection.play(stream, {
type: "unknown"
})
.on("finish", () => {
msg.guild.me.voice.channel.leave();
})
});
}
});
client.login("TOKEN");
\`\`\`
## Converted Stream
\`\`\`js
const ytdl = require("discord-ytdl-core");
const Discord = require("discord.js");
const client = new Discord.Client();
client.on("ready", () => {
console.log("ready")
});
client.on("message", msg => {
if (msg.author.bot || !msg.guild) return;
if (msg.content === "!play") {
if (!msg.member.voice.channel) return msg.channel.send("You're not in a voice channel?");
let stream = ytdl("https://youtube.com/watch?v=ERu6jh_1gR0", {
filter: "audioonly",
opusEncoded: false,
encoderArgs: ['-af', 'bass=g=10,dynaudnorm=f=200']
});
msg.member.voice.channel.join()
.then(connection => {
let dispatcher = connection.play(stream, {
type: "converted"
})
.on("finish", () => {
msg.guild.me.voice.channel.leave();
})
});
}
});
client.login("TOKEN");
\`\`\`
# Downloading the video
\`\`\`js
const ytdl = require("../index.js");
const { createWriteStream } = require ("fs");
const url = "https://www.youtube.com/watch?v=zrwTYozyzYA";
let stream = ytdl(url, {
encoderArgs: ["-af", "asetrate=44100*1.25,bass=g=20,dynaudnorm=f=150"],
fmt: "mp3",
opusEncoded: false
});
stream.pipe(createWriteStream(__dirname+"/test.mp3"));
\`\`\`
# Arbitrary Stream
\`\`\`js
const ytdl = require("discord-ytdl-core");
const Discord = require("discord.js");
const client = new Discord.Client();
client.on("ready", () => {
console.log("ready")
});
client.on("message", msg => {
if (msg.author.bot || !msg.guild) return;
if (msg.content === "!play") {
if (!msg.member.voice.channel) return msg.channel.send("You're not in a voice channel?");
let stream = ytdl.arbitraryStream("https://listen.moe/kpop/opus", {
opusEncoded: true,
encoderArgs: ['-af', 'bass=g=10,dynaudnorm=f=200']
});
msg.member.voice.channel.join()
.then(connection => {
let dispatcher = connection.play(stream, {
type: "opus"
})
.on("finish", () => {
msg.guild.me.voice.channel.leave();
})
});
}
});
client.login("TOKEN");
\`\`\`
# Other functions
Visit **[ytdl-core](https://npmjs.com/package/ytdl-core)** for other functions.
# Related
- **[ytdl-core-discord](https://npmjs.com/package/ytdl-core-discord)**
- **[discord-player](https://npmjs.com/discord-player)**
# Developers
- **[@Snowflake107](https://github.com/Snowflake107)**
- **[@Androz2091](https://github.com/Androz2091)**
# Join our Official Discord Server
- **[Snowflake Development ❄️](https://discord.gg/uqB8kxh)**
- **[AndrozDev](https://discord.gg/Qreejcu)**
`;
document.addEventListener("DOMContentLoaded", (e) => {
document.querySelectorAll('pre code').forEach((block) => {
hljs.highlightBlock(block);
});
});
var converter = new showdown.Converter();
var html = converter.makeHtml(markdown);
document.getElementById("data").innerHTML = html;