DrKain / scrape-youtube

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

[Feature request] Support for new channel handles #65

Closed DrKain closed 1 year ago

DrKain commented 1 year ago

Currently the old channel ID/URL is returned (still working) but YouTube is using @ handles.
This should be included in the 'channel' object along with the old ID. Example:

{
    "id": "UCYDD7WruLEgEBfjxeor48aw",
    "name": "The Heavy",
    "link": "https://www.youtube.com/channel/UCYDD7WruLEgEBfjxeor48aw",
    "verified": true,
    "thumbnail": "https://yt3.ggpht.com/oMj9hZlJsbS-JI4MUZnwPDcfwIW36KhYeA5CnOG3_5lwHPnmaY_FL5hjBuUFBo32esrBmoOiZKI=s0?imgmax=0"
}

..will become:

{
    "id": "UCYDD7WruLEgEBfjxeor48aw",
    "name": "The Heavy",
    "handle": "@TheHeavyOfficial",
    "link": "https://www.youtube.com/@TheHeavyOfficial",
    "verified": true,
    "thumbnail": "https://yt3.ggpht.com/oMj9hZlJsbS-JI4MUZnwPDcfwIW36KhYeA5CnOG3_5lwHPnmaY_FL5hjBuUFBo32esrBmoOiZKI=s0?imgmax=0"
}

ID should remain as it is unique/locked, unlike handles.

MohitBansal321 commented 1 year ago

Would you assign this issue to me @DrKain

DrKain commented 1 year ago

Sure thing

MohitBansal321 commented 1 year ago

https://github.com/DrKain/scrape-youtube/blob/HEAD/src/interface.ts#L52-L58

Let me know we need to include handles here nah?

DrKain commented 1 year ago

Yes, the interface should be updated accordingly

MohitBansal321 commented 1 year ago

how can I get the handle detail?

exports.getChannelData = function (video) {
    var channel = (video.ownerText || video.longBylineText)['runs'][0];
    return {
        id: channel.navigationEndpoint.browseEndpoint.browseId,
        name: channel.text,
        link: getChannelLink(channel),
        verified: isVerified(video),
        thumbnail: getChannelThumbnail(video)
    };
};

so after that, I can add a handle here file location scrape-youtube\lib\parser.js

DrKain commented 1 year ago

how can I get the handle detail?

You'll need to take a look at the render data to see where it's available. The best place to look would be the channel object.

so after that, I can add a handle here file location scrape-youtube\lib\parser.js

You won't need to modify the lib directory as it's auto-generated by the build script.

MohitBansal321 commented 1 year ago

Thank for it but i didn't find any way to get youtube handle

DrKain commented 1 year ago

That's fine, I'll un-assign and leave it open for another user unless I find the time later this week.

DrKain commented 1 year ago

Note for anyone reading this issue, the YouTube render data hasn't fully rolled out handles for all channels. I'm about to push an update shortly closing this issue but handles will be either null or a string.

If a handle is found the channel link will use the handle, otherwise it will default to the channel ID.

A good example of this is "The Heavy" topic channel, these are auto generated and do not have handles. https://www.youtube.com/channel/UCbGFbVqBTN3aCjUwz3FChFw

 {
    id: 'UCbGFbVqBTN3aCjUwz3FChFw',
    name: 'The Heavy - Topic',
    link: 'https://www.youtube.com/channel/UCbGFbVqBTN3aCjUwz3FChFw',
    handle: null,
    verified: false,
    thumbnail: 'https:https://yt3.ggpht.com/oMj9hZlJsbS-JI4MUZnwPDcfwIW36KhYeA5CnOG3_5lwHPnmaY_FL5hjBuUFBo32esrBmoOiZKI=s0?imgmax=0',
    description: '',
    videoCount: 139,
    subscribers: '0',
    subscriberCount: 0
  },
  {
    id: 'UCMBr8hDifMR8C8uNnTvzL-w',
    name: 'ROY Shiel-Roberts',
    link: 'https://www.youtube.com/@royshiel-roberts9035',
    handle: '@royshiel-roberts9035',
    verified: false,
    thumbnail: 'https://yt3.googleusercontent.com/ytc/AL5GRJVvrxLPwLVu5QmBhZYr1dyVFYVHb9PNK7iNAudCbA=s0?imgmax=0',
    description: 'For fun and my gaming stuff.',
    videoCount: 0,
    subscribers: '3',
    subscriberCount: 3
  }