1
0
Code Issues Pull Requests Projects Releases Wiki Activity GitHub Gitee

bugfix hifini爬取时,一个thread中包含多首音乐时,获取real链接时重复获取问题

This commit is contained in:
程序员小墨 2022-10-29 16:40:41 +08:00
parent 8a5cd1225a
commit fae4db04a3
2 changed files with 5 additions and 7 deletions

View File

@ -159,24 +159,22 @@ async function getDetail(threadId) {
async function startFetchRealUrl() {
let urlsToFetch = await dataManager.thread.getIdsToFetchRealUrl();
// console.log(urlsToFetch.map(item => item.thread_id));
urlsToFetch = urlsToFetch.map(item => { return { threadId: item.thread_id, fakeUrl: item.music_url } });
for (let i = 0; i < urlsToFetch.length; i++) {
const urlToFetch = urlsToFetch[i];
console.log(`getRealUrl\t| ${i + 1}/${urlsToFetch.length} | threadId: ${urlToFetch.threadId}`);
await getRealUrl(urlToFetch);
console.log(`getRealUrl\t| ${i + 1}/${urlsToFetch.length} | threadId: ${urlToFetch.thread_id} | music_index: ${urlToFetch.music_index}`);
await getRealUrl(urlToFetch.thread_id, urlToFetch.music_index, urlToFetch.music_url);
// await sleepUtils.sleep(100);
}
}
async function getRealUrl(urlToFetch) {
let { threadId, fakeUrl } = urlToFetch;
async function getRealUrl(threadId, musicIndex, fakeUrl) {
let url = "原地址已失效";
try {
url = await requestUtils.getRedirectUrl(`https://hifini.com/${fakeUrl}`);
} catch (e) {
console.log("重定向地址获取失败");
}
result = await dataManager.thread.update(threadId, 0, { music_real_url: url });
result = await dataManager.thread.update(threadId, musicIndex, { music_real_url: url });
}
main();

View File

@ -31,7 +31,7 @@ module.exports = {
getIdsToFetchRealUrl: async () => {
let sql = `
SELECT thread_id,music_url FROM hifini_thread WHERE music_url like 'get_music.php?key=%' and music_real_url=''
SELECT thread_id,music_index,music_url FROM hifini_thread WHERE music_url like 'get_music.php?key=%' and music_real_url=''
${global.args?.order ? `ORDER BY thread_id ${global.args.order}` : ""}
${global.args?.limit ? `LIMIT ${global.args.limit}` : ""}
`;