Files
RSSHub/lib/routes/nmtv/column.tsx
T
dependabot[bot]andTony 417ab04f06 chore(deps-dev): bump eslint-plugin-unicorn from 66.0.0 to 68.0.0 (#22310)
* chore(deps-dev): bump eslint-plugin-unicorn from 66.0.0 to 68.0.0

Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 66.0.0 to 68.0.0.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v66.0.0...v68.0.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-unicorn
  dependency-version: 68.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* style: fix no-useless-coercion

* style: fix prefer-boolean-return

* style: fix no-useless-logical-operand

* style: fix prefer-single-replace

* style: fix consistent-conditional-object-spread

* style: fix no-useless-else

* style: fix prefer-unicode-code-point-escapes

* style: fix operator-assignment

* style: fix prefer-continue

* style: fix prefer-math-constants

* style: fix prefer-hoisting-branch-code

* style: fix prefer-array-slice

* style: fix consistent-class-member-order

* style: fix no-return-array-push

* style: fix prefer-promise-with-resolvers

* style: fix no-array-concat-in-loop

* style: fix no-loop-iterable-mutation

* style: fix no-invalid-argument-count

* style: fix no-duplicate-if-branches

* style: fix prefer-else-if

* style: fix no-unreadable-for-of-expression

* style: fix logical-assignment-operators

* style: fix default-export-style

* style: revert false positve in prefer-type-literal-last in #22274

* style: fix arrow-body-style

* style: add v68 recommended preset

* style: refactor GraphQL queries to use template literals for better readability

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2026-06-20 23:11:27 +08:00

82 lines
2.9 KiB
TypeScript

import { renderToString } from 'hono/jsx/dom/server';
import type { Route } from '@/types';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
export const route: Route = {
path: '/column/:id?',
categories: ['traditional-media'],
example: '/nmtv/column/877',
parameters: { id: '栏目 id,可在对应栏目 URL 中找到' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '点播',
maintainers: ['nczitzk'],
handler,
description: `::: tip
如 [蒙古语卫视新闻联播](http://www.nmtv.cn/folder292/folder663/folder301/folder830/folder877) 的 URL 为 \`http://www.nmtv.cn/folder292/folder663/folder301/folder830/folder877\`,其栏目 id 为末尾数字编号,即 \`877\`。可以得到其对应路由为 [\`/nmtv/column/877\`](https://rsshub.app/nmtv/column/877)
:::`,
};
async function handler(ctx) {
const id = ctx.req.param('id') ?? '877';
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100;
const hostUrl = 'https://vod.m2oplus.nmtv.cn';
const apiRootUrl = 'https://mapi.m2oplus.nmtv.cn';
const apiUrl = `${apiRootUrl}/api/v1/contents.php?offset=0&count=${limit}&column_id=${id}`;
const response = await got({
method: 'get',
url: apiUrl,
});
const data = response.data;
const items = data.map((item) => {
const enclosure_url = `${hostUrl}/${item.target_path}${item.target_filename}`;
const enclosure_type = `${item.type}/${enclosure_url.match(/\.(\w+)$/)[1]}`;
return {
title: item.title,
link: item.content_url,
author: item.column_name,
pubDate: timezone(parseDate(item.publish_time), 8),
description: renderToString(
item.type === 'audio' ? (
<audio controls="controls">
<source src={enclosure_url} type="audio/mp3" />
</audio>
) : item.type === 'video' ? (
<video controls poster={item.index_pic}>
<source src={enclosure_url} type="video/mp4" />
</video>
) : null
),
enclosure_url,
enclosure_type,
itunes_duration: item.video.duration,
itunes_item_image: item.index_pic,
};
});
const author = data[0].column_name;
const imageUrl = data[0].column_info.indexpic;
return {
title: `内蒙古广播电视台 - ${author}`,
link: items[0].link.split(/\/\d{4}-\d{2}-\d{2}\//, 1)[0],
item: items,
image: `${imageUrl.host}${imageUrl.filepath}${imageUrl.filename}`,
itunes_author: author,
};
}