Stremio / stremio-core

⚛️ The Stremio Core: types, addon system, UI models, core logic
MIT License
993 stars 68 forks source link

Effects: recommend_open_item and recommend_open_url + tests #59

Open Ivshti opened 5 years ago

Ivshti commented 5 years ago

will result in: Event::RecommendedAction{ origin: Action, recommendation: Action } or Event::RecommendationFailed

Useful for Open and TryOpenURL

Should be defined in a separate module as Effects

recommend_open(args, addons, settings) - equivalent of stremio-models/utils/open.js - needs addons to get streams, and settings cause of bingeing; args should be a sum type of libItem/metaPreview/notifItem, along with intent, prevStreamBinge and video

recommend_open_url(url, ctx), equivalent of open-files.js:

In recommend_open_item, To get the last played stream, which is normally managed by the player, we will just read the storage directly We should pull the libaddon item from the API; if it’s newer, we should start playing the newer version

Opening subtitles must be handled by recommending a player action that will load them (addExtraSubtitles); the playerM will see this and remember them in PlayerPreferences, so it can add them again on next load

NOTE: we may drop the recommend_ from the name; just having this in the resulting actions will be OK

NOTE: because this has a loading state, it might need to be a Model

NOTE: streams will be auto-selected if there's one video.streams or if behaviorHints.bingeGroup matches with prevStreamBinge or if infoHash matches with prevStreamBinge as you can see here https://github.com/Stremio/stremio-models/blob/master/utils/open.js#L96

IMPORTANT: this is the code that will have to generate a temporary libItem, so make sure that the data is anonymized (a file name/path is not included)

nklhtv commented 2 years ago

All of the redirects that stremio-models/utils/open.js is responsible for must be handled using the deep_links mod. The only one thats not handled yet is the binge watching redirect. If there are others that are still not handled they must be listed here.

recommend_open_url should be a model. Possible structure of this model could be:

pub enum OpenUrlResult {
    DeepLink(Url),
    Addon(DescriptorLoadable),
    Stream(Stream),
}

pub struct OpenUrl {
    pub selected: Option<Url>,
    pub content: OpenUrlResult,
}

if the selected url starts with stremio:// protocol, it resolves as OpenUrlResult::DeepLink if fetching the selected url returns an addon manifest, it resolves as OpenUrlResult::Addon if none of the above matches then we interpred it as stream and we try to play it.