Coder Social home page Coder Social logo

get `videoInfo` from url link about scraper HOT 7 OPEN

yimura avatar yimura commented on June 11, 2024
get `videoInfo` from url link

from scraper.

Comments (7)

Yimura avatar Yimura commented on June 11, 2024

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?

from scraper.

Ayeven avatar Ayeven commented on June 11, 2024

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

from scraper.

Yimura avatar Yimura commented on June 11, 2024

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
        }
    ]
}

from scraper.

Ayeven avatar Ayeven commented on June 11, 2024

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

from scraper.

Ayeven avatar Ayeven commented on June 11, 2024

image
Sometime it able to capture the title

from scraper.

Yimura avatar Yimura commented on June 11, 2024

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

from scraper.

Ayeven avatar Ayeven commented on June 11, 2024

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

from scraper.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.