mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 15:47:48 +08:00
feat: add lastfm (#3794)
This commit is contained in:
@@ -1040,4 +1040,27 @@
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
'last.fm': {
|
||||||
|
_name: 'Last.fm',
|
||||||
|
www: [
|
||||||
|
{
|
||||||
|
title: '用户播放记录',
|
||||||
|
docs: 'https://docs.rsshub.app/multimedia.html#last-fm',
|
||||||
|
source: ['/user/:user', '/user/:user/*'],
|
||||||
|
target: '/lastfm/recent/:user',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '用户 Love 记录',
|
||||||
|
docs: 'https://docs.rsshub.app/multimedia.html#last-fm',
|
||||||
|
source: ['/user/:user', '/user/:user/*'],
|
||||||
|
target: '/lastfm/loved/:user',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '站内 Top 榜单',
|
||||||
|
docs: 'https://docs.rsshub.app/multimedia.html#last-fm',
|
||||||
|
source: '/charts',
|
||||||
|
target: '/lastfm/top',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -397,5 +397,9 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式
|
|||||||
- `FANFOU_USERNAME`: 饭否登录用户名、邮箱、手机号
|
- `FANFOU_USERNAME`: 饭否登录用户名、邮箱、手机号
|
||||||
- `FANFOU_PASSWORD`: 饭否密码
|
- `FANFOU_PASSWORD`: 饭否密码
|
||||||
|
|
||||||
|
- Last.fm 全部路由: [申请地址](https://www.last.fm/api/)
|
||||||
|
|
||||||
|
- `LASTFM_API_KEY`: Last.fm API Key
|
||||||
|
|
||||||
- 北大未名 BBS 全站十大
|
- 北大未名 BBS 全站十大
|
||||||
- `PKUBBS_COOKIE`: BBS 注册用户登录后的 Cookie 值,获取方式:1.登录后打开论坛首页 2. 打开控制台 3. 刷新 4. 找到 <https://bbs.pku.edu.cn/v2/home.php> 请求 5. 找到请求头中的 Cookie
|
- `PKUBBS_COOKIE`: BBS 注册用户登录后的 Cookie 值,获取方式:1.登录后打开论坛首页 2. 打开控制台 3. 刷新 4. 找到 <https://bbs.pku.edu.cn/v2/home.php> 请求 5. 找到请求头中的 Cookie
|
||||||
|
|||||||
@@ -124,6 +124,20 @@ pageClass: routes
|
|||||||
|
|
||||||
<Route author="junfengP" example="/javlibrary/userposts/siccalol" path="/javlibrary/userposts/:uid" :paramsDesc="['用户 id,即用户名称']" />
|
<Route author="junfengP" example="/javlibrary/userposts/siccalol" path="/javlibrary/userposts/:uid" :paramsDesc="['用户 id,即用户名称']" />
|
||||||
|
|
||||||
|
## Last.fm
|
||||||
|
|
||||||
|
### 用户播放记录
|
||||||
|
|
||||||
|
<Route author="hoilc" example="/lastfm/recent/yeFoenix" path="/lastfm/recent/:user" :paramsDesc="['Last.fm 用户名']" radar="1" />
|
||||||
|
|
||||||
|
### 用户 Love 记录
|
||||||
|
|
||||||
|
<Route author="hoilc" example="/lastfm/loved/yeFoenix" path="/lastfm/loved/:user" :paramsDesc="['Last.fm 用户名']" radar="1" />
|
||||||
|
|
||||||
|
### 站内 Top 榜单
|
||||||
|
|
||||||
|
<Route author="hoilc" example="/lastfm/top/spain" path="/lastfm/top/:country?" :paramsDesc="['国家或地区, 需要符合`ISO 3166-1`的英文全称, 可参考`https://zh.wikipedia.org/wiki/ISO_3166-1二位字母代码#正式分配代码`']" radar="1" />
|
||||||
|
|
||||||
## Mp4Ba
|
## Mp4Ba
|
||||||
|
|
||||||
### 影视分类
|
### 影视分类
|
||||||
|
|||||||
@@ -107,6 +107,9 @@ const calculateValue = () => {
|
|||||||
username: envs.FANFOU_USERNAME,
|
username: envs.FANFOU_USERNAME,
|
||||||
password: envs.FANFOU_PASSWORD,
|
password: envs.FANFOU_PASSWORD,
|
||||||
},
|
},
|
||||||
|
lastfm: {
|
||||||
|
api_key: envs.LASTFM_API_KEY,
|
||||||
|
},
|
||||||
pkubbs: {
|
pkubbs: {
|
||||||
cookie: envs.PKUBBS_COOKIE,
|
cookie: envs.PKUBBS_COOKIE,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2187,6 +2187,11 @@ router.get('/netease/ds/:id', require('./routes/netease/ds'));
|
|||||||
// javlibrary
|
// javlibrary
|
||||||
router.get('/javlibrary/userposts/:uid', require('./routes/javlibrary/userposts'));
|
router.get('/javlibrary/userposts/:uid', require('./routes/javlibrary/userposts'));
|
||||||
|
|
||||||
|
// Last.FM
|
||||||
|
router.get('/lastfm/recent/:user', require('./routes/lastfm/recent'));
|
||||||
|
router.get('/lastfm/loved/:user', require('./routes/lastfm/loved'));
|
||||||
|
router.get('/lastfm/top/:country?', require('./routes/lastfm/top'));
|
||||||
|
|
||||||
// piapro
|
// piapro
|
||||||
router.get('/piapro/user/:pid', require('./routes/piapro/user'));
|
router.get('/piapro/user/:pid', require('./routes/piapro/user'));
|
||||||
router.get('/piapro/public/:type/:tag?/:category?', require('./routes/piapro/public'));
|
router.get('/piapro/public/:type/:tag?/:category?', require('./routes/piapro/public'));
|
||||||
|
|||||||
27
lib/routes/lastfm/loved.js
Normal file
27
lib/routes/lastfm/loved.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const config = require('@/config').value;
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
if (!config.lastfm || !config.lastfm.api_key) {
|
||||||
|
throw 'Last.fm RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = ctx.params.user;
|
||||||
|
const api_key = config.lastfm.api_key;
|
||||||
|
|
||||||
|
const response = await got(`http://ws.audioscrobbler.com/2.0/?method=user.getlovedtracks&user=${user}&api_key=${api_key}&format=json`);
|
||||||
|
const data = response.data;
|
||||||
|
const list = data.lovedtracks.track;
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `Loved Tracks by ${data.lovedtracks['@attr'].user} - Last.fm`,
|
||||||
|
link: `https://www.last.fm/user/${user}/loved`,
|
||||||
|
item: list.map((item) => ({
|
||||||
|
title: `${item.name} - ${item.artist.name}`,
|
||||||
|
author: item.artist.name,
|
||||||
|
description: `<img src="${item.image.slice(-1)[0]['#text']}" />`,
|
||||||
|
pubDate: new Date(item.date.uts * 1000),
|
||||||
|
link: item.url,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
27
lib/routes/lastfm/recent.js
Normal file
27
lib/routes/lastfm/recent.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const config = require('@/config').value;
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
if (!config.lastfm || !config.lastfm.api_key) {
|
||||||
|
throw 'Last.fm RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = ctx.params.user;
|
||||||
|
const api_key = config.lastfm.api_key;
|
||||||
|
|
||||||
|
const response = await got(`http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${user}&api_key=${api_key}&format=json`);
|
||||||
|
const data = response.data;
|
||||||
|
const list = data.recenttracks.track;
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `Recent Tracks by ${data.recenttracks['@attr'].user} - Last.fm`,
|
||||||
|
link: `https://www.last.fm/user/${user}/library`,
|
||||||
|
item: list.map((item) => ({
|
||||||
|
title: `${item.name} - ${item.artist['#text']}`,
|
||||||
|
author: item.artist['#text'],
|
||||||
|
description: `<img src="${item.image.slice(-1)[0]['#text']}" />`,
|
||||||
|
pubDate: new Date(item.date.uts * 1000),
|
||||||
|
link: item.url,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
27
lib/routes/lastfm/top.js
Normal file
27
lib/routes/lastfm/top.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const config = require('@/config').value;
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
if (!config.lastfm || !config.lastfm.api_key) {
|
||||||
|
throw 'Last.fm RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
const country = ctx.params.country;
|
||||||
|
const api_key = config.lastfm.api_key;
|
||||||
|
|
||||||
|
const response = await got(`http://ws.audioscrobbler.com/2.0/?method=${country ? 'geo.gettoptracks' : 'chart.gettoptracks'}${country ? '&country=' + country : ''}&api_key=${api_key}&format=json`);
|
||||||
|
const data = response.data;
|
||||||
|
const list = data.tracks.track;
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `Top Tracks${country ? ' in ' + data.tracks['@attr'].country : ''} - Last.fm`,
|
||||||
|
link: 'https://www.last.fm/charts#top-tracks',
|
||||||
|
item: list.map((item) => ({
|
||||||
|
title: `${item.name} - ${item.artist.name}`,
|
||||||
|
author: item.artist.name,
|
||||||
|
description: `<img src="${item.image.slice(-1)[0]['#text']}" />`,
|
||||||
|
pubDate: new Date(),
|
||||||
|
link: item.url,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user