youtube-sr icon indicating copy to clipboard operation
youtube-sr copied to clipboard

getVideo() sometimes returns `null`

Open vincentwinkel opened this issue 1 year ago • 3 comments

Minimal Typescript code:

// debug.ts

import * as youtube from 'youtube-sr';

youtube.default.getVideo('https://www.youtube.com/watch?v=wMzIHuWh_I0').then(console.log);

Run by:

tsx debug.ts

It works perfectly on local, but on a Europe-hosted VPS, it logs null. I don't see any way to debug that but I dont think it's an issue about license.

Do you have an idea?

Note: search() seems working perfectly.

vincentwinkel avatar Dec 04 '24 17:12 vincentwinkel

my guess is that youtuube probably blocked the vps' ip or something, i'm not really sure. Here's an alternative lib that supports auth and more https://github.com/LuanRT/YouTube.js which could be stable compared to this scraper.

twlite avatar Dec 05 '24 03:12 twlite

this happen to me just now. and i can no longer use getVideo(). it always return null.

my setup is on local though, but i mainly use my home internet as a self hosted server. google probably added my static public IP to their blacklist since im using this library from when v4.3.11 was released

PGRjoystick avatar Jun 03 '25 11:06 PGRjoystick

So.. now it doesnt return null, but an error, even tho search() returns the correct media.

const url = 'https://www.youtube.com/watch?v=wMzIHuWh_I0';

// 1 -----

youtube.default.getVideo(url).then(console.log).catch(console.error);

// Error: Could not parse video metadata!

// 2 -----

youtube.default.search(url, { limit: 1, type: 'video' }).then(console.log).catch(console.error);

/* Result
[
  Video {
    nsfw: false,
    shorts: false,
    unlisted: false,
    id: 'wMzIHuWh_I0',
    title: 'Seekae - Test & Recognise (Flume Re-Work)',
    description: null,
    durationFormatted: '5:04',
    duration: 304000,
    uploadedAt: '10 years ago',
    views: 43964578,
    thumbnail: Thumbnail {
      id: 'wMzIHuWh_I0',
      width: 720,
      height: 404,
      url: 'https://i.ytimg.com/vi/wMzIHuWh_I0/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCFXe8Rd3LjlBZnqUZecGQYiqarkg'
    },
    channel: Channel {
      name: 'Flume',
      verified: true,
      id: 'UCXAhoI7XO2kafTMjocm0jCg',
      url: 'https://www.youtube.com/channel/UCXAhoI7XO2kafTMjocm0jCg',
      icon: [Object],
      subscribers: null
    },
    likes: 0,
    dislikes: 0,
    live: false,
    private: false,
    tags: [],
    music: undefined
  }
]
*/

vincentwinkel avatar Jun 18 '25 17:06 vincentwinkel