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}`)
		}
	}
})()
相关推荐
给大佬递杯卡布奇诺7 小时前
FFmpeg 基本API avcodec_alloc_context3函数内部调用流程分析
c++·ffmpeg·音视频
给大佬递杯卡布奇诺10 小时前
FFmpeg 基本API avio_open函数内部调用流程分析
c++·ffmpeg·音视频
Damon小智12 小时前
RedPlayer 视频播放器在 HarmonyOS 应用中的实践
音视频·harmonyos·鸿蒙·小红书·三方库·redplayer
Q_Q196328847514 小时前
python+uniapp基于微信小程序的助眠小程序
spring boot·python·小程序·django·flask·uni-app·node.js
孟陬14 小时前
事件驱动 vs 轮询:为什么 Node.js 官方推荐 `fs.watch()` 而非 `fs.watchFile`
node.js
云雾J视界14 小时前
Linux企业级解决方案架构:字节跳动短视频推荐系统全链路实践
linux·云原生·架构·kubernetes·音视频·glusterfs·elk stack
林希_Rachel_傻希希16 小时前
Express 入门全指南:从 0 搭建你的第一个 Node Web 服务器
前端·后端·node.js
Likeadust16 小时前
新版视频直播点播平台EasyDSS用视频破局,获客转化双提升
大数据·音视频
涛涛讲AI1 天前
一段音频多段字幕,让音频能够流畅自然对应字幕 AI生成视频,扣子生成剪映视频草稿
人工智能·音视频·语音识别
lzptouch1 天前
数据预处理(音频/图像/视频/文字)及多模态统一大模型输入方案
人工智能·音视频