api icon indicating copy to clipboard operation
api copied to clipboard

Prevent YouTube API 403 errors from showing in tooltips

Open jupjohn opened this issue 3 years ago • 0 comments

As Chatterino grows, the calls to the YouTube API increase which causes call quotas to be hit more frequently. When a quota is exceeded, the Chatterino API returns a tooltip containing the YouTube HTML error response instead of the preview. Ideally c2api would return a nicer error message (such as "chatterino was unable to get information about this video"), or use an alternative source of data.

Since YouTube supports oEmbed, the thumbnail URL, video title, and channel name can be resolved without an API call. This is enough to present back to the user. An example workflow is below:

get YT preview request:
    call the YT API
    if YT call is success:
        return tooltip using YT data
    
    fetch oEmbed data
    return a slimmed down tooltip with just the thumbnail, title, & channel name

Example YT oEmbed response:

{
  "title": "Rick Astley - Never Gonna Give You Up (Official Music Video)",
  "author_name": "Rick Astley",
  "author_url": "https://www.youtube.com/c/RickastleyCoUkOfficial",
  "type": "video",
  "height": 113,
  "width": 200,
  "version": "1.0",
  "provider_name": "YouTube",
  "provider_url": "https://www.youtube.com/",
  "thumbnail_height": 360,
  "thumbnail_width": 480,
  "thumbnail_url": "https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg",
  "html": ...omitted for brevity...
}

jupjohn avatar Feb 15 '22 23:02 jupjohn