Skip to content

Commit

Permalink
feat(route): 添加豆瓣电影-即将上映 (#16757)
Browse files Browse the repository at this point in the history
* 添加豆瓣电影即将上映

* 切换到art模板,添加radar

* fix example route
  • Loading branch information
reonokiy committed Sep 15, 2024
1 parent 837aa7b commit 034081a
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
68 changes: 68 additions & 0 deletions lib/routes/douban/movie/coming.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { getCurrentPath } from '@/utils/helpers';
import { art } from '@/utils/render';
import path from 'node:path';

const __dirname = getCurrentPath(import.meta.url);

export const route: Route = {
path: '/movie/coming',
categories: ['social-media'],
example: '/douban/movie/coming',
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '电影即将上映',
maintainers: ['reonokiy'],
radar: [
{
title: '豆瓣电影-即将上映',
source: ['movie.douban.com/coming'],
target: '/movie/coming',
},
],
handler,
};
const renderDescription = (info: { title?: string; cover_url?: string; pubdate?: string[]; intro?: string; directors?: string[]; actors?: string[]; genres: string[]; wish_count?: number | string }) =>
art(path.join(__dirname, '../templates/movie_coming.art'), info);

async function handler(ctx) {
const response = await got({
method: 'get',
url: 'https://m.douban.com/rexxar/api/v2/movie/coming_soon',
headers: {
Referer: 'https://m.douban.com/movie/',
},
});

ctx.set('json', { response });

return {
title: '豆瓣电影-即将上映',
link: 'https://movie.douban.com/coming',
item: response.data?.subjects?.map((item) => ({
title: item?.title,
link: item?.url,
guid: item?.url,
description: renderDescription({
title: item?.title,
intro: item?.intro,
pubdate: item?.pubdate,
cover_url: item?.cover_url,
directors: item?.directors?.map((d) => d?.name),
actors: item?.actors?.map((a) => a?.name),
genres: item?.genres,
wish_count: item?.wish_count,
}),
category: item?.genres,
itunes_item_image: item?.cover_url,
upvotes: item?.wish_count,
})),
};
}
27 changes: 27 additions & 0 deletions lib/routes/douban/templates/movie_coming.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{if cover_url && title}}
<img src="{{cover_url}}" alt="{{title}}" referrerpolicy="no-referrer">
{{/if}}

<h2>电影信息</h2>
<ul>
{{if directors}}
<li>导演:{{directors.join(', ')}}</li>
{{/if}}
{{if actors}}
<li>演员:{{actors.join(', ')}}</li>
{{/if}}
{{if genres}}
<li>类型:{{genres.join(' / ')}}</li>
{{/if}}
{{if pubdate}}
<li>上映日期:{{pubdate.join(' / ')}}</li>
{{/if}}
{{if wish_count}}
<li>想看:{{wish_count}}</li>
{{/if}}
</ul>

{{ if intro }}
<h2>剧情简介</h2>
<p>{{ intro }}</p>
{{/if}}

0 comments on commit 034081a

Please sign in to comment.