youtube-dl not working for all youtube videos

Viewed 2020

I use Youtube API to collect data, then I use node.js Youtube Downloader. On the end I use video on classic html5 <video> tag.

In some reasons some video's work well some not.

I use this package on server part -> 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

Error logon server side:


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)

Any suggestions.

1 Answers

Some videos do not work because Youtube does not always expose their video's urls when requested.

Youtube-DL makes a request to http://www.youtube.com/get_video_info?video_id=XXXX (where XXXX is the video ID) and this returns a JSON text file which has a listing of file urls for the MP4 / webM / M4A, OGG etc, associated with the requested video upload.

For example:

(1) Is working: You can find googlevideo.com links (MP4 etc) mentioned inside the JSON
Pinocchio (trailer) : http://www.youtube.com/get_video_info?video_id=y8UDuUVwUzg

(2) Not working: You cannot find googlevideo.com links in this JSON (no video links to download)
Mirage (full film) : http://www.youtube.com/get_video_info?video_id=FTY-L-l3KN8

Related