From 9f42bbfbba6924ee8e2e54397360ccbd48f186a4 Mon Sep 17 00:00:00 2001 From: Jeff Wen Date: Mon, 20 Aug 2018 14:20:46 +0800 Subject: [PATCH] feat: update 3dm download rss (#496) --- .gitignore | 1 + README.md | 1 + docs/README.md | 8 +++++++ router.js | 1 + routes/3dm/download.js | 52 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 routes/3dm/download.js diff --git a/.gitignore b/.gitignore index 304d50972..cc790af67 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ docs/.vuepress/dist config/app.json config/config.js +yarn-error.log diff --git a/README.md b/README.md index 290a4f5bb..21cf02996 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 新闻中心 - 新闻 - 攻略 + - 下载 - 喜马拉雅 - 专辑 - EZTV diff --git a/docs/README.md b/docs/README.md index a9c7423b2..d64cb7455 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1322,6 +1322,14 @@ language,语言,可在 [Trending 页](https://github.com/trending/javascript 参数: name,游戏的编号可以在专题页的 url 中找到 +### 下载 + +举例: [https://rsshub.app/3dm/detroitbecomehuman/download](https://rsshub.app/3dm/detroitbecomehuman/download) + +路由: `/3dm/:name/download` + +参数: name,游戏的编号可以在专题页的 url 中找到 + ## 喜马拉雅 ### 专辑 diff --git a/router.js b/router.js index 1a5725aa5..ad793d326 100755 --- a/router.js +++ b/router.js @@ -285,6 +285,7 @@ router.get('/nytimes/morning_post', require('./routes/nytimes/morning_post')); router.get('/uukanshu/chapter/:uid', require('./routes/uukanshu/chapter')); // 3dm +router.get('/3dm/:name/download', require('./routes/3dm/download')); router.get('/3dm/:name/:type', require('./routes/3dm/news')); router.get('/3dm/news', require('./routes/3dm/news_center')); diff --git a/routes/3dm/download.js b/routes/3dm/download.js new file mode 100644 index 000000000..5e2ff02a8 --- /dev/null +++ b/routes/3dm/download.js @@ -0,0 +1,52 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const name = ctx.params.name; + const type = 'download'; + const url = `http://www.3dmgame.com/games/${name}/${type}`; + + const response = await axios({ + method: 'get', + url: url, + headers: { + 'User-Agent': config.ua, + }, + }); + + const data = response.data; + + const $ = cheerio.load(data); + const list = $('.ZQ_Left .Llis_4 li'); + const items = []; + + for (let i = 0; i < list.length; i++) { + let item = $(list[i]); + const url = item.find('.bt').attr('href'); + + const value = await ctx.cache.get(url); + if (value) { + item = JSON.parse(value); + } else { + item = { + title: item.find('.bt').text(), + pubDate: item.find('p').text(), + link: url, + guid: url, + }; + + ctx.cache.set(url, JSON.stringify(item), 24 * 60 * 60); + } + + items.push(item); + } + + ctx.state.data = { + title: $('title') + .text() + .split('_')[0], + link: url, + item: items, + }; +};