DrKain / scrape-youtube

A lightning fast package to scrape YouTube search results
MIT License
108 stars 30 forks source link

TypeError: Cannot read property 'simpleText' of undefined #57

Closed wikanonymous-dev closed 2 years ago

wikanonymous-dev commented 2 years ago

Describe the bug Hi there! I got this error on my debugger TypeError: Cannot read property 'simpleText' of undefined from searching some channel. Channel is hiding the information about subscribers

I think you need add try catch for this function. Thank you

const convertSubs = (channel: any): number => {
    const count = channel.subscriberCountText.simpleText.split(' ').shift();

    // If there's no K, M or B at the end.
    if (!isNaN(+count)) return +count;

    const char = count.slice(-1);
    let slicedCount = Number(count.slice(0, -1));

    switch (char.toLowerCase()) {
        case 'k':
            slicedCount *= 1000;
            break;
        case 'k':
            slicedCount *= 1e6;
            break;
        case 'b':
            slicedCount *= 1e9;
            break;
    }

    return ~~slicedCount;
};

To Reproduce Steps to reproduce the behavior:

  1. Search query is UCadOPMAkX21lbuA1yj0JfCQ
  2. See error

Expected behavior It should return the channel's information with subscriberCount is zero or just '-'

Screenshots

Versions:

Additional context Add any other context about the problem here.

DrKain commented 2 years ago

Thanks for reporting. Would you mind telling me what query you searched to catch this error?

wikanonymous-dev commented 2 years ago

Thanks for reporting. Would you mind telling me what query you searched to catch this error?

Im searching for this channel id UCadOPMAkX21lbuA1yj0JfCQ with the option type is channel

DrKain commented 2 years ago

Should be resolved in 2.1.15. Let me know if you have any other problems. Thanks

wikanonymous-dev commented 2 years ago

Thanks. It works well