Skip to content

Commit

Permalink
fix(route): 6v123 processItems export error (#15587)
Browse files Browse the repository at this point in the history
* fix: processItems export error

* fix: optimize code typo
  • Loading branch information
xianghuawe authored May 14, 2024
1 parent e5ba8ab commit 14e7761
Showing 1 changed file with 58 additions and 62 deletions.
120 changes: 58 additions & 62 deletions lib/routes/6v123/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,76 @@ import { load } from 'cheerio';
import timezone from '@/utils/timezone';
import { parseDate } from '@/utils/parse-date';

const utils = {
loadDetailPage: async function loadDetailPage(link) {
const response = await got.get(link, {
responseType: 'buffer',
});
response.data = iconv.decode(response.data, 'gb2312');
export async function loadDetailPage(link) {
const response = await got.get(link, {
responseType: 'buffer',
});
response.data = iconv.decode(response.data, 'gb2312');

const $ = load(response.data);
const $ = load(response.data);

const detailInfo = {
title: $('title')
.text()
.replaceAll(/|6v/g, ''),
description: $('meta[name="description"]').attr('content'),
enclosure_urls: $('table td')
.map((i, e) => ({
title: $(e).text().replace('磁力:', ''),
magnet: $(e).find('a').attr('href'),
}))
.toArray()
.filter((item) => item.magnet?.includes('magnet')),
};
return detailInfo;
},
processItems: async (ctx, baseURL) => {
const response = await got.get(baseURL, {
responseType: 'buffer',
});
response.data = iconv.decode(response.data, 'gb2312');
return {
title: $('title')
.text()
.replaceAll(/|6v/g, ''),
description: $('meta[name="description"]').attr('content'),
enclosure_urls: $('table td')
.map((i, e) => ({
title: $(e).text().replace('磁力:', ''),
magnet: $(e).find('a').attr('href'),
}))
.toArray()
.filter((item) => item.magnet?.includes('magnet')),
};
}

const $ = load(response.data);
const list = $('ul.list')[0].children;
export async function processItems(ctx, baseURL) {
const response = await got.get(baseURL, {
responseType: 'buffer',
});
response.data = iconv.decode(response.data, 'gb2312');

const process = await Promise.all(
list.map((item) => {
const link = $(item).find('a');
const href = link.attr('href');
const pubDate = timezone(parseDate($(item).find('span').text().replaceAll(/[[\]]/g, ''), 'MM-DD'), +8);
const $ = load(response.data);
const list = $('ul.list')[0].children;

if (href === undefined) {
return;
}
const process = await Promise.all(
list.map((item) => {
const link = $(item).find('a');
const href = link.attr('href');
const pubDate = timezone(parseDate($(item).find('span').text().replaceAll(/[[\]]/g, ''), 'MM-DD'), +8);

const itemUrl = 'https://www.hao6v.cc' + link.attr('href');
if (href === undefined) {
return;
}

return cache.tryGet(itemUrl, async () => {
const detailInfo = await utils.loadDetailPage(itemUrl);
const itemUrl = 'https://www.hao6v.cc' + link.attr('href');

if (detailInfo.enclosure_urls.length > 1) {
return detailInfo.enclosure_urls.map((url) => ({
enclosure_url: url.magnet,
enclosure_type: 'application/x-bittorrent',
title: `${link.text()} ( ${url.title} )`,
description: detailInfo.description,
pubDate,
link: itemUrl,
guid: `${itemUrl}#${url.title}`,
}));
}
return cache.tryGet(itemUrl, async () => {
const detailInfo = await loadDetailPage(itemUrl);

return {
enclosure_url: detailInfo.enclosure_urls.length === 0 ? '' : detailInfo.enclosure_urls[0].magnet,
if (detailInfo.enclosure_urls.length > 1) {
return detailInfo.enclosure_urls.map((url) => ({
enclosure_url: url.magnet,
enclosure_type: 'application/x-bittorrent',
title: link.text(),
title: `${link.text()} ( ${url.title} )`,
description: detailInfo.description,
pubDate,
link: itemUrl,
};
});
})
);
guid: `${itemUrl}#${url.title}`,
}));
}

return process.filter((item) => item !== undefined).flat();
},
};
return {
enclosure_url: detailInfo.enclosure_urls.length === 0 ? '' : detailInfo.enclosure_urls[0].magnet,
enclosure_type: 'application/x-bittorrent',
title: link.text(),
description: detailInfo.description,
pubDate,
link: itemUrl,
};
});
})
);

export default utils;
return process.filter((item) => item !== undefined).flat();
}

0 comments on commit 14e7761

Please sign in to comment.