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

[pull] master from diygod:master #330

Merged
merged 6 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
63 changes: 63 additions & 0 deletions lib/routes/msn/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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',
parameters: {
market: 'Market code. Find it in MSN url, e.g. zh-tw',
name: 'Name of the channel. Find it in MSN url, e.g. Bloomberg',
id: 'ID of the channel (always starts with sr-vid). Find it in MSN url, e.g. sr-vid-08gw7ky4u229xjsjvnf4n6n7v67gxm0pjmv9fr4y2x9jjmwcri4s',
},
categories: ['traditional-media'],
example: '/zh-tw/Bloomberg/sr-vid-08gw7ky4u229xjsjvnf4n6n7v67gxm0pjmv9fr4y2x9jjmwcri4s',
description: `MSN News`,
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
},
radar: [
{
source: ['www.msn.com/:market/channel/source/:name/:id'],
target: '/:market/:name/:id',
},
],
name: 'News',
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,
image: 'https://www.msn.com/favicon.ico',
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',
url: 'msn.com',

zh: {
name: 'MSN',
},
};
2 changes: 1 addition & 1 deletion lib/routes/pixiv/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function handler(ctx) {
return {
title: `${username} 的 pixiv 动态`,
link: `https://www.pixiv.net/users/${id}`,
image: illusts[0].user.profile_image_urls.medium,
image: pixivUtils.getProxiedImageUrl(illusts[0].user.profile_image_urls.medium),
description: `${username} 的 pixiv 最新动态`,
item: illusts.map((illust) => {
const images = pixivUtils.getImgs(illust);
Expand Down
8 changes: 8 additions & 0 deletions lib/routes/tiddlywiki/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'TiddlyWiki',
url: 'tiddlywiki.com',
description: '',
lang: 'en',
};
84 changes: 84 additions & 0 deletions lib/routes/tiddlywiki/releases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Route } from '@/types';

import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/releases',
categories: ['program-update'],
example: '/tiddlywiki/releases',
url: 'tiddlywiki.com',
name: 'Releases',
maintainers: ['p3psi-boo'],
radar: [
{
source: ['github.com/TiddlyWiki/TiddlyWiki5'],
target: '/releases',
},
{
source: ['tiddlywiki.com'],
target: '/releases',
},
],
handler,
};

async function handler() {
const tagListUrl = 'https://github.com/TiddlyWiki/TiddlyWiki5/releases.atom';

const response = await got({
method: 'get',
url: tagListUrl,
});

const $ = load(response.data);

const alist = $('entry');

const versionList = alist
.toArray()
.map((item) => {
item = $(item);
const text = item.find('title').text();
const date = item.find('updated').text();
// 使用正则提取 v5.3.6 格式
const version = text.match(/v\d+\.\d+\.\d+/)?.[0];
return {
version,
pubDate: parseDate(date),
};
})
.filter((item) => item.version);

const items = await Promise.all(
versionList.map((item) => {
const _version = item.version.slice(1);
const url = `https://tiddlywiki.com/static/Release%2520${_version}.html`;
return cache.tryGet(url, async () => {
const response = await got({
method: 'get',
url,
});

const $ = load(response.data);

const description = $('.tc-tiddler-body').html();

return {
title: item.version,
link: url,
pubDate: item.pubDate,
description,
};
});
})
);

return {
title: 'TiddlyWiki Releases',
link: 'https://tiddlywiki.com/static/Releases.html',
item: items,
};
}
59 changes: 59 additions & 0 deletions lib/routes/webcatalog/changelog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Route } from '@/types';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import ofetch from '@/utils/ofetch';

export const route: Route = {
path: '/changelog',
categories: ['program-update'],
example: '/webcatalog/changelog',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['desktop.webcatalog.io/:lang/changelog'],
},
],
name: 'Changelog',
maintainers: ['Tsuyumi25'],
handler,
url: 'desktop.webcatalog.io/en/changelog',
};

async function handler() {
const url = 'https://desktop.webcatalog.io/en/changelog';
const response = await ofetch(url);
const $ = load(response);

// remove What's new
$('.container article div.mb-20').remove();
const items = $('.container article')
.html()
?.split('<hr>')
?.map((section) => {
const $section = load(section);
const month = $section('h1').remove().text();
const title = $section('h2').first().remove().text();
return {
title: `${month} - ${title}`,
description: $section.html(),
link: url,
pubDate: parseDate(month),
guid: `webcatalog-${month}-${title}`,
};
});

return {
title: 'WebCatalog Changelog',
link: url,
item: items,
language: 'en',
};
}
7 changes: 7 additions & 0 deletions lib/routes/webcatalog/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'WebCatalog',
url: 'desktop.webcatalog.io',
lang: 'en',
};
6 changes: 3 additions & 3 deletions lib/routes/weibo/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ const weiboUtils = {
}

// drop live photo
const livePhotoCount = status.pics ? status.pics.filter((pic) => pic.type === 'livephotos').length : 0;
const pics = status.pics && status.pics.filter((pic) => pic.type !== 'livephotos');
const livePhotoCount = status.pics ? status.pics.filter((pic) => pic.type === 'livephoto').length : 0;
const pics = status.pics && status.pics.filter((pic) => pic.type !== 'livephoto');

// 添加微博配图
if (pics) {
Expand Down Expand Up @@ -263,7 +263,7 @@ const weiboUtils = {
},
formatVideo: (itemDesc, status) => {
const pageInfo = status.page_info;
const livePhotos = status.pics && status.pics.filter((pic) => pic.type === 'livephotos' && pic.videoSrc);
const livePhotos = status.pics && status.pics.filter((pic) => pic.type === 'livephoto' && pic.videoSrc);
let video = '<br clear="both" /><div style="clear: both"></div>';
let anyVideo = false;
if (livePhotos) {
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/youtube/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const route: Route = {
},
radar: [
{
source: ['www.youtube.com/user/:username'],
source: ['www.youtube.com/user/:username', 'www.youtube.com/:username'],
target: '/user/:username',
},
],
Expand Down
Loading