【问题标题】:youtube-dl not working for all youtube videosyoutube-dl 不适用于所有 youtube 视频
【发布时间】:2020-11-02 17:58:19
【问题描述】:

我使用 Youtube API 来收集数据,然后我使用 node.js Youtube Downloader。 最后,我在经典 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)

任何建议。

【问题讨论】:

  • 请添加可播放视频和不可播放视频之间的差异 - 检查浏览器的网址、网络选项卡,如果这些视频可用(嵌入、盗用、删除等)。
  • 不播放的视频是不是快速启动?
  • fast start 是什么意思? @szatmary
  • “moov”框的位置。如果你不知道这意味着什么,请谷歌它。如果您想流式传输 mp4 文件,这是您绝对必须知道的信息。
  • 这并不违法。投诉是由 RIAA(美国艺术家唱片业)提出的。如果你不使用 Taylor Swift 或 Micheal Jackson 这样的美国音乐,那么你就不符合他们的抱怨。这也已修复(YT-DL 拒绝下载此类文件)... PS:我不提倡任何下载,但如果您将其保持为友好使用,而不是一些不尊重和过度盗版,那么您可能会没事。

标签: html video youtube


【解决方案1】:

某些视频无法播放,因为 Youtube 并不总是在请求时公开其视频的网址。

Youtube-DL 向http://www.youtube.com/get_video_info?video_id=XXXX(其中XXXX 是视频 ID)发出请求,这将返回一个 JSON 文本文件,其中包含与 MP4 / webM / M4A、OGG 等相关联的文件 URL 列表请求的视频上传。

例如:

(1) 正在工作:您可以找到 JSON 中提到的 googlevideo.com 链接(MP4 等)
木偶奇遇记(预告片):http://www.youtube.com/get_video_info?video_id=y8UDuUVwUzg

(2) 不起作用:您在此 JSON 中找不到 googlevideo.com 链接(没有可下载的视频链接)
海市蜃楼(全片):http://www.youtube.com/get_video_info?video_id=FTY-L-l3KN8

【讨论】:

  • 我要试试。我将在关键视频上测试http://www.youtube.com/get_video_info?。我总是使用格式 -18 .....
  • 我测试了youtube-dl -F,所有资源都没有标准格式。在第一次捕获中,我将尝试获取信息,然后寻找正确的存在来源。谢谢
  • 我有机会再次检查,发现您的"not working" link实际上是一个直播。视频页面的源代码中提到了 M3U8 链接,如果您的应用可以播放 TS 文件,请尝试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-11
相关资源
最近更新 更多