1
0
mirror of https://github.com/TeamPiped/Piped.git synced 2024-12-13 13:50:27 +05:30

Add support for storing and loading video watched times.

Closes #373
This commit is contained in:
FireMaskterK 2021-10-27 01:15:37 +01:00
parent 6ee9592218
commit 993fb15397
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
2 changed files with 36 additions and 2 deletions

View File

@ -31,6 +31,7 @@ export default {
return {}; return {};
}, },
}, },
videoId: String,
sponsors: { sponsors: {
type: Object, type: Object,
default: () => { default: () => {
@ -45,6 +46,7 @@ export default {
return { return {
$player: null, $player: null,
$ui: null, $ui: null,
lastUpdate: new Date().getTime(),
}; };
}, },
computed: { computed: {
@ -138,7 +140,19 @@ export default {
videoEl.setAttribute("poster", this.video.thumbnailUrl); videoEl.setAttribute("poster", this.video.thumbnailUrl);
if (this.$route.query.t) videoEl.currentTime = this.$route.query.t; if (this.$route.query.t) {
videoEl.currentTime = this.$route.query.t;
} else {
var tx = window.db.transaction("watch_history", "readonly");
var store = tx.objectStore("watch_history");
var request = store.get(this.videoId);
request.onsuccess = function(event) {
var video = event.target.result;
if (video && video.currentTime) {
videoEl.currentTime = video.currentTime;
}
};
}
const noPrevPlayer = !this.$player; const noPrevPlayer = !this.$player;
@ -226,8 +240,9 @@ export default {
if (noPrevPlayer) { if (noPrevPlayer) {
videoEl.addEventListener("timeupdate", () => { videoEl.addEventListener("timeupdate", () => {
const time = videoEl.currentTime;
this.updateProgressDatabase(time);
if (this.sponsors && this.sponsors.segments) { if (this.sponsors && this.sponsors.segments) {
const time = videoEl.currentTime;
this.sponsors.segments.map(segment => { this.sponsors.segments.map(segment => {
if (!segment.skipped || this.selectedAutoLoop) { if (!segment.skipped || this.selectedAutoLoop) {
const end = segment.segment[1]; const end = segment.segment[1];
@ -339,6 +354,24 @@ export default {
player.trickPlay(this.getPreferenceNumber("rate", 1)); player.trickPlay(this.getPreferenceNumber("rate", 1));
}); });
}, },
async updateProgressDatabase(time) {
// debounce
if (new Date().getTime() - this.lastUpdate < 500) return;
this.lastUpdate = new Date().getTime();
if (!this.videoId) return;
var tx = window.db.transaction("watch_history", "readwrite");
var store = tx.objectStore("watch_history");
var request = store.get(this.videoId);
request.onsuccess = function(event) {
var video = event.target.result;
if (video) {
video.currentTime = time;
store.put(video);
}
};
},
destroy() { destroy() {
if (this.$ui) { if (this.$ui) {
this.$ui.destroy(); this.$ui.destroy();

View File

@ -17,6 +17,7 @@
<Player <Player
ref="videoPlayer" ref="videoPlayer"
:video="video" :video="video"
:video-id="getVideoId()"
:sponsors="sponsors" :sponsors="sponsors"
:selected-auto-play="selectedAutoPlay" :selected-auto-play="selectedAutoPlay"
:selected-auto-loop="selectedAutoLoop" :selected-auto-loop="selectedAutoLoop"