SuspiciousLookingOwl / scrape-yt

Simple lib to scrape information from youtube such as search results, video information, related videos, playlist information and up next video
https://www.npmjs.com/package/scrape-yt
MIT License
9 stars 3 forks source link

Thumbnail on search() sometimes return object #5

Closed KareemH closed 4 years ago

KareemH commented 4 years ago

I want to store the thumbnail url (which I presume is a string) into my database, and the field of where I store the thumbnail is type String

However, I receive this error image image

Interestingly, some songs are able to store the thumbnail url as a string (coverImage field)...... image

SuspiciousLookingOwl commented 4 years ago

It should return string, i figured out what causes this but i'm not going to release any update for it for now because i'm still working on improving getVideo() scrapping.

For now you can do something like this to check whether thumbnail is string or not

var videos = scrapeYt.search("something");

for (video of videos) {
    var thumbnailUrl = "";
    if (typeof video.thumbnail === "string") {
        thumbnailUrl = video.thumbnail;
    } else {
        thumbnailUrl = video.thumbnail.url
    }
    console.log(thumbnailUrl);
}
SuspiciousLookingOwl commented 4 years ago

Fixed on 2c504e2fad67195ee51310ffda9b03ea72ccd481 Updated at npm (v1.0.13)

Thanks for reporting this!