微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决youtube-dl不适用于所有youtube视频

我使用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)

任何建议。

解决方法

某些视频无法正常工作,因为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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。