diff --git a/docs/multimedia.md b/docs/multimedia.md index 861cca627..a3b0d171a 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -349,6 +349,12 @@ pageClass: routes +## 荔枝 FM + +### 电台更新 + + + ## 猫眼电影 ### 正在热映 diff --git a/lib/router.js b/lib/router.js index ea95498c9..3b93dd6ef 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2834,4 +2834,7 @@ router.get('/egameqq/room/:id', require('./routes/tencent/egame/room')); // 国家税务总局 router.get('/gov/chinatax/latest', require('./routes/gov/chinatax/latest')); +// 荔枝FM +router.get('/lizhi/user/:id', require('./routes/lizhi/user')); + module.exports = router; diff --git a/lib/routes/lizhi/user.js b/lib/routes/lizhi/user.js new file mode 100644 index 000000000..b465f7ebb --- /dev/null +++ b/lib/routes/lizhi/user.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const link = `https://www.lizhi.fm/api/user/audios/${ctx.params.id}/1`; + const response = await got({ + method: 'get', + url: link, + }); + + const userUrl = `https://m.lizhi.fm/vod/user/${ctx.params.id}`; + const userResponse = await got({ + method: 'get', + url: userUrl, + }); + const $ = cheerio.load(userResponse.data); + + const list = response.data.audios.map((item) => ({ + title: item.name, + enclosure_url: item.url, + enclosure_length: item.duration, + enclosure_type: 'audio/mpeg', + link: `https://www.lizhi.fm/${$('div.user_info div.desc span').eq(0).text().replace('FM ', '')}/${item.id}`, + pubDate: new Date(item.create_time).toUTCString(), + })); + + ctx.state.data = { + title: `荔枝FM - ${$('div.username h3.name').text()}`, + link: `https://www.lizhi.fm/user/${ctx.params.id}`, + itunes_author: $('div.username h3.name').text(), + itunes_category: '', + image: `http://${$('div.user_info div.cover img').attr('src').replace('200x200', '320x320')}`, + item: await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const res = await got({ method: 'get', url: item.link }); + const content = cheerio.load(res.data); + item.description = content('div.desText').text(); + item.itunes_item_image = content('div.audioCover img').attr('src'); + return item; + }) + ) + ), + description: `${$('div.isAll').text()}`, + }; +};