Skip to content

Commit

Permalink
rss: add smzdm keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jun 6, 2018
1 parent a3710f6 commit 9a118ae
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- 专辑
- EZTV
- Lookup Torrents by IMDB ID(根据 IMDB ID 查找种子)
- 什么值得买
- 关键词

## 鸣谢

Expand Down
16 changes: 16 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1114,3 +1114,19 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到
路由: `/eztv/torrents/:imdb_id`

参数: imdb_id,想搜寻的 show 的种子所对应的 IMDB ID,可在 [IMDB](https://www.imdb.com) 官网找到

## 什么值得买

::: tip 提示

网站也提供了部分 RSS:https://www.smzdm.com/dingyue

:::

### 关键词

举例: [https://rsshub.app/smzdm/keyword/女装](https://rsshub.app/smzdm/keyword/女装)

路由: `/smzdm/keyword/:keyword`

参数: keyword,你想订阅的关键词
7 changes: 5 additions & 2 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ router.get('/yande.re/post/popular_recent', require('./routes/yande.re/post_popu
router.get('/yande.re/post/:tags', require('./routes/yande.re/post'));
router.get('/yande.re/post/popular_recent/:period', require('./routes/yande.re/post_popular_recent'));

// nytimes
// 纽约时报
router.get('/nytimes/morning_post', require('./routes/nytimes/morning_post'));

// uukanshu
// UU看书
router.get('/uukanshu/chapter/:uid', require('./routes/uukanshu/chapter'));

// 喜马拉雅
Expand All @@ -290,4 +290,7 @@ router.get('/ximalaya/album/:classify/:id', require('./routes/ximalaya/album'));
// EZTV
router.get('/eztv/torrents/:imdb_id', require('./routes/eztv/imdb'));

// 什么值得买
router.get('/smzdm/keyword/:keyword', require('./routes/smzdm/keyword'));

module.exports = router;
63 changes: 63 additions & 0 deletions routes/smzdm/keyword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const config = require('../../config');
const formatPubDate = require('../../utils/date.js');

module.exports = async (ctx) => {
const keyword = ctx.params.keyword;

const response = await axios({
method: 'get',
url: `http://search.smzdm.com/?c=home&s=${encodeURI(keyword)}&order=time&v=b`,
headers: {
'User-Agent': config.ua,
Referer: `http://search.smzdm.com/?c=home&s=${encodeURI(keyword)}&order=time&v=b`,
},
});

const data = response.data;

const $ = cheerio.load(data);
const list = $('.feed-row-wide');

ctx.state.data = {
title: `${keyword} - 什么值得买`,
link: `http://search.smzdm.com/?c=home&s=${encodeURI(keyword)}&order=time&v=b`,
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: `${item
.find('.feed-block-title a')
.eq(0)
.text()
.trim()} - ${item
.find('.feed-block-title a')
.eq(1)
.text()
.trim()}`,
description: `${item
.find('.feed-block-descripe')
.contents()
.eq(2)
.text()
.trim()}<br>${item
.find('.feed-block-extras span')
.text()
.trim()}<br><img referrerpolicy="no-referrer" src="http:${item.find('.z-feed-img img').attr('src')}">`,
pubDate: formatPubDate(
item
.find('.feed-block-extras')
.contents()
.eq(0)
.text()
.trim()
),
link: `${item.find('.feed-block-title a').attr('href')}`,
};
})
.get(),
};
};
2 changes: 1 addition & 1 deletion routes/ximalaya/album.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const config = require('../../config');
const formatPubDate = require('../../utils/pubDate.js');
const formatPubDate = require('../../utils/date.js');

const baseUrl = 'http://www.ximalaya.com';
module.exports = async (ctx) => {
Expand Down
8 changes: 8 additions & 0 deletions utils/pubDate.js → utils/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ module.exports = (html) => {
math = / (\d+):(\d+)/.exec(html);
date = new Date(date.getFullYear(), date.getMonth(), date.getDate() - 1, math[1], math[2]);
return date.toUTCString();
} else if (/(\d+)-(\d+) (\d+):(\d+)/.exec(html)) {
math = /(\d+)-(\d+) (\d+):(\d+)/.exec(html);
date = new Date(date.getFullYear(), parseInt(math[1]) - 1, math[2], math[3], math[4]);
return date.toUTCString();
} else if (/(\d+):(\d+)/.exec(html)) {
math = /(\d+):(\d+)/.exec(html);
date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), math[1], math[2]);
return date.toUTCString();
} else if (/(\d+)(\d+) (\d+):(\d+)/.exec(html)) {
math = /(\d+)(\d+) (\d+):(\d+)/.exec(html);
date = new Date(date.getFullYear(), parseInt(math[1]) - 1, math[2], math[3], math[4]);
Expand Down

0 comments on commit 9a118ae

Please sign in to comment.