Skip to content

Commit

Permalink
feat(route): sony software downloads (DIYgod#12046)
Browse files Browse the repository at this point in the history
* feat(route): sony software downloads

* Update lib/v2/sony/downloads.js

* chore: use map instead of forEach, delete description

---------
  • Loading branch information
EthanWng97 authored Mar 7, 2023
1 parent 569c630 commit c8f06fe
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/en/program-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,21 @@ See [#nintendo](/game.html#nintendo)

<RouteEn author="Jeason0228" example="/sketch/updates" path="/sketch/updates" />

## Sony

### Software Downloads

<RouteEn author="NavePnow" example="/sony/downloads/product/nw-wm1am2" path="/sony/downloads/:productType/:productId" :paramsDesc="['product type', 'product id']">

::: 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`.

:::

</RouteEn>


## Thunderbird

### Changelog
Expand Down
14 changes: 14 additions & 0 deletions docs/program-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,20 @@ Logseq 开发团队已经放弃了 [旧网站](https://logseq.com/blog)。

<Route author="Jeason0228" example="/sketch/updates" path="/sketch/updates" />

## Sony

### Software Downloads

<Route author="NavePnow" example="/sony/downloads/product/nw-wm1am2" path="/sony/downloads/:productType/:productId" :paramsDesc="['产品类别', '产品Id']">

::: 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`

:::

</Route>

## Thunderbird

### 更新日志
Expand Down
47 changes: 47 additions & 0 deletions lib/v2/sony/downloads.js
Original file line number Diff line number Diff line change
@@ -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,
})),
};
};
3 changes: 3 additions & 0 deletions lib/v2/sony/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/downloads/:productType/:productId': ['NavePnow'],
};
13 changes: 13 additions & 0 deletions lib/v2/sony/radar.js
Original file line number Diff line number Diff line change
@@ -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',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/sony/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/downloads/:productType/:productId', require('./downloads'));
};
4 changes: 4 additions & 0 deletions lib/v2/sony/templates/software-description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
<br><br>
Release Date: {{ item.pubDate }}
</div>

0 comments on commit c8f06fe

Please sign in to comment.