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}`)
		}
	}
})()
相关推荐
largecode4 分钟前
能不能让座机号码显示“XX公司”那样的认证名称?申请号码认证方法
经验分享·笔记·音视频·课程设计·oneapi·segmentfault·微信开放平台
美狐美颜sdk2 小时前
美颜SDK开发难点有哪些?Android/iOS美颜SDK接入
人工智能·音视频·直播美颜sdk·视频美颜sdk·美狐美颜sdk
blevoice2 小时前
JL杰理AC696N开发板上调试蓝牙音质优化:开启AAC高清音频支持
单片机·ffmpeg·音视频·aac·ac6966b蓝牙音响方案·杰理智能音箱开发·杰理ac6965e蓝牙音频开发
Elastic 中国社区官方博客2 小时前
jina-embeddings-v5-omni:用于文本、图像、音频和视频的 embeddings
大数据·人工智能·elasticsearch·搜索引擎·ai·音视频·jina
EasyGBS2 小时前
智慧工地、明厨亮灶、平安校园……国标GB28181视频平台EasyGBS凭什么成为ToB视频方案的“万能基座”?
网络·音视频
Czzzzlq2 小时前
【无标题】
typescript·node.js·ai编程
CheungChunChiu3 小时前
Linux 音频子系统完整梳理:ALSA、ASoC、DAPM、Codec、Machine、es8389 与 rk‑multicodecs 全解析
linux·运维·音视频·codec·audio·asla·dapm
ZC跨境爬虫4 小时前
跟着MDN学HTML_day_46:(HTMLCollection与NodeList)
前端·javascript·ui·html·音视频
前端若水4 小时前
开发环境准备:Python、Node.js、Docker与Git
python·docker·node.js
HwJack204 小时前
深潜 HarmonyOS APP开发中AVSession 音视频会话管理
华为·音视频·harmonyos