Skip to content

Commit 7cd86cb

Browse files
kommunarrOothecaPickle
authored andcommitted
Autoplay time limit (FreeTubeApp#5871)
* Implement timer for next video to not play automatically * Update implementation to block next video autoplay i.e., instead of 'start video automatically' autoplay * Update variable name and add keyboard handling for ending timeout * Change autoplay timeout message to be more descriptive, and increase duration to 1 hr
1 parent ee1300d commit 7cd86cb

File tree

6 files changed

+59
-11
lines changed

6 files changed

+59
-11
lines changed

src/renderer/components/ft-shaka-video-player/ft-shaka-video-player.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export default defineComponent({
122122
vrProjection: {
123123
type: String,
124124
default: null
125-
}
125+
},
126126
},
127127
emits: [
128128
'error',

src/renderer/components/player-settings/player-settings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ export default defineComponent({
9595
return this.backendPreference !== 'invidious' && !this.backendFallback
9696
},
9797

98+
defaultAutoplayInterruptionIntervalHours: function () {
99+
return parseInt(this.$store.getters.getDefaultAutoplayInterruptionIntervalHours)
100+
},
101+
98102
defaultSkipInterval: function () {
99103
return parseInt(this.$store.getters.getDefaultSkipInterval)
100104
},
@@ -286,6 +290,7 @@ export default defineComponent({
286290
...mapActions([
287291
'updateAutoplayVideos',
288292
'updateAutoplayPlaylists',
293+
'updateDefaultAutoplayInterruptionIntervalHours',
289294
'updatePlayNextVideo',
290295
'updateEnableSubtitlesByDefault',
291296
'updateProxyVideos',

src/renderer/components/player-settings/player-settings.vue

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,6 @@
8282
</div>
8383
</div>
8484
<ft-flex-box>
85-
<ft-slider
86-
:label="$t('Settings.Player Settings.Fast-Forward / Rewind Interval')"
87-
:default-value="defaultSkipInterval"
88-
:min-value="1"
89-
:max-value="70"
90-
:step="1"
91-
value-extension="s"
92-
@change="updateDefaultSkipInterval"
93-
/>
9485
<ft-slider
9586
:label="$t('Settings.Player Settings.Next Video Interval')"
9687
:default-value="defaultInterval"
@@ -100,6 +91,24 @@
10091
value-extension="s"
10192
@change="updateDefaultInterval"
10293
/>
94+
<ft-slider
95+
:label="$t('Settings.Player Settings.Autoplay Interruption Timer')"
96+
:default-value="defaultAutoplayInterruptionIntervalHours"
97+
:min-value="1"
98+
:max-value="12"
99+
:step="1"
100+
value-extension="h"
101+
@change="updateDefaultAutoplayInterruptionIntervalHours"
102+
/>
103+
<ft-slider
104+
:label="$t('Settings.Player Settings.Fast-Forward / Rewind Interval')"
105+
:default-value="defaultSkipInterval"
106+
:min-value="1"
107+
:max-value="70"
108+
:step="1"
109+
value-extension="s"
110+
@change="updateDefaultSkipInterval"
111+
/>
103112
<ft-slider
104113
:label="$t('Settings.Player Settings.Default Volume')"
105114
:default-value="defaultVolume"

src/renderer/store/modules/settings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ const state = {
172172
baseTheme: 'system',
173173
mainColor: 'Red',
174174
secColor: 'Blue',
175+
defaultAutoplayInterruptionIntervalHours: 3,
175176
defaultCaptionSettings: '{}',
176177
defaultInterval: 5,
177178
defaultPlayback: 1,

src/renderer/views/Watch/Watch.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export default defineComponent({
5757
beforeRouteLeave: async function (to, from, next) {
5858
this.handleRouteChange()
5959
window.removeEventListener('beforeunload', this.handleWatchProgress)
60+
document.removeEventListener('keydown', this.resetAutoplayInterruptionTimeout)
61+
document.removeEventListener('click', this.resetAutoplayInterruptionTimeout)
6062

6163
if (this.$refs.player) {
6264
await this.$refs.player.destroyPlayer()
@@ -119,6 +121,8 @@ export default defineComponent({
119121
playNextTimeout: null,
120122
playNextCountDownIntervalId: null,
121123
infoAreaSticky: true,
124+
blockVideoAutoplay: false,
125+
autoplayInterruptionTimeout: null,
122126

123127
onMountedRun: false,
124128

@@ -160,6 +164,9 @@ export default defineComponent({
160164
proxyVideos: function () {
161165
return this.$store.getters.getProxyVideos
162166
},
167+
defaultAutoplayInterruptionIntervalHours: function () {
168+
return this.$store.getters.getDefaultAutoplayInterruptionIntervalHours
169+
},
163170
defaultInterval: function () {
164171
return this.$store.getters.getDefaultInterval
165172
},
@@ -321,7 +328,13 @@ export default defineComponent({
321328
this.getVideoInformationLocal()
322329
}
323330

331+
document.removeEventListener('keydown', this.resetAutoplayInterruptionTimeout)
332+
document.removeEventListener('click', this.resetAutoplayInterruptionTimeout)
333+
document.addEventListener('keydown', this.resetAutoplayInterruptionTimeout)
334+
document.addEventListener('click', this.resetAutoplayInterruptionTimeout)
335+
324336
window.addEventListener('beforeunload', this.handleWatchProgress)
337+
this.resetAutoplayInterruptionTimeout()
325338
},
326339

327340
changeTimestamp: function (timestamp) {
@@ -1233,6 +1246,18 @@ export default defineComponent({
12331246
return
12341247
}
12351248

1249+
if (this.blockVideoAutoplay) {
1250+
showToast(this.$t('Autoplay Interruption Timer',
1251+
this.defaultAutoplayInterruptionIntervalHours,
1252+
{
1253+
autoplayInterruptionIntervalHours: this.defaultAutoplayInterruptionIntervalHours
1254+
}),
1255+
3_600_000
1256+
)
1257+
this.resetAutoplayInterruptionTimeout()
1258+
return
1259+
}
1260+
12361261
if (this.watchingPlaylist && this.getPlaylistPauseOnCurrent()) {
12371262
this.disablePlaylistPauseOnCurrent()
12381263
return
@@ -1639,6 +1664,12 @@ export default defineComponent({
16391664
this.updatePlaylistLastPlayedAt({ _id: playlist._id })
16401665
},
16411666

1667+
resetAutoplayInterruptionTimeout() {
1668+
clearTimeout(this.autoplayInterruptionTimeout)
1669+
this.autoplayInterruptionTimeout = setTimeout(() => { this.blockVideoAutoplay = true }, this.defaultAutoplayInterruptionIntervalHours * 3_600_000)
1670+
this.blockVideoAutoplay = false
1671+
},
1672+
16421673
...mapActions([
16431674
'updateHistory',
16441675
'updateWatchProgress',

static/locales/en-US.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ Settings:
415415
Skip by Scrolling Over Video Player: Skip by Scrolling Over Video Player
416416
Display Play Button In Video Player: Display Play Button In Video Player
417417
Enter Fullscreen on Display Rotate: Enter Fullscreen on Display Rotate
418-
Next Video Interval: Next Video Interval
418+
Next Video Interval: Autoplay Countdown Timer
419+
Autoplay Interruption Timer: Autoplay Interruption Timer
419420
Fast-Forward / Rewind Interval: Fast-Forward / Rewind Interval
420421
Default Volume: Default Volume
421422
Default Playback Rate: Default Playback Rate
@@ -1078,6 +1079,7 @@ Playlist will not pause when current video is finished: Playlist will not pause
10781079
Playlist will pause when current video is finished: Playlist will pause when current video is finished
10791080
Playing Next Video Interval: Playing next video in no time. Click to cancel. | Playing next video in {nextVideoInterval} second. Click to cancel. | Playing next video in {nextVideoInterval} seconds. Click to cancel.
10801081
Canceled next video autoplay: Canceled next video autoplay
1082+
Autoplay Interruption Timer: Autoplay canceled due to {autoplayInterruptionIntervalHours} hours of inactivity
10811083

10821084
Default Invidious instance has been set to {instance}: Default Invidious instance has been set to {instance}
10831085
Default Invidious instance has been cleared: Default Invidious instance has been cleared

0 commit comments

Comments
 (0)