bugfix hifini爬取时,一个thread中包含多首音乐时,获取real链接时重复获取问题
This commit is contained in:
parent
8a5cd1225a
commit
fae4db04a3
@ -159,24 +159,22 @@ async function getDetail(threadId) {
|
|||||||
async function startFetchRealUrl() {
|
async function startFetchRealUrl() {
|
||||||
let urlsToFetch = await dataManager.thread.getIdsToFetchRealUrl();
|
let urlsToFetch = await dataManager.thread.getIdsToFetchRealUrl();
|
||||||
// console.log(urlsToFetch.map(item => item.thread_id));
|
// 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++) {
|
for (let i = 0; i < urlsToFetch.length; i++) {
|
||||||
const urlToFetch = urlsToFetch[i];
|
const urlToFetch = urlsToFetch[i];
|
||||||
console.log(`getRealUrl\t| ${i + 1}/${urlsToFetch.length} | threadId: ${urlToFetch.threadId}`);
|
console.log(`getRealUrl\t| ${i + 1}/${urlsToFetch.length} | threadId: ${urlToFetch.thread_id} | music_index: ${urlToFetch.music_index}`);
|
||||||
await getRealUrl(urlToFetch);
|
await getRealUrl(urlToFetch.thread_id, urlToFetch.music_index, urlToFetch.music_url);
|
||||||
// await sleepUtils.sleep(100);
|
// await sleepUtils.sleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getRealUrl(urlToFetch) {
|
async function getRealUrl(threadId, musicIndex, fakeUrl) {
|
||||||
let { threadId, fakeUrl } = urlToFetch;
|
|
||||||
let url = "原地址已失效";
|
let url = "原地址已失效";
|
||||||
try {
|
try {
|
||||||
url = await requestUtils.getRedirectUrl(`https://hifini.com/${fakeUrl}`);
|
url = await requestUtils.getRedirectUrl(`https://hifini.com/${fakeUrl}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("重定向地址获取失败");
|
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();
|
main();
|
@ -31,7 +31,7 @@ module.exports = {
|
|||||||
|
|
||||||
getIdsToFetchRealUrl: async () => {
|
getIdsToFetchRealUrl: async () => {
|
||||||
let sql = `
|
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?.order ? `ORDER BY thread_id ${global.args.order}` : ""}
|
||||||
${global.args?.limit ? `LIMIT ${global.args.limit}` : ""}
|
${global.args?.limit ? `LIMIT ${global.args.limit}` : ""}
|
||||||
`;
|
`;
|
||||||
|
Loading…
Reference in New Issue
Block a user