brandonbothell / popyt

A very easy to use Youtube Data v3 API library.
https://brandonbothell.github.io/popyt/
The Unlicense
43 stars 10 forks source link

Certain channels do not resolve #297

Closed ronvoluted closed 3 years ago

ronvoluted commented 3 years ago

This may be a YouTube limitation but reporting here in case it's otherwise. If you try getChannel() with this URL it will fail with "Item not found" error:

https://www.youtube.com/c/ChilledCow

but the same URL with a trailing slash will work just fine:

https://www.youtube.com/c/ChilledCow/

Using just "ChilledCow" also works. However, other channels do not work even with trailing slash or with only the end path.

const { YouTube } = require('popyt');
const youtube = new YouTube(YOUTUBE_KEY);

/*
Working:
'https://www.youtube.com/c/ChilledCow/'
'ChilledCow'

"Item not found":
'https://www.youtube.com/c/ChilledCow'
'https://www.youtube.com/c/fosterkittensofficial/'
'https://www.youtube.com/c/fosterkittensofficial'
'fosterkittensofficial'
*/

const query = 'https://www.youtube.com/c/ChilledCow/';

youtube
  .getChannel(query)
  .then(res => console.log(res.data.snippet))
  .catch(err => console.error(err));

When I load those failing URLs in the browser, they load fine and I can't discern any particular difference between the working and non-working URLs. Thank you for the library! 🙇🏼‍♂️

brandonbothell commented 3 years ago

The problem with the trailing slash was with my code. I have since fixed that, but I cannot push it until I finish my current YouTube API compliance review.

The problem with certain channels not working at all is due to a limitation with the YouTube API. There is no way to get a channel from its custom URL, so popyt sort of mimics this by grabbing the end of the URL and searching for it. In the case of "fosterkittensofficial", their actual username is "Cindy Congdon", so "fosterkittensofficial" returns no results (and if it did, they would most likely be garbage). I have also edited the documentation of the getChannel() function to clarify this.

Once my compliance review is complete, I will push these new changes and close this issue. Thanks!

ronvoluted commented 3 years ago

No worries and no rush! Glad a cause could be found.

Yeah for urls where there's no id or username, I just grabbed the html as is then regexed the id:

/(?<="channelId":")[A-Za-z0-9]{24}/g
/(?<="externalId":")[A-Za-z0-9]{24}/g
/(?<="browseId":")[A-Za-z0-9]{24}/g

Wasn't sure if channelId was always present so the other two are just fallbacks.

brandonbothell commented 3 years ago

I would add this, but the wrapper is purely meant to use the YouTube Data v3 API. The frontend can change unexpectedly, so scraping the website isn't an option. A good solution for anyone that really wants to be able to get a channel by its custom URL, though.

On Wed, Feb 17, 2021 at 11:51 PM Ron Au notifications@github.com wrote:

No worries and no rush! Glad a cause could be found.

Yeah for urls where there's no id or username, I just grabbed the html as is then regexed the id:

/(?<="channelId":")[A-Za-z0-9]{24}/g /(?<="externalId":")[A-Za-z0-9]{24}/g/(?<="browseId":")[A-Za-z0-9]{24}/g

Wasn't sure if channelId was always present so the other two are just fallbacks.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/jasonhaxstuff/popyt/issues/297#issuecomment-781048396, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIRI62R7B7SDW5RR2J7LPJDS7SMEZANCNFSM4VTH2FSQ .

ronvoluted commented 3 years ago

Oh 100% agreed, just an account of how one person ended up resolving it.