Skip to content

Prevent YouTube API 403 errors from showing in tooltips #268

@jupjohn

Description

@jupjohn

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...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions