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}`)
		}
	}
})()
相关推荐
weixin_571667419 小时前
[解决] Node.js 安装后 命令找不到
node.js
潇凝子潇10 小时前
chrome插件-给音视频添加倍速播放控制功能
音视频·chrome devtools
sweetone10 小时前
SONY老式磁带随身听wm-fx193 之摩机过程(提升重低音音效,改耳放)
经验分享·音视频
孜孜不倦不忘初心11 小时前
mac安装nvm及问题记录
前端·node.js
数据法师11 小时前
视频文件重复检测工具:基于哈希与视频指纹的三级筛选机制
算法·音视频·哈希算法
AI创界者12 小时前
告别云端限制!Sulphur 2 本地文生视频/图生视频整合包,本地部署,解压即用,保姆级部署与工作流实战
人工智能·python·aigc·音视频
南山有乔木78913 小时前
NCM格式在线转换MP3怎么操作?解决ncm打不开和无法导入问题
音视频
快乐的哈士奇14 小时前
Gmail-邮件自动处理系统
node.js·自动化·excel
星空16 小时前
Node.js (Express) + Vue2 Axios 前后端交互 CRUD
vue.js·node.js·express
小鹿研究点东西16 小时前
AI直播系统怎么搭?
人工智能·ffmpeg·自动化·音视频·语音识别