Files
RSSHub/lib/v2/1lou/index.js
T
falling 82622e71c5 feat(route): add BT之家1LOU站 (#14219)
* route: BT之家1LOU

* 1. using new routers.
2. If path is empty, visit correct main page of website.
3. roll back deleted doc by mistake.

* Update lib/v2/1lou/radar.js

* Update website/docs/routes/multimedia.mdx

* Update website/docs/routes/multimedia.mdx

---------
2024-01-12 22:37:18 +08:00

54 lines
1.8 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const path = ctx.params.path ?? '';
const rootUrl = `https://www.1lou.me`;
const currentUrl = `${rootUrl}/${path}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
let items = $('li.media.thread.tap:not(.hidden-sm)')
.toArray()
.map((item) => {
const title = $(item).find('.subject.break-all').children('a').first();
const author = $(item).find('.username.text-grey.mr-1').text();
const pubDate = $(item).find('.date.text-grey').text();
return {
title: title.text(),
link: `${rootUrl}/${title.attr('href')}`,
author,
pubDate: timezone(parseDate(pubDate), +8),
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.message.break-all').html();
const torrents = content('.attachlist').find('a');
if (torrents.length > 0) {
item.enclosure_type = 'application/x-bittorrent';
item.enclosure_url = `${rootUrl}/${torrents.first().attr('href')}`;
}
return item;
})
)
);
ctx.state.data = {
title: '1Lou',
link: currentUrl,
item: items,
};
};