From 5b28a7263d350da1d560d0a5257673aed129dc24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=89=E5=87=89?= Date: Fri, 26 Oct 2018 10:46:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E4=BC=98=E9=85=B7-?= =?UTF-8?q?=E9=A2=91=E9=81=93=20(#972)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现 #402 --- docs/README.md | 4 +++ router.js | 3 +++ routes/youku/channel.js | 56 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 routes/youku/channel.js diff --git a/docs/README.md b/docs/README.md index 2615932a3..c8c41a236 100644 --- a/docs/README.md +++ b/docs/README.md @@ -775,6 +775,10 @@ GitHub 官方也提供了一些 RSS: +### 优酷 + + + ## 图片 ### 妹子图 diff --git a/router.js b/router.js index ed5532fa9..f95db4ae7 100644 --- a/router.js +++ b/router.js @@ -689,6 +689,9 @@ router.get('/chouti/:subject?', require('./routes/chouti')); // 西安电子科技大学 router.get('/xidian/jwc/:category?', require('./routes/xidian/jwc')); +// 优酷 +router.get('/youku/channel/:channelId/:embed?', require('./routes/youku/channel')); + // 油价 router.get('/oilprice/:area', require('./routes/oilprice')); diff --git a/routes/youku/channel.js b/routes/youku/channel.js new file mode 100644 index 000000000..71e92ae64 --- /dev/null +++ b/routes/youku/channel.js @@ -0,0 +1,56 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const path = require('path'); + +module.exports = async (ctx) => { + const channelId = ctx.params.channelId; + const embed = !ctx.params.embed; + + const response = await axios({ + method: 'get', + url: `http://i.youku.com/i/${channelId}/videos`, + headers: { + Host: 'i.youku.com', + Referer: `http://i.youku.com/i/${channelId}`, + }, + }); + + const data = response.data; + const $ = cheerio.load(data); + const list = $('.items > .v'); + + ctx.state.data = { + title: $('.username').text(), + link: `http://i.youku.com/i/${channelId}`, + description: $('.desc').text(), + item: + list && + list + .map((index, item) => { + item = $(item); + const cover = item.find('.v-thumb img').attr('src'); + const title = item.find('.v-link a').attr('title'); + const $link = item.find('.v-meta-title > a'); + const link = $link.length > 0 ? `https:${$link.attr('href')}` : null; + + if (link) { + const videoId = path.parse(link).name.replace(/^id_/g, ''); + const iframe = ``; + + return { + title, + description: ` + ${embed ? iframe : ''} +
+ + `, + link, + }; + } else { + return null; + } + }) + .get() + .filter((item) => item), + }; +};