Skip to content

fix: reliable thumbnail resolution in hqify with async sddefault upgrade - #400

Open
KrX3D wants to merge 3 commits into
reisxd:mainfrom
KrX3D:hqify_fix
Open

fix: reliable thumbnail resolution in hqify with async sddefault upgrade#400
KrX3D wants to merge 3 commits into
reisxd:mainfrom
KrX3D:hqify_fix

Conversation

@KrX3D

@KrX3D KrX3D commented Mar 8, 2026

Copy link
Copy Markdown

Problem

hqify was unconditionally setting thumbnails to sddefault.jpg
(640×480), but YouTube only generates sddefault for videos uploaded
after a certain point. Older videos return a 404 for that filename,
which the TV browser renders as a grey placeholder instead of the
actual thumbnail.

Switching blindly to hqdefault (480×360) fixes the grey box but
sacrifices resolution for videos where sddefault does exist.

Solution

Two-phase approach:

  1. Set hqdefault immediately — guaranteed to exist for every
    video ever uploaded, so no grey boxes under any circumstance.
  2. Async HEAD-check sddefault — if the CDN responds 200,
    upgrade the same thumbnails[0] reference in-place to the
    higher resolution version.

Because thumbs holds a live reference into the item object and the
TV layout pipeline runs after multiple JS microtasks, the HEAD response
(against the same CDN already warm from page load) typically resolves
before the renderer reads the thumbnail, so most videos get the
640×480 version with no visible flash or fallback.

Also adds an early continue guard for tiles with no existing
thumbnail URL (some home page tiles are lazy-loaded and arrive with
an empty thumbnails array), preventing a crash in those cases.

Additionally, the original thumbnail URL from YouTube's JSON contains a
long query string (visible as ?sqp=...&rs=... on the URL). This is a
CDN signature tied to the exact filename it was issued for — copying it
onto a different filename causes a signature mismatch and the CDN returns
the grey placeholder regardless of whether the file actually exists.
Dropping the query string entirely avoids this; plain filename URLs like
hqdefault.jpg and sddefault.jpg work without any signing.

Before:
image

After:
image

hqdefault is guaranteed for every video; sddefault is not generated
for older uploads and returns 404, causing a grey placeholder.
Set hqdefault immediately, then HEAD-check sddefault and upgrade
the thumbnail reference in-place if the CDN confirms it exists.

@ice-fly ice-fly left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execllent fix, code comments, and contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants