Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add msn news #17968

Merged
merged 4 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add msn news
  • Loading branch information
KTachibanaM committed Dec 23, 2024
commit a033fe6dbbda8b2726aa318d3b0ab72019f14b92
56 changes: 56 additions & 0 deletions lib/routes/msn/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
import { load } from 'cheerio';

const apiKey = '0QfOX3Vn51YCzitbLaRkTTBadtWpgTN8NZLW0C1SEM';

export const route: Route = {
path: '/:market/:name/:id',
KTachibanaM marked this conversation as resolved.
Show resolved Hide resolved
categories: ['traditional-media'],
example: '/zh-tw/Bloomberg/sr-vid-08gw7ky4u229xjsjvnf4n6n7v67gxm0pjmv9fr4y2x9jjmwcri4s',
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
},
radar: [
{
source: ['https://www.msn.com/:market/channel/source/:name/:id'],
KTachibanaM marked this conversation as resolved.
Show resolved Hide resolved
target: '/:market/:name/:id',
},
],
name: 'MSN News',
KTachibanaM marked this conversation as resolved.
Show resolved Hide resolved
maintainers: ['KTachibanaM'],
handler: async (ctx) => {
const { market, name, id } = ctx.req.param();
let truncatedId = id;
if (truncatedId.startsWith('sr-')) {
truncatedId = truncatedId.substring(3);
}

const pageData = await ofetch(`https://www.msn.com/${market}/channel/source/${name}/${id}`);
const $ = load(pageData);
const headElement = $('head');
const dataClientSettings = headElement.attr('data-client-settings') ?? '{}';
const parsedSettings = JSON.parse(dataClientSettings);
const requestMuid = parsedSettings.fd_muid;

const jsonData = await ofetch(`https://assets.msn.com/service/news/feed/pages/providerfullpage?market=${market}&query=newest&CommunityProfileId=${truncatedId}&apikey=${apiKey}&user=m-${requestMuid}`);
const items = jsonData.sections[0].cards.map((card) => ({
title: card.title,
link: card.url,
description: card.abstract,
pubDate: parseDate(card.publishedDateTime),
category: [card.category],
}));

const channelLink = `https://www.msn.com/${market}/channel/source/${name}/${id}`;
return {
title: name,
link: channelLink,
item: items,
};
},
};
10 changes: 10 additions & 0 deletions lib/routes/msn/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'MSN news',
KTachibanaM marked this conversation as resolved.
Show resolved Hide resolved
url: 'msn.com',

zh: {
name: 'MSN 新闻',
},
};
Loading