From c8f06fe4934dfcdd65fb1f028b59de471d0f6f57 Mon Sep 17 00:00:00 2001 From: Evan Date: Tue, 7 Mar 2023 05:31:25 -0800 Subject: [PATCH] feat(route): sony software downloads (#12046) * feat(route): sony software downloads * Update lib/v2/sony/downloads.js * chore: use map instead of forEach, delete description --------- --- docs/en/program-update.md | 15 ++++++ docs/program-update.md | 14 ++++++ lib/v2/sony/downloads.js | 47 +++++++++++++++++++ lib/v2/sony/maintainer.js | 3 ++ lib/v2/sony/radar.js | 13 +++++ lib/v2/sony/router.js | 3 ++ .../sony/templates/software-description.art | 4 ++ 7 files changed, 99 insertions(+) create mode 100644 lib/v2/sony/downloads.js create mode 100644 lib/v2/sony/maintainer.js create mode 100644 lib/v2/sony/radar.js create mode 100644 lib/v2/sony/router.js create mode 100644 lib/v2/sony/templates/software-description.art diff --git a/docs/en/program-update.md b/docs/en/program-update.md index 50d4fefd8c..39e57282d8 100644 --- a/docs/en/program-update.md +++ b/docs/en/program-update.md @@ -489,6 +489,21 @@ See [#nintendo](/game.html#nintendo) +## Sony + +### Software Downloads + + + +::: tip + +Open `https://www.sony.com/electronics/support` and search for the corresponding product, such as `Sony A7M4`, the website corresponding to which is `https://www.sony.com/electronics/support/e-mount-body-ilce-7-series/ilce-7m4/downloads`, where `productType` is `e-mount-body-ilce-7-series` and `productId` is `ilce-7m4`. + +::: + + + + ## Thunderbird ### Changelog diff --git a/docs/program-update.md b/docs/program-update.md index 5b1f567243..0971869204 100644 --- a/docs/program-update.md +++ b/docs/program-update.md @@ -572,6 +572,20 @@ Logseq 开发团队已经放弃了 [旧网站](https://logseq.com/blog)。 +## Sony + +### Software Downloads + + + +::: tip 提示 + +打开 `https://www.sony.com/electronics/support` 并搜索对应的产品,比如 `Sony A7M4` 对应的网站是 `https://www.sony.com/electronics/support/e-mount-body-ilce-7-series/ilce-7m4/downloads`,`productType` 为 `e-mount-body-ilce-7-series`, `productId` 为 `ilce-7m4` + +::: + + + ## Thunderbird ### 更新日志 diff --git a/lib/v2/sony/downloads.js b/lib/v2/sony/downloads.js new file mode 100644 index 0000000000..b79c96d139 --- /dev/null +++ b/lib/v2/sony/downloads.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const host = 'https://www.sony.com'; +module.exports = async (ctx) => { + const { productType, productId } = ctx.params; + const url = `${host}/electronics/support/${productType}/${productId}/downloads`; + const response = await got({ + method: 'get', + url, + }); + const data = response.data; + + const $ = cheerio.load(data); + const contents = $('script:contains("window.__PRELOADED_STATE__.downloads")').text(); + + const regex = /window\.__PRELOADED_STATE__\.downloads\s*=\s*({.*?});\s*window\.__PRELOADED_STATE__/s; + + const match = contents.match(regex); + let results = {}; + if (match) { + results = JSON.parse(match[1]).searchResults.results; + } + const list = results.map((item) => { + const data = {}; + data.title = item.title; + data.pubDate = item.publicationDate; + const url = item.url; + if (url.startsWith('http')) { + data.url = url; + } else if (url.startsWith('//')) { + data.url = 'https:' + url; + } else { + data.url = host + url; + } + return data; + }); + ctx.state.data = { + title: `Sony - ${productId.toUpperCase()}`, + link: url, + description: `Sony - ${productId.toUpperCase()}`, + item: list.map((item) => ({ + title: item.title, + link: item.url, + pubDate: item.pubDate, + })), + }; +}; diff --git a/lib/v2/sony/maintainer.js b/lib/v2/sony/maintainer.js new file mode 100644 index 0000000000..7465a0d08b --- /dev/null +++ b/lib/v2/sony/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/downloads/:productType/:productId': ['NavePnow'], +}; diff --git a/lib/v2/sony/radar.js b/lib/v2/sony/radar.js new file mode 100644 index 0000000000..07286c18a1 --- /dev/null +++ b/lib/v2/sony/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'sony.com': { + _name: 'Sony', + '.': [ + { + title: 'Software Downloads', + docs: 'https://docs.rsshub.app/program-update.html#sony', + source: ['/electronics/support/:productType/:productId/downloads'], + target: '/sony/downloads/:productType/:productId', + }, + ], + }, +}; diff --git a/lib/v2/sony/router.js b/lib/v2/sony/router.js new file mode 100644 index 0000000000..b4af605235 --- /dev/null +++ b/lib/v2/sony/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/downloads/:productType/:productId', require('./downloads')); +}; diff --git a/lib/v2/sony/templates/software-description.art b/lib/v2/sony/templates/software-description.art new file mode 100644 index 0000000000..1538d42cf4 --- /dev/null +++ b/lib/v2/sony/templates/software-description.art @@ -0,0 +1,4 @@ +
+

+ Release Date: {{ item.pubDate }} +