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) {
|
||||
return url.startsWith("https://youtube") ||
|
||||
url.startsWith("https://youtu.be");
|
||||
url.startsWith("https://youtu.be");
|
||||
}
|
||||
|
||||
export async function extractId(url: string): Promise<string> {
|
||||
if (!isYTLink(url)) {
|
||||
const ytDlpBin = process.env.YT_DLP_BIN_PATH! ?? "yt-dlp";
|
||||
return await new Promise<string>((resolve, reject) => {
|
||||
const p = spawn(ytDlpBin, [
|
||||
"--print", "%(id)s",
|
||||
url,
|
||||
]);
|
||||
// if (!isYTLink(url)) {
|
||||
const ytDlpBin = process.env.YT_DLP_BIN_PATH! ?? "yt-dlp";
|
||||
return await new Promise<string>((resolve, reject) => {
|
||||
const p = spawn(ytDlpBin, [
|
||||
"--print", "%(id)s",
|
||||
url,
|
||||
]);
|
||||
|
||||
let out = ""
|
||||
p.stderr.on("data", d => process.stderr.write(d));
|
||||
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")));
|
||||
});
|
||||
let out = ""
|
||||
p.stderr.on("data", d => process.stderr.write(d));
|
||||
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")));
|
||||
});
|
||||
|
||||
} else {
|
||||
const idMatch = /[?&]v=([a-zA-Z0-9_-]{11})/.exec(url);
|
||||
if (!idMatch) throw new Error("Cannot extract video ID");
|
||||
const id = idMatch[1];
|
||||
return id
|
||||
}
|
||||
// } else {
|
||||
// const idMatch = /[?&]v=([a-zA-Z0-9_-]{11})/.exec(url);
|
||||
// if (!idMatch) throw new Error("Cannot extract video ID");
|
||||
// const id = idMatch[1];
|
||||
// return id
|
||||
// }
|
||||
}
|
||||
|
||||
export async function downloadAudio(url: string): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user