Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark Video as Watched When Using External Player #424

Merged
merged 4 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/routes/MetaDetails/MetaDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ const MetaDetails = ({ urlParams, queryParams }) => {
<StreamsList
className={styles['streams-list']}
streams={metaDetails.streams}
video={video}
/>
:
metaPath !== null ?
Expand Down
26 changes: 21 additions & 5 deletions src/routes/MetaDetails/StreamsList/Stream/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { useServices } = require('stremio/services');
const StreamPlaceholder = require('./StreamPlaceholder');
const styles = require('./styles');

const Stream = ({ className, addonName, name, description, thumbnail, progress, deepLinks, ...props }) => {
const Stream = ({ className, videoId, addonName, name, description, thumbnail, progress, deepLinks, ...props }) => {
const profile = useProfile();
const streamingServer = useStreamingServer();
const { core } = useServices();
Expand All @@ -29,10 +29,22 @@ const Stream = ({ className, addonName, name, description, thumbnail, progress,
:
null;
}, [deepLinks, profile, streamingServer]);
const onClick = React.useCallback((e) => {
const markVideoAsWatched = React.useCallback(() => {
if (typeof videoId === 'string') {
core.transport.dispatch({
action: 'MetaDetails',
args: {
action: 'MarkVideoAsWatched',
args: [videoId, true]
}
});
}
}, [videoId]);
const onClick = React.useCallback((event) => {
if (href === null) {
// link does not lead to the player, it is expected to
// open with local video player through the streaming server
markVideoAsWatched();
core.transport.dispatch({
action: 'StreamingServer',
args: {
Expand All @@ -43,15 +55,18 @@ const Stream = ({ className, addonName, name, description, thumbnail, progress,
}
}
});
} else if (profile.settings.playerType === 'external') {
} else if (profile.settings.playerType !== 'internal') {
markVideoAsWatched();
toast.show({
type: 'success',
title: 'Stream opened in external player',
timeout: 4000
});
}
props.onClick(e);
}, [href, deepLinks, props.onClick, profile, toast]);
if (typeof props.onClick === 'function') {
props.onClick(event);
}
}, [href, deepLinks, props.onClick, profile, toast, markVideoAsWatched]);
const forceDownload = React.useMemo(() => {
// we only do this in one case to force the download
// of a M3U playlist generated in the browser
Expand Down Expand Up @@ -95,6 +110,7 @@ Stream.Placeholder = StreamPlaceholder;

Stream.propTypes = {
className: PropTypes.string,
videoId: PropTypes.string,
addonName: PropTypes.string,
name: PropTypes.string,
description: PropTypes.string,
Expand Down
8 changes: 5 additions & 3 deletions src/routes/MetaDetails/StreamsList/StreamsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const styles = require('./styles');

const ALL_ADDONS_KEY = 'ALL';

const StreamsList = ({ className, ...props }) => {
const StreamsList = ({ className, video, ...props }) => {
const { t } = useTranslation();
const { core } = useServices();
const [selectedAddon, setSelectedAddon] = React.useState(ALL_ADDONS_KEY);
Expand Down Expand Up @@ -105,6 +105,7 @@ const StreamsList = ({ className, ...props }) => {
{filteredStreams.map((stream, index) => (
<Stream
key={index}
videoId={video?.id}
addonName={stream.addonName}
name={stream.name}
description={stream.description}
Expand All @@ -119,15 +120,16 @@ const StreamsList = ({ className, ...props }) => {
}
<Button className={styles['install-button-container']} title={t('ADDON_CATALOGUE_MORE')} href={'#/addons'}>
<Icon className={styles['icon']} icon={'ic_addons'} />
<div className={styles['label']}>{ t('ADDON_CATALOGUE_MORE') }</div>
<div className={styles['label']}>{t('ADDON_CATALOGUE_MORE')}</div>
</Button>
</div>
);
};

StreamsList.propTypes = {
className: PropTypes.string,
streams: PropTypes.arrayOf(PropTypes.object).isRequired
streams: PropTypes.arrayOf(PropTypes.object).isRequired,
video: PropTypes.object
};

module.exports = StreamsList;