Node.js 检测视频链接是否可以播放(批量检测)

Node.js 检测视频链接是否可以播放(批量检测)

  • 运行 node check-video.js
js 复制代码
//check-video.js
const sections = [
	{
		content_length_text: '01:42:37',
		content_length: 6157,
		index: 1,
		items: [
			{
				can_be_previewed: true,
				content_summary: '03:07',
				id: 42059630,
				title: 'What Is Social Media Marketing',
				object_index: 1,
				item_type: 'lecture',
			},
			{
				can_be_previewed: true,
				content_summary: '03:19',
				id: 42059642,
				title: 'Social Media Marketing - How to Use Social Platforms to Grow Your Business',
				object_index: 2,
				item_type: 'lecture',
			},
			{
				can_be_previewed: true,
				content_summary: '03:09',
				id: 42059658,
				title: 'Social Media Marketing Course - Top Social Platforms',
				object_index: 3,
				item_type: 'lecture',
			}],
		lecture_count: 21,
		title: 'Social Media Marketing',
	}]
// npm 安装依赖
const axios = require('axios')
function buildUrl(item, sitem) {
	const className = item.title // 一级目录
	const subClassName = sitem.title //二级标题
	return `/${className}/${subClassName}.mp4`
}

async function checkVideoHead(url) {
	try {
		const response = await axios.head(url)
		if (response.status === 200 && response.headers['content-type'].startsWith('video/')) {
			return { url, playable: true }
		} else {
			return { url, playable: false }
		}
	} catch (err) {
		return { url, playable: false }
	}
}

;(async () => {
	const allResults = []
    let count = 0 ;
	for (const section of sections) {
		for (const sitem of section.items) {
			const url = buildUrl(section, sitem)
			const result = await checkVideoHead(url)
			allResults.push(result)
             count ++;
			console.log(count,`${result.playable ? '✅' : '❌'} ${url}`)
		}
	}
})()
相关推荐
MingT 明天你好!37 分钟前
trae中安装mcp报Cannot find package/ERR_MODULE_NOT_FOUND问题
node.js·trae
桑榆肖物2 小时前
有字幕,没配音?用浏览器自带语音能力,让网页视频直接“开口说话”
数据库·edge·音视频·tts
米丘4 小时前
从 HTTP 到 WebSocket:深入 Vite HMR 的网络层原理
http·node.js·vite
米丘4 小时前
Node.js 事件循环
前端·javascript·node.js
Kel4 小时前
深入 Ink 源码:当 React 遇见终端 —— Custom Reconciler 全链路剖析
react.js·架构·node.js
ai产品老杨4 小时前
源码交付与全协议兼容:企业级 AI 视频中台的二次开发实战
人工智能·音视频
2403_896177535 小时前
怎么把AVI改成mp4?把AVI改成mp4的5种方法
microsoft·音视频
琪伦的工具库6 小时前
视频素材库迁移后的完整性验证:我们团队的检测方案
音视频
全马必破三6 小时前
Vue3+Node.js 实现AI流式输出全解析
前端·javascript·node.js