feat: 懂球帝又双叒叕改版了 (#3701)

This commit is contained in:
Henry Wang 2020-01-08 07:25:38 +00:00 committed by DIYgod
parent a73c2b2b17
commit bd7cd285ac
4 changed files with 48 additions and 70 deletions

View File

@ -1,7 +1,6 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');
const date = require('@/utils/date');
module.exports = async (ctx) => {
const response = await got.get('https://www.dongqiudi.com/special/48');
@ -41,24 +40,11 @@ module.exports = async (ctx) => {
const responses = await got.all(proList);
for (let i = 0; i < proList.length; i++) {
const $ = utils.ProcessVideo(cheerio.load(responses[i].data));
const full = $('div.detail');
out[i].description = utils.ProcessHref(full.find('div:nth-of-type(1)')).html();
out[i].author = full.find('span.name').text();
out[i].pubDate = date(
full
.find('span.time')
.text()
.trim(),
8
);
ctx.cache.set(out[i].itemUrl, JSON.stringify(out[i]));
utils.ProcessFeedType2(out[i], responses[i].data);
}
ctx.state.data = {
title: '懂球帝早报',
link: 'http://www.dongqiudi.com/special/48',
item: out.filter((e) => e !== undefined),
item: out.filter((e) => e.description !== undefined),
};
};

View File

@ -1,7 +1,6 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');
const date = require('@/utils/date');
module.exports = async (ctx) => {
const id = ctx.params.id;
@ -41,20 +40,7 @@ module.exports = async (ctx) => {
const responses = await got.all(proList);
for (let i = 0; i < proList.length; i++) {
const $ = utils.ProcessVideo(cheerio.load(responses[i].data));
const full = $('div.detail');
out[i].description = utils.ProcessHref(full.find('div:nth-of-type(1)')).html();
out[i].author = full.find('span.name').text();
out[i].pubDate = date(
full
.find('span.time')
.text()
.trim(),
8
);
ctx.cache.set(out[i].itemUrl, JSON.stringify(out[i]));
utils.ProcessFeedType2(out[i], responses[i].data);
}
ctx.state.data = {
title: `懂球帝专题-${id}`,

View File

@ -1,7 +1,5 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');
const date = require('@/utils/date');
module.exports = async (ctx) => {
const id = ctx.params.id || 1;
@ -34,18 +32,7 @@ module.exports = async (ctx) => {
const responses = await got.all(proList);
for (let i = 0; i < proList.length; i++) {
const $ = utils.ProcessVideo(cheerio.load(responses[i].data));
const full = $('div.detail');
out[i].description = utils.ProcessHref(full.find('div:nth-of-type(1)')).html();
out[i].author = full.find('span.name').text();
out[i].pubDate = date(
full
.find('span.time')
.text()
.trim(),
8
);
utils.ProcessFeedType2(out[i], responses[i].data);
}
ctx.state.data = {
title: `懂球帝 - ${label}`,

View File

@ -1,24 +1,31 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
const url = require('url');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const ProcessVideo = (content) => {
content('div.video').each((i, v) => {
let link = v.attribs.src;
switch (v.attribs.site) {
case 'qiniu':
// 临时解决七牛 CDN 证书过期
link = link.replace('https://', 'http://');
content(`<video width="100%" controls="controls"> <source src="${link}" type="video/mp4"> Your RSS reader does not support video playback. </video>`).insertAfter(v);
content(v).remove();
break;
case 'youku':
content(`<iframe height='100%' width='100%' src='${link}' frameborder=0 scrolling=no webkitallowfullscreen=true allowfullscreen=true></iframe>`).insertAfter(v);
content(v).remove();
break;
default:
break;
let link = url.parse(v.attribs.src);
if (link.host === 'm.miguvideo.com') {
content(`<a href="${link.href}"> ▶️ 观看视频 </a><br>`).insertAfter(v);
content(v).remove();
} else {
link = v.attribs.src;
switch (v.attribs.site) {
case 'qiniu':
// 临时解决七牛 CDN 证书过期
link = link.replace('https://', 'http://');
content(`<video width="100%" controls="controls"> <source src="${link}" type="video/mp4"> Your RSS reader does not support video playback. </video>`).insertAfter(v);
content(v).remove();
break;
case 'youku':
content(`<iframe height='100%' width='100%' src='${link}' frameborder=0 scrolling=no webkitallowfullscreen=true allowfullscreen=true></iframe>`).insertAfter(v);
content(v).remove();
break;
default:
break;
}
}
});
@ -26,7 +33,7 @@ const ProcessVideo = (content) => {
content('iframe.media-iframe, .edui-faked-video').each((i, v) => {
const link = v.attribs.src;
if (link.startsWith('http://ssports.iqiyi.com')) {
content(`<a href="${link}">观看视频</a><br>`).insertAfter(v);
content(`<a href="${link.link}"> ▶️ 观看视频 </a><br>`).insertAfter(v);
}
content(v).remove();
@ -36,16 +43,11 @@ const ProcessVideo = (content) => {
};
const ProcessHref = (content) => {
content.each((i, v) => {
cheerio
.load(v)('a')
.each((j, y) => {
if (y.attribs.href) {
y.attribs.href = y.attribs.href.replace('dongqiudi:///news', 'https://www.dongqiudi.com/share/article');
}
});
content.each((j, y) => {
if (y.attribs.href) {
y.attribs.href = y.attribs.href.replace('dongqiudi:///news', 'https://www.dongqiudi.com/share/article');
}
});
return content;
};
const ProcessFeed = async (ctx, link, type) => {
@ -90,7 +92,7 @@ const ProcessFeed = async (ctx, link, type) => {
}
});
ProcessHref(content);
ProcessHref(content.find('a'));
const single = {
title: item.title,
@ -111,8 +113,25 @@ const ProcessFeed = async (ctx, link, type) => {
};
};
const ProcessFeedType2 = (item, response) => {
const dom = new JSDOM(response, {
runScripts: 'dangerously',
});
const data = dom.window.__NUXT__.data[1].newData;
if (Object.keys(data).length > 0) {
const body = ProcessVideo(cheerio.load(data.body));
ProcessHref(body('a'));
item.description = body.html();
item.author = data.writer;
item.pubDate = new Date(data.show_time * 1000).toUTCString();
}
};
module.exports = {
ProcessVideo,
ProcessFeed,
ProcessFeedType2,
ProcessHref,
};