diff --git a/docs/multimedia.md b/docs/multimedia.md index 2c5a98dc7..045ce94c6 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -243,6 +243,12 @@ pageClass: routes +## Yahoo!テレビ + +### 番組検索 + + + ## Youtube 见 [#youtube](/social-media.html#youtube) diff --git a/lib/router.js b/lib/router.js index fb93f180f..154e263f6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2110,6 +2110,9 @@ router.get('/rthk-news/:lang/:category', require('./routes/rthk-news/index')); // yahoo router.get('/yahoo-news/:region/:category?', require('./routes/yahoo-news/index')); +// Yahoo!テレビ +router.get('/yahoo-jp-tv/:query', require('./routes/yahoo-jp-tv/index')); + // 白鲸出海 router.get('/baijing', require('./routes/baijing')); diff --git a/lib/routes/yahoo-jp-tv/index.js b/lib/routes/yahoo-jp-tv/index.js new file mode 100644 index 000000000..ec9b9207f --- /dev/null +++ b/lib/routes/yahoo-jp-tv/index.js @@ -0,0 +1,27 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const querystring = require('querystring'); + +module.exports = async (ctx) => { + const query = querystring.stringify({ q: ctx.params.query }); + const link = `https://tv.yahoo.co.jp/search/?${query}`; + const response = await got(link); + const $ = cheerio.load(response.body); + const [title] = $('.search_result') + .find('p') + .text() + .split(':'); + const item = $('.programlist li') + .map((index, item) => { + const $item = $(item); + const title = `${$item + .find('.leftarea') + .text() + .replace(/\n/g, '')} ${$item.find('.yjLS').text()}`; + const link = `https://tv.yahoo.co.jp${$item.find('div.rightarea p.yjLS.pb5p a').attr('href')}`; + const description = $item.find('p.yjMS:nth-child(3)').text(); + return { title, description, link }; + }) + .get(); + ctx.state.data = { title, link, item }; +};