Don't re-resolve a favorite whose URL is already the media file

Some channels hand back the media URL itself as an item's url. Since the
favorites fix, opening one of those sent it to /api/resolve first, so
yt-dlp fetched the media just to report the URL we already had. On a
signed link (`?secure=<ts>-<token>`) that is a second request against
something that may be single-use or IP-bound, and the request that
matters -- the playback fetch -- is then refused. Such URLs now play
directly, with no resolve round trip, as they did before.

Alongside that, three things that make expiry survivable:

/api/stream, after its existing referer-less retry, now retries a 403
completely bare (Range only). Signed CDN links are routinely served to a
plain browser request and refused when it carries extras -- a
`Sec-Fetch-Mode: navigate` on a media subresource, say, which is what
yt-dlp's generic extractor hands back and no real player would send.

When every source fails, the player re-resolves once and retries instead
of giving up, since the likeliest cause is that signed URLs went stale in
a long-open tab rather than the video being gone. A manual quality pick
is dropped for that retry, as it names one of the URLs that just failed.

Favorites stored by older versions still carry a `meta` blob of resolved
formats, long expired; it's now stripped on read so nothing can reach for
one.

Verified: a favorite whose url is a .mp4 plays with zero /api/resolve
calls, straight from that URL; playback, prefetch, feed paging, HUD,
rotation, momentum and the version check all still pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QBDkEXP4htyXTCZUwMLphd
This commit is contained in:
Simon
2026-09-05 20:41:31 +00:00
parent 59f7c33ebd
commit d508263946
4 changed files with 84 additions and 1 deletions

View File

@@ -698,6 +698,27 @@ App.player = App.player || {};
if (settled || token !== cp.attemptToken) return;
settled = true;
if (hasNext) attempt(index + 1);
else if (!(opts && opts.refreshed) && App.videos &&
typeof App.videos.refreshFormats === 'function') {
// Every candidate failed. Media URLs are signed with an
// expiry, so the most likely cause is that these ones went
// stale (a tab left open, or formats resolved a while ago),
// not that the video is gone. Re-resolve and try once more
// before telling the viewer it can't be played.
App.videos.refreshFormats(videoData).then((meta) => {
if (token !== cp.attemptToken) return;
// A manually picked format points at one of the URLs
// that just failed, so the retry goes back to automatic
// selection over the freshly resolved list.
cp.formatOverride = null;
const retryOpts = Object.assign({}, opts, { refreshed: true, resumeAt });
if (meta) playSources(videoData, retryOpts);
else {
clearLoading();
showError(message, () => playSources(videoData, retryOpts), sourceUrl);
}
});
}
else {
clearLoading();
showError(message, () => playSources(videoData, opts), sourceUrl);