gpt4 book ai didi

javascript - 下载特定歌曲时 Ffmpeg 崩溃

转载 作者:行者123 更新时间:2023-12-04 23:10:24 31 4
gpt4 key购买 nike

我有一个音乐机器人,可以根据用户输入(可以是单词或链接)将歌曲下载到 mp3。问题是当我通过像“jojo op 3”这样的歌曲时,它会搜索歌曲,当它返回像“JoJo's Bizarre Adventure Opening 3 | 4K | 60FPS | Creditless”这样的歌曲名称时,ffmpeg 返回

Error: ffmpeg exited with code 1: ./musicSaves/JoJo's Bizarre Adventure Opening 3 | 4K | 60FPS | Creditless.mp3: Invalid argument
但是对于其他歌曲,例如 manuel 的 gas gas gas,它会正常下载,我一辈子都不知道为什么会这样。下面是下载代码:
import puppeteer from 'puppeteer';
import youtubeMp3Converter from 'youtube-mp3-converter';

//Tries to find link in message using Regex
export function getLink(messageLink){
const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
let link = messageLink.match(urlRegex);

if(link == null){
findSongName(messageLink)
} else {
convertToMp3(link)
}
}

//Converts source to mp3 to be played by audio player
async function convertToMp3(inputLink){
const convertLinkToMp3 = youtubeMp3Converter('./musicSaves')
const pathToMp3 = await convertLinkToMp3(inputLink)
}

//If link isn't found; tries to find source using puppeteer
async function findSongName(stringWithName){

const searchYT = async (page, searchQuery) => {
const encodedQuery = encodeURIComponent(searchQuery);
const url = `https://www.youtube.com/results?search_query=${encodedQuery}`;
await page.goto(url);
const sel = "a#video-title";
await page.waitForSelector(sel);
return page.$$eval(sel, els =>
els.map(e => ({
title: e.textContent.trim(),
href: e.href,
}))
);
};

let browser;
(async () => {
browser = await puppeteer.launch({headless: true});
const [page] = await browser.pages();
await page.setRequestInterception(true);
page.on("request", req => {
req.resourceType() === "image" ? req.abort() : req.continue();
});
const results = await searchYT(page, stringWithName);
const finalLink = results[0].href;
convertToMp3(finalLink);
})()
.catch(err => console.error(err))
.finally(() => browser?.close());
}

最佳答案

从文件名中删除特殊字符。 ' 和 |。

关于javascript - 下载特定歌曲时 Ffmpeg 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70712739/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com