gpt4 book ai didi

html - youtube-dl 不适用于所有 youtube 视频

转载 作者:行者123 更新时间:2023-12-03 05:28:27 25 4
gpt4 key购买 nike

我使用Youtube API 收集数据,然后我使用node.js影片下载。
最后,我在经典 html5 上使用视频 <video>标签。
由于某些原因,有些视频效果很好,有些则不行。
我在服务器部分使用这个包 - >
https://www.npmjs.com/package/youtube-dl

    if (request.url.search(/.nidza|.dzoni/g) != -1) {

// file.serveFile('bad.html', 402, {}, request, response);
const localVid = request.url.split("?vid=")
console.log("videoID => ", localVid[1])
console.log("Vule bule request.url., ", request.url)
const addressLink = 'http://www.youtube.com/watch?v=' + localVid[1]
const checkvideo = '../dist/videos/vule' + localVid[1] + '.mp4'

try {
if (fs.existsSync(checkvideo)) {
// file exists
console.log("skip...")
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('[video-exist]');
return;
}
} catch(err) {
console.error(err)
}

const myPromise = new Promise((resolve, reject) => {

var test = youtubedl(addressLink, ['--format=18'], { cwd: __dirname })
try{
resolve(test)
} catch(err) {
reject(err)
}

}).then((video) => {

video.on('info', function(info) {
console.log('Download started')
console.log('filename: ' + info._filename)
console.log('size: ' + info.size)
})

const videoName = '../dist/videos/vule' + localVid[1] + '.mp4';
video.pipe(fs.createWriteStream(videoName, {
flag: "w+"
}))

}).catch(function(err) {
reject().than(()=>{
console.log("Error in promise youtubedl => ", err)
})
});

response.writeHead(200, {'Content-Type': 'text/plain'})
response.end(`VuleTube service version 0.3.1 \n
https://maximumroulette.com:3000 `)

}
Link for server node.js
错误登录服务器端:

f an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:23569) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Request contains invalid range header: [ '0', '' ]
Error: Range request present but invalid, might serve whole file instead
at Server.respondNoGzip (/var/www/html/applications/vue-project/vue-typescript-starter/vue-ts-starter/server/node_modules/node-static/lib/node-static.js:297:23)
at Server.respond (/var/www/html/applications/vue-project/vue-typescript-starter/vue-ts-starter/server/node_modules/node-static/lib/node-static.js:350:14)
at /var/www/html/applications/vue-project/vue-typescript-starter/vue-ts-starter/server/node_modules/node-static/lib/node-static.js:146:22
at FSReqWrap.oncomplete (fs.js:166:5)
Range request exceeds file boundaries, goes until byte no 524287 against file size of 1312 bytes
Error: Range request present but invalid, might serve whole file instead
at Server.respondNoGzip (/var/www/html/applications/vue-project/vue-typescript-starter/vue-ts-starter/server/node_modules/node-static/lib/node-static.js:297:23)
at Server.respond (/var/www/html/applications/vue-project/vue-typescript-starter/vue-ts-starter/server/node_modules/node-static/lib/node-static.js:350:14)
at /var/www/html/applications/vue-project/vue-typescript-starter/vue-ts-starter/server/node_modules/node-static/lib/node-static.js:64:22
at FSReqWrap.oncomplete (fs.js:166:5)

有什么建议。

最佳答案

某些视频不起作用,因为 Youtube 并不总是在请求时公开其视频的网址。
Youtube-DL 向 http://www.youtube.com/get_video_info?video_id=XXXX 发出请求(其中 XXXX 是视频 ID),这将返回一个 JSON 文本文件,其中包含与请求的视频上传相关联的 MP4/webM/M4A、OGG 等的文件 URL 列表。
例如:
(1) 正在工作:您可以找到 googlevideo.com JSON 中提到的链接(MP4 等)
匹诺曹(预告片):http://www.youtube.com/get_video_info?video_id=y8UDuUVwUzg
(2) 不工作:您找不到 googlevideo.com此 JSON 中的链接(没有可下载的视频链接)
Mirage(全片):http://www.youtube.com/get_video_info?video_id=FTY-L-l3KN8

关于html - youtube-dl 不适用于所有 youtube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64650797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com