fix(route): fix youku/channel route is empty and refactor to V2 (#9002)

* Fix(route): fix route is empty and change to V2

* Fix(route): change HTTP to HTTPS
This commit is contained in:
Fatpandac 2022-02-06 19:33:32 +08:00 committed by GitHub
parent 3f04a89e48
commit e436c5d270
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 81 additions and 60 deletions

View File

@ -1315,7 +1315,7 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
### 频道
<Route author="xyqfer" example="/youku/channel/UNTg3MTM3OTcy" path="/youku/channel/:channelId/:embed?" :paramsDesc="['频道 id', '默认为开启内嵌视频, 任意值为关闭']"/>
<Route author="xyqfer Fatpandac" example="/youku/channel/UNTg3MTM3OTcy" path="/youku/channel/:channelId/:embed?" :paramsDesc="['频道 id', '默认为开启内嵌视频, 任意值为关闭']"/>
## 中国高清网

View File

@ -995,9 +995,6 @@ router.get('/xidian/jwc/:category?', lazyloadRouteHandler('./routes/universities
// Westore
router.get('/westore/new', lazyloadRouteHandler('./routes/westore/new'));
// 优酷
router.get('/youku/channel/:channelId/:embed?', lazyloadRouteHandler('./routes/youku/channel'));
// 油价
router.get('/oilprice/:area', lazyloadRouteHandler('./routes/oilprice'));

View File

@ -1,56 +0,0 @@
const got = require('@/utils/got');
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 got({
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 = `<iframe height=498 width=510 src='https://player.youku.com/embed/${videoId}' frameborder=0 'allowfullscreen'></iframe>`;
return {
title,
description: `
${embed ? iframe : ''}
<br>
<img src="${cover}">
`,
link,
};
} else {
return null;
}
})
.get()
.filter((item) => item),
};
};

56
lib/v2/youku/channel.js Normal file
View File

@ -0,0 +1,56 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const channelId = ctx.params.channelId;
const embed = !ctx.params.embed;
const response = await got({
method: 'get',
url: `https://i.youku.com/i/${channelId}/videos`,
headers: {
Host: 'i.youku.com',
Referer: `https://i.youku.com/i/${channelId}`,
},
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('div.videoitem_pack');
ctx.state.data = {
title: $('.username').text(),
link: `https://i.youku.com/i/${channelId}`,
description: $('.desc').text(),
item:
list &&
list
.map((_, item) => {
item = $(item);
const title = item.find('a.videoitem_videolink').attr('title');
const cover = item.find('a.videoitem_videolink > img').attr('src');
const $link = item.find('a.videoitem_videolink');
const link = $link.length > 0 ? `https:${$link.attr('href')}` : null;
const dateText = item.find('p.videoitem_subtitle').text().split('-').length === 2 ? `${new Date().getFullYear()}-${item.find('p.videoitem_subtitle').text()}` : item.find('p.videoitem_subtitle').text();
const pubDate = parseDate(dateText);
return link
? {
title,
description: art(path.join(__dirname, 'templates/channel.art'), {
embed,
videoId: path.parse(link).name.replace(/^id_/g, ''),
cover,
}),
link,
pubDate,
}
: null;
})
.get()
.filter((item) => item),
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/channel/:channelId/:embed?': ['xyqfer', 'Fatpandac'],
};

13
lib/v2/youku/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'youku.com': {
_name: '优酷',
i: [
{
title: '订阅作者',
docs: 'https://docs.rsshub.app/multimedia.html#you-ku',
source: ['/i/:id'],
target: '/youku/channel/:id',
},
],
},
};

3
lib/v2/youku/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/channel/:channelId/:embed?', require('./channel'));
};

View File

@ -0,0 +1,5 @@
{{ if embed }}
<iframe height=498 width=510 src='https://player.youku.com/embed/{{videoId}}' frameborder=0 'allowfullscreen'></iframe>
{{ /if }}
<br>
<img src="{{cover}}">