Skip to content

Commit

Permalink
feat: add router yahoo-jp-tv (Yahoo!テレビ) (DIYgod#3928)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakamossan authored Feb 9, 2020
1 parent 7eee7cd commit f2bb385
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/multimedia.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ pageClass: routes

<Route author="fallenhh" example="/soundcloud/tracks/angeart" path="/soundcloud/tracks/:user" :paramsDesc="['用户名']" />

## Yahoo!テレビ

### 番組検索

<Route author="sakamossan" example="/yahoo-jp-tv/%E8%8A%B1%E6%BE%A4%E9%A6%99%E8%8F%9C" path="/yahoo-jp-tv/:query" :paramsDesc="['搜索查询']"/>

## Youtube

[#youtube](/social-media.html#youtube)
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
27 changes: 27 additions & 0 deletions lib/routes/yahoo-jp-tv/index.js
Original file line number Diff line number Diff line change
@@ -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 };
};

0 comments on commit f2bb385

Please sign in to comment.