* style: add eslint-unicorn * style: fix unicorn/no-useless-spread * style: fix unicorn/no-useless-promise-resolve-reject * style: fix unicorn/no-for-loop * fix: codeql bad HTML filtering regexp * fix: codeql incomplete replace * fix: unicorn/no-abusive-eslint-disable * style: fix unicorn/no-new-array * style: fix unicorn/no-typeof-undefined * style: fix unicorn/no-zero-fractions * style: fix unicorn/no-empty-file * style: fix unicorn/prefer-date-now * revert: auto fix unicorn/prefer-switch on lib/v2/kuaidi100/utils.js * style: fix unicorn/prefer-array-find * style: fix unicorn/prefer-array-flat * style: fix unicorn/prefer-array-flat-map * style: fix unicorn/prefer-at * style: fix unicorn/prefer-string-starts-ends-with * style: fix unicorn/prefer-includes * fix: codeql URL substring sanitization * style: fix unicorn/prefer-optional-catch-binding * style: fix unicorn/catch-error-name * style: fix unicorn/escape-case * style: fix unicorn/prefer-native-coercion-functions * style: fix unicorn/prefer-regexp-test * style: fix unicorn/require-array-join-separator * style: fix unicorn/prefer-math-trunc * style: fix unicorn/prefer-negative-index * style: fix unicorn/prefer-dom-node-dataset * style: fix unicorn/prefer-dom-node-text-content * style: fix unicorn/prefer-query-selector * style: fix unicorn/no-array-for-each * style: fix unicorn/no-negated-condition * style: fix unicorn/prefer-add-event-listener * style: fix unicorn/import-style * style: fix prefer-regex-literals * style: disable unicorn/no-useless-switch-case * style: disable unicorn/text-encoding-identifier-case * style: fix unicorn/prefer-set-has * style: fix unicorn/prefer-spread * revert: auto fix on lib/routes/universities/ynnu/edu/base64.js * style: fix unicorn/no-useless-undefined * style: fix unicorn/no-array-push-push * style: fix unicorn/no-useless-undefined again * style: fix unicorn/no-lonely-if * style: fix unicorn/prefer-reflect-apply * style: fix unicorn/switch-case-braces * style: fix unicorn/prefer-switch * style: fix unicorn/prefer-array-some * fix: deepscan UNUSED_VAR_ASSIGN * style: fix unicorn/prefer-ternary * fix: follow-up of unicorn/prefer-ternary * revert: auto fix of unicorn/prefer-string-slice for substring() * style: disable unicorn/prefer-string-slice fix: auto fix slice over deprecated substr * style: fix unicorn/throw-new-error * style: fix unicorn/filename-case * test: fix dateParser renaming * style: fix unicorn/better-regex * style: fix unicorn/prefer-string-replace-all * fix(deps): add sanitize-html * style: fix no-prototype-builtins * style: fix unicorn/consistent-destructuring * style: fix unicorn/consistent-function-scoping * style: fix unicorn/prefer-regexp-test * style: fix unicorn/prefer-logical-operator-over-ternary * style: fix unicorn/no-array-callback-reference * style: add prefer-object-has-own * style: warn unicorn/no-empty-file * style: fix unicorn/prefer-number-properties * style: fix no-useless-undefined again * style: fix unicorn/numeric-separators-style * style: disable unicorn/no-array-callback-reference false postive with cheerio
158 lines
5.7 KiB
JavaScript
158 lines
5.7 KiB
JavaScript
const got = require('@/utils/got');
|
|
const { art } = require('@/utils/render');
|
|
const path = require('path');
|
|
const cheerio = require('cheerio');
|
|
const get_sec_page_data = require('./get-sec-page-data');
|
|
|
|
const rootUrl = 'https://oreno3d.com';
|
|
|
|
const sortRename = {
|
|
favorites: '高評価',
|
|
hot: '急上昇',
|
|
latest: '新着',
|
|
popularity: '人気',
|
|
};
|
|
|
|
function get_user_url(rootUrl, ctx, sort) {
|
|
let userUrl = '';
|
|
// 判断userurl获取位置
|
|
if (ctx.params.keyword) {
|
|
const keyword = ctx.params.keyword;
|
|
userUrl = `${rootUrl}/search?sort=${sort}&keyword=${keyword}`;
|
|
} else if (ctx.params.characterid) {
|
|
const characterid = ctx.params.characterid;
|
|
userUrl = `${rootUrl}/characters/${characterid}?sort=${sort}`;
|
|
} else if (ctx.params.authorid) {
|
|
const authorid = ctx.params.authorid;
|
|
userUrl = `${rootUrl}/authors/${authorid}?sort=${sort}`;
|
|
} else if (ctx.params.tagid) {
|
|
const tagid = ctx.params.tagid;
|
|
userUrl = `${rootUrl}/tags/${tagid}?sort=${sort}`;
|
|
} else if (ctx.params.originid) {
|
|
const originid = ctx.params.originid;
|
|
userUrl = `${rootUrl}/origins/${originid}?sort=${sort}`;
|
|
}
|
|
return userUrl;
|
|
}
|
|
module.exports = async (ctx) => {
|
|
// 获取视频链接列表及标题
|
|
function getLinksTitle(response) {
|
|
const selector = 'a.box';
|
|
const $ = cheerio.load(response.data);
|
|
const title = $('div.g-main-list').find('h1.main-h').text();
|
|
const list = $(selector);
|
|
return { title, list };
|
|
}
|
|
// 数据爬取和分析
|
|
async function getData(response) {
|
|
const $ = cheerio.load(response.data);
|
|
// 第一页,获取搜索主标题
|
|
const title = getLinksTitle(response).title;
|
|
const list = getLinksTitle(response).list;
|
|
const items = await Promise.all(
|
|
list
|
|
.map(async (_, item) => {
|
|
// 第一页,获取搜各视频地址
|
|
const link = $(item).attr('href');
|
|
// 第二页数据分析+缓存
|
|
const sec_data = await get_sec_page_data(link);
|
|
// 传递
|
|
const raw_pic_link = sec_data.raw_pic_link;
|
|
const video_name = sec_data.video_name;
|
|
const authors = sec_data.authors;
|
|
const origins = sec_data.origins;
|
|
const characters = sec_data.characters;
|
|
const tags = sec_data.tags;
|
|
const desc = sec_data.desc;
|
|
const iwara_link = sec_data.iwara_link;
|
|
const oreno3d_link = sec_data.oreno3d_link;
|
|
// 打包,缓存HTML
|
|
const description = art(path.join(__dirname, 'templates/description.art'), {
|
|
raw_pic_link,
|
|
video_name,
|
|
authors,
|
|
origins,
|
|
characters,
|
|
tags,
|
|
desc,
|
|
iwara_link,
|
|
oreno3d_link,
|
|
});
|
|
const title = `${video_name} - ${authors}`;
|
|
const realData = await ctx.cache.tryGet(oreno3d_link, () => {
|
|
const result = {
|
|
title,
|
|
author: authors,
|
|
link: oreno3d_link,
|
|
category: tags.split(' '),
|
|
description,
|
|
};
|
|
return result;
|
|
});
|
|
return realData;
|
|
})
|
|
.get()
|
|
);
|
|
return { items, title };
|
|
}
|
|
// 参数定义
|
|
const sort = ctx.params.sort;
|
|
let pagelimit = ctx.params.pagelimit ?? 1;
|
|
// 根链接
|
|
const userUrl = get_user_url(rootUrl, ctx, sort);
|
|
// 确认最大页数并比较修改(同时也是获取第一页的内容)
|
|
const response = await got(userUrl);
|
|
const $ = cheerio.load(response.data);
|
|
const maxPageSelector = 'div.container > main > div.g-main-list > ul.pagination > li:last-child > a';
|
|
// 页码判断
|
|
if ($(maxPageSelector)) {
|
|
const pageLink = new URLSearchParams($(maxPageSelector).attr('href'));
|
|
const actualNum = pageLink.get('page'); // 获取最大页数
|
|
if (Number.parseInt(pagelimit) >= Number.parseInt(actualNum)) {
|
|
pagelimit = actualNum;
|
|
}
|
|
} else {
|
|
pagelimit = 1;
|
|
}
|
|
// 构造网页数据的对应数组
|
|
const responseList = [];
|
|
// 将第一页的数据加入数组
|
|
responseList.push(response);
|
|
// 创建不含第一页链接的数组
|
|
const Links = [];
|
|
for (let i = 1; i < pagelimit; i++) {
|
|
Links.push(`${userUrl}&page=${i + 1}`);
|
|
}
|
|
// 由数组索引添加response
|
|
await Promise.all(
|
|
Links.map(async (link) => {
|
|
const response = await got(link);
|
|
responseList.push(response);
|
|
})
|
|
);
|
|
// 由数组索引获取初步分析数据
|
|
const tempData = [];
|
|
await Promise.all(
|
|
responseList.map(async (response) => {
|
|
const result = await getData(response);
|
|
tempData.push(result);
|
|
})
|
|
);
|
|
// 拼接多页面item
|
|
let realItem = [];
|
|
for (const data of tempData) {
|
|
realItem = [...realItem, ...data.items];
|
|
}
|
|
// 构造最终data
|
|
const data = {
|
|
title: tempData[0].title,
|
|
item: realItem,
|
|
};
|
|
// 生成RSS源码
|
|
ctx.state.data = {
|
|
title: `${data.title} - ${sortRename[sort]}(Page 1-${pagelimit})`,
|
|
link: userUrl,
|
|
item: data.item,
|
|
};
|
|
};
|