Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get videoInfo from url link #10

Open
Ayeven opened this issue Jul 6, 2021 · 7 comments
Open

get videoInfo from url link #10

Ayeven opened this issue Jul 6, 2021 · 7 comments
Labels
invalid This doesn't seem right

Comments

@Ayeven
Copy link

Ayeven commented Jul 6, 2021

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

@Yimura
Copy link
Owner

Yimura commented Jul 6, 2021

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 Yimura added the question Further information is requested label Jul 6, 2021
@Ayeven
Copy link
Author

Ayeven commented Jul 6, 2021

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

@Yimura
Copy link
Owner

Yimura commented Jul 6, 2021

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 Yimura added invalid This doesn't seem right and removed question Further information is requested labels Jul 6, 2021
@Ayeven
Copy link
Author

Ayeven commented Jul 6, 2021

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
Copy link
Author

Ayeven commented Jul 6, 2021

image
Sometime it able to capture the title

@Yimura
Copy link
Owner

Yimura commented Jul 6, 2021

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

@Ayeven
Copy link
Author

Ayeven commented Jul 6, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants