diff --git a/docs/README.md b/docs/README.md index 4e5b755991..2aca711e47 100644 --- a/docs/README.md +++ b/docs/README.md @@ -189,7 +189,7 @@ RSSHub 同时支持 RSS 2.0、Atom 和 [JSON Feed](https://jsonfeed.org/) 输出 #### 内购价格更新(限免) -举例: [https://rsshub.app/appstore/iap/cn/id1152443474](https://rsshub.app/appstore/price/cn/id1152443474) +举例: [https://rsshub.app/appstore/iap/cn/id953286746](https://rsshub.app/appstore/price/cn/id953286746) 路由: `/appstore/iap/:country/:id` diff --git a/docs/en/README.md b/docs/en/README.md index f45c1a298b..c74d8d912c 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -164,7 +164,7 @@ Parameters: ### App Store/Mac App Store In-App-Purchase Price Drop Alert -Eg: [https://rsshub.app/appstore/iap/cn/id1152443474](https://rsshub.app/appstore/price/cn/id1152443474) +Eg: [https://rsshub.app/appstore/iap/us/id953286746](https://rsshub.app/appstore/price/us/id953286746) Route: `/appstore/iap/:country/:id` diff --git a/routes/appstore/in-app-purchase.js b/routes/appstore/in-app-purchase.js index 47847c71fa..a16a716c47 100644 --- a/routes/appstore/in-app-purchase.js +++ b/routes/appstore/in-app-purchase.js @@ -10,36 +10,28 @@ module.exports = async (ctx) => { const res = await axios.get(target); const $ = cheerio.load(res.data); - const titleTemp = $('h1') - .contents() - .first() - .text() - .trim(); - const list = $('div.l-row div.we-lockup'); - const item = list - .map((i, e) => ({ - link, - guid: `${titleTemp} ${$(e) - .find('h3.we-lockup__title') - .text() - .trim()} ${$(e) - .find('h5') - .text() - .trim()}`, - title: `${titleTemp} ${$(e) - .find('h3.we-lockup__title') - .text() - .trim()} is now ${$(e) - .find('h5') - .text() - .trim()}`, - pubDate: new Date(Date.now()).toUTCString(), - })) - .get(); - const platform = $('.we-localnav__title__product').text(); - - const title = `${country === 'cn' ? '内购限免提醒' : 'IAP price watcher'}: ${titleTemp} for ${platform.startsWith('App') ? 'iOS' : 'macOS'}`; + const data = JSON.parse($('#shoebox-ember-data-store')[0].firstChild.data); + const attributes = data.data.attributes; + const titleTemp = attributes.name; + const platform = attributes.kind === 'iosSoftware' ? 'iOS' : 'macOS'; + let title; + let item = []; + if (attributes.hasInAppPurchases) { + title = `${country === 'cn' ? '内购限免提醒' : 'IAP price watcher'}: ${titleTemp} for ${platform}`; + const list = data.included.filter((e) => e.type === 'product/app/in-app'); + item = list.map((e) => { + const title = `${e.attributes.name} is now ${e.attributes.price}`; + return { + link, + guid: title, + title, + pubDate: new Date(Date.now()).toUTCString(), + }; + }); + } else { + title = `${titleTemp} for ${platform} ${country === 'cn' ? ' 不包含内购项目' : 'has no IAP items'}`; + } ctx.state.data = { title,