SuspiciousLookingOwl / youtubei

Get Youtube data such as videos, playlists, channels, video information & comments, related videos, up next video, and more!
https://suspiciouslookingowl.github.io/youtubei
MIT License
237 stars 50 forks source link

subscriberCount equals channel name when using findOne #116

Closed ShinyRa closed 1 day ago

ShinyRa commented 2 months ago

Bug description Fetching subscriberCount from profile returns the name of the youtube channel.

To Reproduce

import { Client } from "youtubei";

const youtube = new Client();

const run = async () => {
    const profile = await youtube.findOne("RickAstleyYT", { type: "channel"})
    console.log(profile.subscriberCount)
}

run()

Output image

Expected behavior subscriberCount should be populated with the number of subscribers to the youtube channel, rather than the name.

Probable fix This is likely due to a frontend update on youtube's and where the code looks to fetch subscriber count.

ShinyRa commented 2 months ago

I think it's either: https://github.com/SuspiciousLookingOwl/youtubei/blob/a39278641acf45f790ac33b9157ca1b959e770f2/src/youtube/Channel/ChannelParser.ts#L22

Or https://github.com/SuspiciousLookingOwl/youtubei/blob/a39278641acf45f790ac33b9157ca1b959e770f2/src/youtube/Channel/ChannelParser.ts#L42-L44

that causes this issue.

ShinyRa commented 2 months ago

It looks like it's an issue specific to retrieving channel data using the findOne method. For channels that do not result in an error while retrieving (see https://github.com/SuspiciousLookingOwl/youtubei/issues/115) the subscriberCount works fine.

const vSauce = await youtube.getChannel("UC6nSFpj9HTCZ5t-N3Rm3-HA");
const worthABuy = await youtube.getChannel("UCywBfpGBYhsczNuyyh6Cf6w");
const rickAstleyYT = await youtube.findOne("@RickAstleyYT", { type: "channel" });
const fireShip = await youtube.findOne("@Fireship", { type: "channel" });

console.log(vSauce.name);
console.log(vSauce.subscriberCount + "\n");

console.log(worthABuy.name);
console.log(worthABuy?.subscriberCount + "\n");

console.log(rickAstleyYT.name);
console.log(rickAstleyYT.subscriberCount + "\n");

console.log(fireShip.name);
console.log(fireShip.subscriberCount + "\n");

Output

image

SuspiciousLookingOwl commented 3 weeks ago

Hi, sorry for the late response. I lost motivation on maintaining anything YouTube-related for the past few weeks (including this project, and my app that uses YouTube services) ever since YouTube made changes regarding anti-bot which rendered my app unusable.

I recently tried a workaround (implementing OAuth) which seems to be working, so I'll try to get back to working on this library again soon / after I fix the issue that is preventing my app from running, but I'll be busy for a while (personal life matter) so it might take some time.

Appreciate the debugging info!

SuspiciousLookingOwl commented 2 weeks ago

I think this is just YouTube being derpy with the returned data:

This is the raw returned data from YouTube

{
  channelId: 'UCuAXFkgsw1L7xaCfnd5JJOw',
  title: { simpleText: 'Rick Astley' },
  navigationEndpoint: {
    clickTrackingParams: 'CFwQ2jAYASITCNr2-Ommq4kDFVdL9QUdLbAfRA==',
    commandMetadata: { webCommandMetadata: [Object] },
    browseEndpoint: {
      browseId: 'UCuAXFkgsw1L7xaCfnd5JJOw',
      canonicalBaseUrl: '/@RickAstleyYT'
    }
  },
  thumbnail: { thumbnails: [ [Object], [Object] ] },
  descriptionSnippet: { runs: [ [Object] ] },
  shortBylineText: { runs: [ [Object] ] },
  videoCountText: {
    accessibility: { accessibilityData: [Object] },
    simpleText: '4.18M subscribers'
  },
  subscriptionButton: { subscribed: false },
  ownerBadges: [ { metadataBadgeRenderer: [Object] } ],
  subscriberCountText: { simpleText: '@RickAstleyYT' },
  subscribeButton: {
    buttonRenderer: {
      style: 'STYLE_DESTRUCTIVE',
      size: 'SIZE_DEFAULT',
      isDisabled: false,
      text: [Object],
      navigationEndpoint: [Object],
      trackingParams: 'CF0Q8FsiEwja9vjppquJAxVXS_UFHS2wH0Q='
    }
  },
  trackingParams: 'CFwQ2jAYASITCNr2-Ommq4kDFVdL9QUdLbAfRA==',
  longBylineText: { runs: [ [Object] ] }
}

The value of subscribeCountText and videoCountText is swapped, I'm just gonna wait to see if YouTube will fix this

xiaohaoxing commented 3 days ago

this bug fixed in 1.6.6