fix: mp4kan 网页改版问题 (#12645)

This commit is contained in:
savokiss 2023-06-09 18:44:50 +08:00 committed by GitHub
parent a47d1b6810
commit 352cba2fdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 0 deletions

View File

@ -2,10 +2,36 @@ const cheerio = require('cheerio');
const got = require('@/utils/got');
const { baseUrl, decodeCipherText, composeMagnetUrl, getUrlType } = require('./utils');
// 兼容没有 script 标签的情况,直接解析 dom
function getDomList($, detailUrl) {
const list = $('.down-list li')
.toArray()
.map((item) => {
item = $(item);
const title = item.find('a').attr('title');
const downurl = item.find('a').attr('href');
const urlType = getUrlType(downurl);
const enclosureUrl = urlType === 'magnet' ? composeMagnetUrl(downurl) : downurl;
return {
enclosure_url: enclosureUrl,
enclosure_length: '',
enclosure_type: 'application/x-bittorrent',
title,
link: detailUrl,
guid: `${title}-${urlType}`,
};
});
return list;
}
function getItemList($, detailUrl) {
const encoded = $('.article script[type]')
.text()
.match(/return p}\('(.*)',(\d+),(\d+),'(.*)'.split\(/);
// 若 script 标签没有内容,直接解析 dom
if (!encoded) {
return getDomList($, detailUrl);
}
const data = JSON.parse(
decodeCipherText(encoded[1], encoded[2], encoded[3], encoded[4].split('|'), 0, {})
.match(/var down_urls=\\'(.*)\\'/)[1]