Auto-switch source when AllManga lacks the requested episode#90
Open
nevatas wants to merge 1 commit into
Open
Conversation
AllManga doesn't always have every episode (especially newer or less
popular titles). The default source for anime content is AllManga, so
the user currently gets an "Episode not found on AllManga · Try a
different source" overlay and has to manually switch sources each visit.
Add per-episode failover:
* On AllManga resolve failure (res.ok === false), automatically switch
to the next non-async source (Videasy → VidSrc → 2Embed) and remember
the choice in localStorage keyed by (tmdbId, season, episode, dub).
* On subsequent visits to the same episode, skip the AllManga IPC call
and load the cached fallback directly.
* On AllManga resolve success, clear the cache entry so we don't keep
overriding once the title becomes available upstream.
* Manual source picks clear the entry for the current episode, so the
auto-switch can't fight the user's explicit choice.
Network/timeout errors still surface the existing error overlay — only
explicit "episode missing" responses trigger the failover, so a flaky
connection won't silently change sources.
Covers both episodic content (TVPage) and movies (MoviePage). Cache
keys: tv_<tmdbId>_s<season>_e<ep>_<sub|dub> and movie_<tmdbId>_<sub|dub>.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What you'll see today
Pick an anime title in the app and try to play an episode that AllManga doesn't have (e.g. Naruto Shippuden S1E1 currently fails for me). The player overlay says:
…and the user has to manually open the source picker and re-pick a non-anime source. Then do it again the next time they visit the same episode, because the choice isn't remembered per title.
What this PR does
Adds a tiny per-episode failover cache so the app does the manual step for the user, once:
resolveAllMangareturns{ ok: false }for an episode, the resolve effect now switchesplayerSourceto the next non-async source inPLAYER_SOURCESorder (Videasy → VidSrc → 2Embed) instead of surfacing the error overlay, and writes the choice intostorage.SOURCE_FAILOVER_CACHEkeyed bytv_<tmdbId>_s<season>_e<ep>_<dub>(ormovie_<tmdbId>_<dub>for movies).resolveAllMangasuccess the cache entry is cleared, so once AllManga gets the title we naturally fall back to the user's normal preference.Only the explicit "no playable link" branch triggers the switch — network/timeout errors still go through the existing
setResolveErrorpath so a flaky connection doesn't silently change sources.Why this design
I considered two other approaches and rejected them:
Files changed
src/utils/storage.js— addsSTORAGE_KEYS.SOURCE_FAILOVER_CACHEand three helpers:getFailoverSource(epKey),setFailoverSource(epKey, sourceId),clearFailoverSource(epKey). The shape is a flat{ [epKey]: sourceId }object kept inlocalStorage.src/utils/api.js— addsgetNextNonAsyncSource(currentId)helper that walksPLAYER_SOURCESand returns the next entry whoseasyncflag is falsy. Async sources are skipped because they share AllManga's "missing episode" failure mode and we'd just loop.src/pages/TVPage.jsx— wires the cache into the existing AllManga resolveuseEffect: read the cached source up front, write it on!res.ok, clear it on success. The source-pickeronClickalso clears the entry for the current episode before applying the user's manual choice.src/pages/MoviePage.jsx— same wiring for the single-resolve movie path withmovie_<tmdbId>_<dub>as the cache key.How to verify