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

feat: add autoplay next #114

Merged
merged 1 commit into from
Aug 1, 2024
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/modules/storeVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const STORE = new Store();

export const setDefaultStoreVariables = () => {
if (!STORE.has('update_progress')) STORE.set('update_progress', false);
if (!STORE.has('autoplay_next')) STORE.set('autoplay_next', true);
if (!STORE.has('dubbed')) STORE.set('dubbed', false);
if (!STORE.has('source_flag')) STORE.set('source_flag', 'US');
if (!STORE.has('intro_skip_time')) STORE.set('intro_skip_time', 85);
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/components/player/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
}, 7500);
};

const handleVideoEnd = () => {
if ((STORE.get('autoplay_next') as boolean) === true) {
canNextEpisode(episodeNumber) &&
changeEpisode(episodeNumber + 1);
};
};

const handleMouseMove = () => {
clearTimeout(pauseInfoTimer);
setShowPauseInfo(false);
Expand Down Expand Up @@ -580,6 +587,7 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
onKeyDown={handleKeydown}
onTimeUpdate={handleTimeUpdate}
onPause={handleVideoPause}
onEnded={handleVideoEnd}
crossOrigin="anonymous"
></video>
</div>
Expand Down
23 changes: 23 additions & 0 deletions src/renderer/components/player/VideoSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
faHeadphones,
faLanguage,
faRotateRight,
faRightLong,
faSpinner,
faVideo,
faVolumeHigh,
Expand Down Expand Up @@ -46,6 +47,9 @@ const VideoSettings: React.FC<SettingsProps> = ({
const [updateProgress, setUpdateProgress] = useState<boolean>(
STORE.get('update_progress') as boolean,
);
const [autoplayNext, setAutoplayNext] = useState<boolean>(
STORE.get('autoplay_next') as boolean,
);
const [watchDubbed, setWatchDubbed] = useState<boolean>(
STORE.get('dubbed') as boolean,
);
Expand Down Expand Up @@ -135,6 +139,11 @@ const VideoSettings: React.FC<SettingsProps> = ({
setUpdateProgress(!updateProgress);
};

const handleAutoplayNext = () => {
STORE.set('autoplay_next', !autoplayNext);
setAutoplayNext(!autoplayNext);
};

const handleWatchDubbedChange = async () => {
const previous = STORE.get('dubbed');
STORE.set('dubbed', !watchDubbed);
Expand Down Expand Up @@ -295,6 +304,20 @@ const VideoSettings: React.FC<SettingsProps> = ({
</label>
)}
</li>
<li className="autoplay-next">
<span>
<FontAwesomeIcon className="i" icon={faRightLong} />
Autoplay Next
</span>
<label className="switch">
<input
type="checkbox"
checked={autoplayNext}
onChange={handleAutoplayNext}
/>
<span className="slider round"></span>
</label>
</li>
<li className="language">
<span>
<FontAwesomeIcon className="i" icon={faLanguage} />
Expand Down
13 changes: 13 additions & 0 deletions src/renderer/tabs/Tab4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ const Tab4: React.FC = () => {
const [updateProgress, setUpdateProgress] = useState<boolean>(
STORE.get('update_progress') as boolean,
);
const [autoplayNext, setAutoplayNext] = useState<boolean>(
STORE.get('autoplay_next') as boolean,
);
const [watchDubbed, setWatchDubbed] = useState<boolean>(
STORE.get('dubbed') as boolean,
);
Expand Down Expand Up @@ -126,6 +129,11 @@ const Tab4: React.FC = () => {
setShowDuration(!showDuration);
};

const handleAutoplayNextChange = () => {
STORE.set('autoplay_next', !autoplayNext);
setAutoplayNext(!autoplayNext);
};

const languageOptions: Option[] = [
{ value: 'US', label: 'English' },
{ value: 'IT', label: 'Italian' },
Expand Down Expand Up @@ -160,6 +168,11 @@ const Tab4: React.FC = () => {
checked={watchDubbed}
onChange={handleWatchDubbedChange}
/>
<CheckboxElement
label="Autoplay next episode"
checked={autoplayNext}
onChange={handleAutoplayNextChange}
/>
<SelectElement
label="Select the language in which you want to watch the episodes"
value={selectedLanguage}
Expand Down