Skip to content

Conversation

@goestav
Copy link

@goestav goestav commented Nov 7, 2025

This pull request marks videos as watched after watching them for a given amount of time if JavaScript is enabled and also indirectly fixes a bug that prevents YouTube/Invidious links from updating when seeking backwards for the video.

Closes #3794

@goestav goestav marked this pull request as ready for review November 7, 2025 19:24
@goestav goestav requested a review from SamantazFox as a code owner November 7, 2025 19:24
@unixfox unixfox requested a review from Copilot November 13, 2025 16:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a feature to automatically mark videos as watched after the user has watched them for at least 30 seconds (or fully for videos shorter than 30 seconds). The feature is opt-in via a new user preference and uses client-side tracking to determine when to mark videos as watched. It also removes the previous server-side logic that marked videos as watched upon navigation to a video page, and fixes a bug preventing YouTube/Invidious link updates when seeking backwards.

Key changes:

  • Added mark_watched_after_duration preference with default value of false to avoid confusion for existing users
  • Implemented client-side tracking in player.js to monitor watch time and trigger mark-as-watched after thresholds are met
  • Removed automatic server-side marking of videos as watched on page load

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/invidious/config.cr Added mark_watched_after_duration property to default preferences config
src/invidious/user/preferences.cr Added mark_watched_after_duration property to user preferences struct
src/invidious/videos/video_preferences.cr Added processing and handling of mark_watched_after_duration parameter in video preferences
src/invidious/routes/preferences.cr Added route handling to save the mark_watched_after_duration preference from form submission
src/invidious/routes/watch.cr Removed server-side logic that automatically marked videos as watched on page navigation
src/invidious/views/user/preferences.ecr Added checkbox UI for the new preference in the preferences page
src/invidious/views/template.ecr Added hidden span to expose the preference value to client-side JavaScript (only for logged-in users)
locales/en-US.json Added English translation for the preference label
assets/js/player.js Implemented client-side watch time tracking and auto-mark-as-watched logic, also fixed backward seeking bug
Comments suppressed due to low confidence (1)

assets/js/player.js:210

  • Avoid automated semicolon insertion (93% of all statements in the enclosing function have an explicit semicolon).
    time_watched += 1

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@unixfox
Copy link
Member

unixfox commented Nov 13, 2025

It also removes the previous server-side logic that marked videos as watched upon navigation to a video page

I don't think that's a good thing because we still want to support non js users as long as possible.

@goestav
Copy link
Author

goestav commented Nov 13, 2025

Apologies, that was supposed to be ignored only if this feature is enabled.

- if watched && preferences.watch_history
+ if watched && preferences.watch_history && !preferences.mark_watched_after_duration
  Invidious::Database::Users.mark_watched(user.as(User), id)
end

It should probably be mentioned under the checkbox in the preference page that the feature requires JavaScript though.
What do you think?

@SamantazFox
Copy link
Member

It also removes the previous server-side logic that marked videos as watched upon navigation to a video page

I don't think that's a good thing because we still want to support non js users as long as possible.

We can do that, without the need for a config option.

The simplest way would be to add an extra URL query parameter (like mark_watched=0) using JS to all links that go the the /watch page when clicked, so that the backend knows that is shouldn't mark a video as watched when loading the page.

Then the front-end JS will call the right endpoint after the video passes the 5s mark.

For non-JS users, it has no impact, as if the query parameter is absent, it continues to do as it did in the past.

@goestav goestav force-pushed the feat/mark-watched-after-duration branch from 004ed27 to d999c50 Compare December 6, 2025 22:13
@goestav
Copy link
Author

goestav commented Dec 10, 2025

I think this PR is ready now, I implemented @SamantazFox's suggestion.
I can rebase if necessary.

@goestav
Copy link
Author

goestav commented Jan 10, 2026

@SamantazFox or @unixfox could either of you review/merge this PR please?

@unixfox unixfox added the need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something label Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Mark as watched after certain amount of time

3 participants