Merge pull request #299 from Stremio/trakt-integration

Trakt integration
This commit is contained in:
Nikola Hristov 2022-09-12 14:10:47 +03:00 committed by GitHub
commit 91db29c4c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 19 deletions

View file

@ -90,6 +90,12 @@ const App = () => {
action: 'PullAddonsFromAPI'
}
});
services.core.transport.dispatch({
action: 'Ctx',
args: {
action: 'PullUserFromAPI'
}
});
}
}, [initialized]);
return (

View file

@ -186,7 +186,6 @@ const Intro = ({ queryParams }) => {
tos: state.termsAccepted,
privacy: state.privacyPolicyAccepted,
marketing: state.marketingAccepted,
time: new Date(),
from: 'web'
}
}

View file

@ -18,14 +18,14 @@ const useSettings = require('./useSettings');
const styles = require('./styles');
const Player = ({ urlParams, queryParams }) => {
const { core, chromecast } = useServices();
const { chromecast } = useServices();
const [forceTranscoding, maxAudioChannels] = React.useMemo(() => {
return [
queryParams.has('forceTranscoding'),
queryParams.has('maxAudioChannels') ? parseInt(queryParams.get('maxAudioChannels'), 10) : null
];
}, [queryParams]);
const [player, updateLibraryItemState, pushToLibrary] = usePlayer(urlParams);
const [player, timeChanged, pausedChanged, ended, pushToLibrary] = usePlayer(urlParams);
const [settings, updateSettings] = useSettings();
const streamingServer = useStreamingServer();
const routeFocused = useRouteFocused();
@ -42,6 +42,7 @@ const Player = ({ urlParams, queryParams }) => {
const [videoState, setVideoState] = React.useReducer(
(videoState, nextVideoState) => ({ ...videoState, ...nextVideoState }),
{
manifest: null,
stream: null,
paused: null,
time: null,
@ -75,6 +76,7 @@ const Player = ({ urlParams, queryParams }) => {
}
}, []);
const onImplementationChanged = React.useCallback((manifest) => {
setVideoState({ manifest });
manifest.props.forEach((propName) => {
dispatch({ type: 'observeProp', propName });
});
@ -93,16 +95,8 @@ const Player = ({ urlParams, queryParams }) => {
setVideoState({ [propName]: propValue });
}, []);
const onEnded = React.useCallback(() => {
ended();
pushToLibrary();
if (player.libraryItem !== null) {
core.transport.dispatch({
action: 'Ctx',
args: {
action: 'RewindLibraryItem',
args: player.libraryItem._id
}
});
}
if (player.nextVideo !== null) {
window.location.replace(
typeof player.nextVideo.deepLinks.player === 'string' ?
@ -302,10 +296,17 @@ const Player = ({ urlParams, queryParams }) => {
dispatch({ type: 'setProp', propName: 'extraSubtitlesOutlineColor', propValue: settings.subtitlesOutlineColor });
}, [settings.subtitlesOutlineColor]);
React.useEffect(() => {
if (videoState.time !== null && !isNaN(videoState.time) && videoState.duration !== null && !isNaN(videoState.duration)) {
updateLibraryItemState(videoState.time, videoState.duration);
if (videoState.time !== null && !isNaN(videoState.time) &&
videoState.duration !== null && !isNaN(videoState.duration) &&
videoState.manifest !== null && typeof videoState.manifest.name === 'string') {
timeChanged(videoState.time, videoState.duration, videoState.manifest.name);
}
}, [videoState.time, videoState.duration]);
}, [videoState.time, videoState.duration, videoState.manifest]);
React.useEffect(() => {
if (videoState.paused !== null) {
pausedChanged(videoState.paused);
}
}, [videoState.paused]);
React.useEffect(() => {
if ((!Array.isArray(videoState.subtitlesTracks) || videoState.subtitlesTracks.length === 0) &&
(!Array.isArray(videoState.extraSubtitlesTracks) || videoState.extraSubtitlesTracks.length === 0) &&

View file

@ -86,12 +86,12 @@ const usePlayer = (urlParams) => {
};
}
}, [urlParams]);
const updateLibraryItemState = React.useCallback((time, duration) => {
const timeChanged = React.useCallback((time, duration, device) => {
core.transport.dispatch({
action: 'Player',
args: {
action: 'UpdateLibraryItemState',
args: { time, duration }
action: 'TimeChanged',
args: { time, duration, device }
}
}, 'player');
}, []);
@ -103,8 +103,25 @@ const usePlayer = (urlParams) => {
}
}, 'player');
}, []);
const ended = React.useCallback(() => {
core.transport.dispatch({
action: 'Player',
args: {
action: 'Ended'
}
}, 'player');
}, []);
const pausedChanged = React.useCallback((paused) => {
core.transport.dispatch({
action: 'Player',
args: {
action: 'PausedChanged',
args: { paused }
}
}, 'player');
}, []);
const player = useModelState({ model: 'player', action, map });
return [player, updateLibraryItemState, pushToLibrary];
return [player, timeChanged, pausedChanged, ended, pushToLibrary];
};
module.exports = usePlayer;