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}`)
		}
	}
})()
相关推荐
道亦无名6 小时前
音频数据特征值提取 方法和步骤
android·音视频
西***63478 小时前
声画合一 智控全场 —— 高清数字会议系统重构现代会议新生态
音视频·会议系统
莫有杯子的龙潭峡谷9 小时前
在 Windows 系统上安装 OpenClaw
人工智能·node.js·安装教程·openclaw
REDcker10 小时前
RTSP 直播技术详解
linux·服务器·网络·音视频·实时音视频·直播·rtsp
微尘hjx10 小时前
【Gstreamer 应用程序开发手册 01】关于GSTREAMER
linux·音视频·媒体
石去皿10 小时前
轻量级 Web 应用 —— 把一堆图片按指定频率直接拼成视频,零特效、零依赖、零命令行
前端·音视频
进击的小头12 小时前
FIR滤波器实战:音频信号降噪
c语言·python·算法·音视频
Black蜡笔小新12 小时前
终结“监控盲区”:EasyGBS视频质量诊断技术多场景应用设计
人工智能·音视频·视频质量诊断
朝朝暮暮an15 小时前
Node.js-第一天学习内容
node.js
liliangcsdn15 小时前
视频嵌入表示生成方案的探索
数据库·人工智能·音视频