Scraper icon indicating copy to clipboard operation
Scraper copied to clipboard

get `videoInfo` from url link

Open Ayeven opened this issue 4 years ago • 7 comments

Is your feature request related to a problem? Please describe. This package is fast in searching youtube videos, and should state in the documentation the limit it search. As I wanted to get video info from the link, sometime the title return undefined, thus forcing me to make it Unknown Track.

Describe the solution you'd like Get video info at least title from the provided link parameter

Describe alternatives you've considered No idea

Additional context

image

Ayeven avatar Jul 06 '21 13:07 Ayeven

Could you give a small example of your code? I don't seem to understand the issue at hand.

In the image it shows a list of found track titles but then when you select a track the title is undefined?

Yimura avatar Jul 06 '21 13:07 Yimura

That quite fast response, here is the line https://github.com/Ayeven/generic-bot/blob/c87589523aefc7b87c0a95959b51239285b89698/base/track.js#L86 which I can't extract info from url link. I console log it, return empty array. The music is correctly playing the right track, but title become undefined since empty array. This is the full repo link : https://github.com/Ayeven/generic-bot

Ayeven avatar Jul 06 '21 14:07 Ayeven

This is expected behavior as this Scraper just replicates the search from YouTube and parses the response data, if you were to fill in an URL in YouTube search it might return the expected video or it might not...

const { Scraper } = require('@yimura/scraper');
const ytsr = new Scraper();

ytsr.search("keywords");

=> image

If YouTube doesn't return data for a link then we can't parse it, your code also seems incorrect as the return object for Scraper#search() is vastly different and doesn't contain the title property.

Example Return Object:

{
    channels: [
        { ... }
    ],
    playlists: [
        { ... }
    ],
    streams: [
        { ... }
    ],
    videos: [
        {
            description: String,
            duration: Number,
            uploaded: String,
            views: Number,
            channel: {
                name: String,
                link: String,
                verified: Boolean
            },
            id: String,
            link: String,
            thumbnail: String,
            title: String,
            shareLink: String
        }
    ]
}

Yimura avatar Jul 06 '21 14:07 Yimura

if ((url.startsWith('https://www.youtube.com/')) || (url.startsWith('https://youtu.be')) || (url.startsWith('https://m.youtube.com'))) { const yt = await ytsr.search(url); console.log(yt); info = yt.videos[0].title ?? 'Unknown Track'; } Yeah, found the issue now, sorry to bug you, must've been rushing reading the #readme. Edit : console.log : https://youtu.be/FHr3g1c11yw { channels: [], playlists: [], streams: [], videos: [] } TypeError: Cannot read property 'title' of undefined. still seem not able to capture the title from url link

image from youtube search

Ayeven avatar Jul 06 '21 14:07 Ayeven

image Sometime it able to capture the title

Ayeven avatar Jul 06 '21 15:07 Ayeven

This inconsistency comes down to YouTube themselves.

I'm unable to reproduce your issue, seems to do what it is supposed to... https://runkit.com/embed/o1fw9ymgai9g

Yimura avatar Jul 06 '21 15:07 Yimura

let info = ''; if ((url.startsWith('https://www.youtube.com/')) || (url.startsWith('https://youtu.be')) || (url.startsWith('https://m.youtube.com'))) { const yt = new Scraper(); const ytsr = await yt.search(id || url); info = ytsr.videos[0]?.title ?? 'Unknown Track'; } else if (url.startsWith('https://soundcloud.com/')) { const sc = await scdl.getInfo(url || id); info = sc.title; } else { info = 'Unknown Track'; } Lmao, some solution for that inconsistency, so far it can capture it, well it is from the video id. I'll see if the issue persist

Ayeven avatar Jul 06 '21 16:07 Ayeven