早报视频处理 (#829)

This commit is contained in:
Henry Wang
2018-10-07 16:02:49 +08:00
committed by DIYgod
parent 76b4feb92b
commit f170752f04
2 changed files with 25 additions and 19 deletions
+4 -3
View File
@@ -1,12 +1,13 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const utils = require('./utils');
module.exports = async (ctx) => {
const response = await axios.get('http://www.dongqiudi.com/special/48');
const response = await axios.get('https://www.dongqiudi.com/special/48');
const $ = cheerio.load(response.data);
const host = 'http://www.dongqiudi.com';
const host = 'https://www.dongqiudi.com';
const list = $('.detail.special ul li h3')
.slice(0, 10)
@@ -37,7 +38,7 @@ module.exports = async (ctx) => {
const responses = await axios.all(proList);
for (let i = 0; i < responses.length; i++) {
const $ = cheerio.load(responses[i].data);
const $ = utils.ProcessVideo(cheerio.load(responses[i].data));
const full = $('div.detail');
out[i].description = full.find('div:nth-of-type(1)').html();
+21 -16
View File
@@ -2,7 +2,27 @@ const dayjs = require('dayjs');
const cheerio = require('cheerio');
const axios = require('../../utils/axios');
const ProcessVideo = (content) => {
content('div.video').each((i, v) => {
const link = v.attribs.src;
switch (v.attribs.site) {
case 'qiniu':
content(`<video width="100%" 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;
}
});
return content;
};
module.exports = {
ProcessVideo: ProcessVideo,
ProcessFeed: async (ctx, link, api) => {
const axios_ins = axios.create({
headers: {
@@ -20,22 +40,7 @@ module.exports = {
list.map(async (item) => {
const itemUrl = item.web_url;
const res = await axios_ins.get(itemUrl);
const content = cheerio.load(res.data);
content('div.video').each((i, v) => {
const link = v.attribs.src;
switch (v.attribs.site) {
case 'qiniu':
content('div.video').replaceWith(`<video width="100%" controls> <source src="${link}" type="video/mp4"> Your RSS reader does not support video playback. </video>`);
break;
case 'youku':
content('div.video').replaceWith(`<iframe height='100%' width='100%' src='${link}' frameborder=0 scrolling=no webkitallowfullscreen=true allowfullscreen=true></iframe>`);
break;
default:
break;
}
});
const content = ProcessVideo(cheerio.load(res.data));
const serverOffset = new Date().getTimezoneOffset() / 60;
const single = {
title: content('h1').text(),