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 basic info from yt music.getArtist() call. #226

Closed
4 tasks done
titong0 opened this issue Nov 4, 2022 · 3 comments
Closed
4 tasks done

Get basic info from yt music.getArtist() call. #226

titong0 opened this issue Nov 4, 2022 · 3 comments
Labels
question Further information is requested

Comments

@titong0
Copy link
Contributor

titong0 commented Nov 4, 2022

Question

Is there any way to get a channel's Name and profile picture? my old code looked like this

  const artist = await client.music.getArtist(channelId);

  return {
      name: artist.header?.title.text,
      avatar: artist.header.thumbnail?.contents,
      description: artist.header.description.text,
      id: channelId,
    }

but as of version 2.3.0, artist.header.title is possibly undefined.
thumbnail and description are only present in MusicVisualHeader and MusicInmersiveHeader. but artist.header can also be MusicHeader which doesn't have them.

  1. How can I get the channels name without having to do optional chaining? (I feel like artis.header?.title.text could break)
  2. How can I get the avatar and (if present) description?

Other details

I saw this issue but I'm pretty sure this information could be obtained without an additional call.

Checklist

  • I am running the latest version.
  • I checked the documentation and found no answer.
  • I have searched the existing issues and made sure this is not a duplicate.
  • I have provided sufficient information.
@titong0 titong0 added the question Further information is requested label Nov 4, 2022
@itsmenewbie03
Copy link
Contributor

Not sure if this is the best approach but this could work xD

    const artist = await yt.music.getArtist(cId);
    const name = artist.header.title?.text;
    if (artist.header.type === 'MusicVisualHeader') {
        //has profile pic probably
        var avatar = artist.header.foreground_thumbnails[0].url
    }
    else if (artist.header.type === 'MusicImmersiveHeader') {
        //has banner
        var desc = artist.header.description?.text
        var avatar = artist.header.thumbnail.contents[0].url
    }

@LuanRT
Copy link
Owner

LuanRT commented Nov 6, 2022

MusicHeader is used in other pages where it doesn't need a title, but I doubt that will ever be the case for artist pages, so I wouldn't worry about that. And as for the description, profile pictures and banners you'll have to manually check the header type. If it helps, YouTube Music seems to favor MusicImmersiveHeader.

@titong0
Copy link
Contributor Author

titong0 commented Nov 7, 2022

Thanks! I'll try this method out.

@titong0 titong0 closed this as completed Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants