mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 06:30:40 +08:00
feat: Create the Letterboxd Following Diary endpoint. (#3858)
This commit is contained in:
@@ -79,6 +79,10 @@ Provides a better reading experience (full text articles) over the official one.
|
|||||||
|
|
||||||
<RouteEn author="loganrockmore" example="/letterboxd/user/diary/demiadejuyigbe" path="/letterboxd/user/diary/:username" :paramsDesc="['username']" />
|
<RouteEn author="loganrockmore" example="/letterboxd/user/diary/demiadejuyigbe" path="/letterboxd/user/diary/:username" :paramsDesc="['username']" />
|
||||||
|
|
||||||
|
### Following diary
|
||||||
|
|
||||||
|
<RouteEn author="loganrockmore" example="/letterboxd/user/followingdiary/demiadejuyigbe" path="/letterboxd/user/followingdiary/:username" :paramsDesc="['username']" />
|
||||||
|
|
||||||
## Nautilus
|
## Nautilus
|
||||||
|
|
||||||
### Topics
|
### Topics
|
||||||
|
|||||||
@@ -2177,6 +2177,7 @@ router.get('/mqube/top', require('./routes/mqube/top'));
|
|||||||
|
|
||||||
// Letterboxd
|
// Letterboxd
|
||||||
router.get('/letterboxd/user/diary/:username', require('./routes/letterboxd/userdiary'));
|
router.get('/letterboxd/user/diary/:username', require('./routes/letterboxd/userdiary'));
|
||||||
|
router.get('/letterboxd/user/followingdiary/:username', require('./routes/letterboxd/followingdiary'));
|
||||||
|
|
||||||
// 网易大神
|
// 网易大神
|
||||||
router.get('/netease/ds/:id', require('./routes/netease/ds'));
|
router.get('/netease/ds/:id', require('./routes/netease/ds'));
|
||||||
|
|||||||
8
lib/routes/letterboxd/followingdiary.js
Normal file
8
lib/routes/letterboxd/followingdiary.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const utils = require('./utils');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const url = `https://letterboxd.com/${ctx.params.username}/following/`;
|
||||||
|
const title = `Letterboxd - following diary - ${ctx.params.username}`;
|
||||||
|
|
||||||
|
ctx.state.data = await utils.getFollowingData(ctx, ctx.params.username, url, title);
|
||||||
|
};
|
||||||
@@ -4,5 +4,5 @@ module.exports = async (ctx) => {
|
|||||||
const url = `https://letterboxd.com/${ctx.params.username}/films/diary/by/added/`;
|
const url = `https://letterboxd.com/${ctx.params.username}/films/diary/by/added/`;
|
||||||
const title = `Letterboxd - diary - ${ctx.params.username}`;
|
const title = `Letterboxd - diary - ${ctx.params.username}`;
|
||||||
|
|
||||||
ctx.state.data = await utils.getData(ctx, url, title);
|
ctx.state.data = await utils.getData(ctx, ctx.params.username, url, title);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ async function ProcessFeed(list, username, caches) {
|
|||||||
const rewatch = $('.td-rewatch.icon-status-off').length <= 0;
|
const rewatch = $('.td-rewatch.icon-status-off').length <= 0;
|
||||||
const hasReview = $('.td-review.icon-status-off').length <= 0;
|
const hasReview = $('.td-review.icon-status-off').length <= 0;
|
||||||
|
|
||||||
let descriptionText = `<b>${filmTitle}</b><br />Watched: ${displayDate}<br />Rating: ${rating}`;
|
let descriptionText = `<b>${filmTitle}</b><br />watched by ${username}<br />Date: ${displayDate}<br />Rating: ${rating}`;
|
||||||
|
|
||||||
if (liked) {
|
if (liked) {
|
||||||
descriptionText = descriptionText.concat('<br />Liked');
|
descriptionText = descriptionText.concat('<br />Liked');
|
||||||
@@ -75,7 +75,7 @@ async function ProcessFeed(list, username, caches) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const getData = async (ctx, url, title) => {
|
const getData = async (ctx, username, url, title) => {
|
||||||
const response = await got({
|
const response = await got({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: url,
|
url: url,
|
||||||
@@ -87,7 +87,7 @@ const getData = async (ctx, url, title) => {
|
|||||||
const $ = cheerio.load(response.data);
|
const $ = cheerio.load(response.data);
|
||||||
const list = $('.diary-entry-row').get();
|
const list = $('.diary-entry-row').get();
|
||||||
|
|
||||||
const result = await ProcessFeed(list, ctx.params.username, ctx.cache);
|
const result = await ProcessFeed(list, username, ctx.cache);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: title,
|
title: title,
|
||||||
@@ -97,6 +97,45 @@ const getData = async (ctx, url, title) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getFollowingData = async (ctx, username, url, title) => {
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: url,
|
||||||
|
headers: {
|
||||||
|
Referer: url,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
const list = $('.person-table td.table-person').get();
|
||||||
|
|
||||||
|
const users = list.map(function(user) {
|
||||||
|
const $ = cheerio.load(user);
|
||||||
|
return $('a.name').attr('href');
|
||||||
|
});
|
||||||
|
|
||||||
|
const usersResult = await Promise.all(
|
||||||
|
users.map(async (user) => {
|
||||||
|
const userWithoutSlashes = user.replace(/^\//, '').replace(/\/$/, '');
|
||||||
|
|
||||||
|
const url = `https://letterboxd.com/${userWithoutSlashes}/films/diary/by/added/`;
|
||||||
|
const data = getData(ctx, userWithoutSlashes, url, title);
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const usersItems = usersResult.map((result) => result.item);
|
||||||
|
const flattenedItems = [].concat.apply([], usersItems);
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: title,
|
||||||
|
link: url,
|
||||||
|
description: $('meta[name="description"]').attr('content'),
|
||||||
|
item: flattenedItems,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getData,
|
getData,
|
||||||
|
getFollowingData,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user