mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-28 17:08:46 +00:00
map subtitles origin from from ctx addons
This commit is contained in:
parent
907ccc04f4
commit
c8a14e51f5
1 changed files with 35 additions and 2 deletions
|
|
@ -1,13 +1,45 @@
|
|||
const React = require('react');
|
||||
const { useModelState } = require('stremio/common');
|
||||
|
||||
const initPlayer = () => ({
|
||||
const initPlayerState = () => ({
|
||||
selected: null,
|
||||
meta_resource: null,
|
||||
subtitles_resources: [],
|
||||
next_video: null
|
||||
});
|
||||
|
||||
const mapPlayerStateWithCtx = (player, ctx) => {
|
||||
const selected = player.selected;
|
||||
const meta_resource = player.meta_resource;
|
||||
const subtitles_resources = player.subtitles_resources.map((subtitles_resource) => {
|
||||
if (subtitles_resource.content.type === 'Ready') {
|
||||
const origin = ctx.content.addons.reduce((origin, addon) => {
|
||||
if (addon.transportUrl === subtitles_resource.request.base) {
|
||||
return typeof addon.manifest.name === 'string' && addon.manifest.name.length > 0 ?
|
||||
addon.manifest.name
|
||||
:
|
||||
addon.manifest.id;
|
||||
}
|
||||
|
||||
return origin;
|
||||
}, subtitles_resource.request.base);
|
||||
subtitles_resource.content.content = subtitles_resource.content.content.map((subtitles) => ({
|
||||
...subtitles,
|
||||
origin
|
||||
}));
|
||||
}
|
||||
|
||||
return subtitles_resource;
|
||||
}, []);
|
||||
const next_video = player.next_video;
|
||||
return {
|
||||
selected,
|
||||
meta_resource,
|
||||
subtitles_resources,
|
||||
next_video
|
||||
};
|
||||
};
|
||||
|
||||
const usePlayer = (urlParams) => {
|
||||
const loadPlayerAction = React.useMemo(() => {
|
||||
try {
|
||||
|
|
@ -34,7 +66,8 @@ const usePlayer = (urlParams) => {
|
|||
return useModelState({
|
||||
model: 'player',
|
||||
action: loadPlayerAction,
|
||||
init: initPlayer
|
||||
init: initPlayerState,
|
||||
mapWithCtx: mapPlayerStateWithCtx
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue