diff --git a/docs/en/live.md b/docs/en/live.md index 3660f22ec..21fb6903e 100644 --- a/docs/en/live.md +++ b/docs/en/live.md @@ -4,6 +4,16 @@ pageClass: routes # Live +## LiSA + +### News + + + +### Latest Discography + + + ## V LIVE ### Board diff --git a/lib/v2/lxixsxa/discography.js b/lib/v2/lxixsxa/discography.js new file mode 100644 index 000000000..172cea59b --- /dev/null +++ b/lib/v2/lxixsxa/discography.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { parseJSONP } = require('./jsonpHelper'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const api = 'https://www.sonymusic.co.jp/json/v2/artist/lisa/discography/start/0/count/-1'; + const url = 'https://www.sonymusic.co.jp/artist/lisa/discography'; + + const title = 'LATEST DISCOGRAPHY'; + + const response = await got({ + method: 'get', + url: api, + }); + + const data = parseJSONP(response.data).items.map((item) => ({ + title: item.title, + referID: item.representative_goods_number, + imageLink: item.image !== '' ? item.image : item.image_original, + type: item.type, + releaseDate: item.release_date, + price: item.price !== '' ? item.price + ' (Tax Inclusive)' : 'Unknown Yet', + description: item.comment, + comment: item.catch_copy !== '' ? item.catch_copy : '今日もいい日だ!', + })); + + ctx.state.data = { + // the source title + title, + // the source url + link: url, + // the source description + description: "LiSA's Latest Albums", + // iterate through all leaf objects + item: data.map((item) => ({ + // the article title + title: item.title, + // the article content + description: art(path.join(__dirname, 'templates/disco.art'), { + comment: item.comment, + type: item.type, + price: item.price, + image: item.imageLink, + description: item.description, + }), + // the article publish time + pubDate: parseDate(item.releaseDate), + // the article link + link: `${url}/${item.referID}`, + })), + }; +}; diff --git a/lib/v2/lxixsxa/information.js b/lib/v2/lxixsxa/information.js new file mode 100644 index 000000000..1684bd5e1 --- /dev/null +++ b/lib/v2/lxixsxa/information.js @@ -0,0 +1,48 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { parseJSONP } = require('./jsonpHelper'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const api = 'https://www.sonymusic.co.jp/json/v2/artist/lisa/information/start/0/count/-1'; + const url = 'https://www.sonymusic.co.jp/artist/lisa/info'; + + const title = 'NEWS'; + + const response = await got({ + method: 'get', + url: api, + }); + + const data = parseJSONP(response.data).items.map((item) => ({ + id: item.id, + title: item.title, + category: item.category, + date: item.date, + description: item.article, + })); + + ctx.state.data = { + // the source title + title, + // the source url + link: url, + // the source description + description: "Let's see what is new about LiSA.", + // iterate through all leaf objects + item: data.map((item) => ({ + // the article title + title: item.title, + // the article content + description: art(path.join(__dirname, 'templates/info.art'), { + category: item.category, + description: item.description.replace(/\n/g, '
'), + }), + // the article publish time + pubDate: parseDate(item.date), + // the article link + link: `${url}/${item.id}`, + })), + }; +}; diff --git a/lib/v2/lxixsxa/jsonpHelper.js b/lib/v2/lxixsxa/jsonpHelper.js new file mode 100644 index 000000000..9f2f1938f --- /dev/null +++ b/lib/v2/lxixsxa/jsonpHelper.js @@ -0,0 +1,19 @@ +function parseJSONP(jsonpData) { + try { + const startPos = jsonpData.indexOf('({'); + const endPos = jsonpData.lastIndexOf('})'); + let jsonString = jsonpData.substring(startPos + 1, endPos + 1); + + // remove escaped single quotes since they are not valid json + jsonString = jsonString.replace(/\\'/g, "'"); + + return JSON.parse(jsonString); + } catch (e) { + const error = new Error(`Failed to convert jsonp to json. ${e.message}`); + throw error; + } +} + +module.exports = { + parseJSONP, +}; diff --git a/lib/v2/lxixsxa/maintainer.js b/lib/v2/lxixsxa/maintainer.js new file mode 100644 index 000000000..344d4a95e --- /dev/null +++ b/lib/v2/lxixsxa/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/info': ['Kiotlin'], + '/disco': ['Kiotlin'], +}; diff --git a/lib/v2/lxixsxa/radar.js b/lib/v2/lxixsxa/radar.js new file mode 100644 index 000000000..54f4db78c --- /dev/null +++ b/lib/v2/lxixsxa/radar.js @@ -0,0 +1,36 @@ +module.exports = { + 'sonymusic.co.jp': { + _name: 'Sony Music', + www: [ + { + title: 'LiSA News', + docs: 'https://docs.rsshub.app/en/live.html#lisa', + source: ['/artist/lisa/', '/artist/lisa/info/'], + target: '/lxixsxa/info', + }, + { + title: 'LiSA Albums', + docs: 'https://docs.rsshub.app/en/live.html#lisa', + source: ['/artist/lisa/', '/artist/lisa/discography/'], + target: '/lxixsxa/disco', + }, + ], + }, + 'lxixsxa.com': { + _name: 'LiSA Official', + www: [ + { + title: 'News', + docs: 'https://docs.rsshub.app/en/live.html#lisa', + source: ['/', '/info'], + target: '/lxixsxa/info', + }, + { + title: 'Albums', + docs: 'https://docs.rsshub.app/en/live.html#lisa', + source: ['/', '/discography'], + target: '/lxixsxa/disco', + }, + ], + }, +}; diff --git a/lib/v2/lxixsxa/router.js b/lib/v2/lxixsxa/router.js new file mode 100644 index 000000000..356bcc65e --- /dev/null +++ b/lib/v2/lxixsxa/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/info', require('./information')); + router.get('/disco', require('./discography')); +}; diff --git a/lib/v2/lxixsxa/templates/disco.art b/lib/v2/lxixsxa/templates/disco.art new file mode 100644 index 000000000..0e495a922 --- /dev/null +++ b/lib/v2/lxixsxa/templates/disco.art @@ -0,0 +1,5 @@ +{{comment}} Type: {{type}} Price: {{price}} +{{ if image }} + +{{ /if }} +{{@ description }} \ No newline at end of file diff --git a/lib/v2/lxixsxa/templates/info.art b/lib/v2/lxixsxa/templates/info.art new file mode 100644 index 000000000..851917bd8 --- /dev/null +++ b/lib/v2/lxixsxa/templates/info.art @@ -0,0 +1,4 @@ +{{ if category }} + Category: {{category}} +{{ /if }} +{{@ description }} \ No newline at end of file