działaj ty kurwo
This commit is contained in:
@@ -20,30 +20,30 @@ export async function getAudioFile(url: string): Promise<string> {
|
|||||||
|
|
||||||
function isYTLink(url: string) {
|
function isYTLink(url: string) {
|
||||||
return url.startsWith("https://youtube") ||
|
return url.startsWith("https://youtube") ||
|
||||||
url.startsWith("https://youtu.be");
|
url.startsWith("https://youtu.be");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function extractId(url: string): Promise<string> {
|
export async function extractId(url: string): Promise<string> {
|
||||||
if (!isYTLink(url)) {
|
// if (!isYTLink(url)) {
|
||||||
const ytDlpBin = process.env.YT_DLP_BIN_PATH! ?? "yt-dlp";
|
const ytDlpBin = process.env.YT_DLP_BIN_PATH! ?? "yt-dlp";
|
||||||
return await new Promise<string>((resolve, reject) => {
|
return await new Promise<string>((resolve, reject) => {
|
||||||
const p = spawn(ytDlpBin, [
|
const p = spawn(ytDlpBin, [
|
||||||
"--print", "%(id)s",
|
"--print", "%(id)s",
|
||||||
url,
|
url,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let out = ""
|
let out = ""
|
||||||
p.stderr.on("data", d => process.stderr.write(d));
|
p.stderr.on("data", d => process.stderr.write(d));
|
||||||
p.stdout.on("data", d => out += d.toString());
|
p.stdout.on("data", d => out += d.toString());
|
||||||
p.on("close", code => code === 0 ? resolve(out.trim()) : reject(new Error("yt-dlp extract id failed")));
|
p.on("close", code => code === 0 ? resolve(out.trim()) : reject(new Error("yt-dlp extract id failed")));
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
// } else {
|
||||||
const idMatch = /[?&]v=([a-zA-Z0-9_-]{11})/.exec(url);
|
// const idMatch = /[?&]v=([a-zA-Z0-9_-]{11})/.exec(url);
|
||||||
if (!idMatch) throw new Error("Cannot extract video ID");
|
// if (!idMatch) throw new Error("Cannot extract video ID");
|
||||||
const id = idMatch[1];
|
// const id = idMatch[1];
|
||||||
return id
|
// return id
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadAudio(url: string): Promise<void> {
|
export async function downloadAudio(url: string): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user