From 6a6afa1f9633d7e72e21056649f58d873e25cc41 Mon Sep 17 00:00:00 2001 From: Alin Date: Fri, 17 Feb 2023 12:21:15 +0000 Subject: [PATCH] show "Next up" in related. --- src/components/VideoPlayer.vue | 53 ++++------------------------ src/components/WatchVideo.vue | 63 +++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 48 deletions(-) diff --git a/src/components/VideoPlayer.vue b/src/components/VideoPlayer.vue index 51fd2c30..dd2ac583 100644 --- a/src/components/VideoPlayer.vue +++ b/src/components/VideoPlayer.vue @@ -38,6 +38,12 @@ export default { return {}; }, }, + nextVideo: { + type: Object, + default: () => { + return {}; + }, + }, playlist: { type: Object, default: null, @@ -63,16 +69,12 @@ export default { initialSeekComplete: false, destroying: false, inSegment: false, - nextVideo: null, }; }, computed: { shouldAutoPlay: _this => { return _this.getPreferenceBoolean("playerAutoPlay", true) && !_this.isEmbed; }, - priorityAutoPlay: _this => { - return _this.getPreferenceBoolean("priorityAutoPlay", true) && !_this.isEmbed; - }, preferredVideoCodecs: _this => { var preferredVideoCodecs = []; const enabledCodecs = _this.getPreferenceString("enabledCodecs", "vp9,avc").split(","); @@ -408,9 +410,6 @@ export default { } }); } - if (this.priorityAutoPlay) { - this.setNextVideo(); - } //TODO: Add sponsors on seekbar: https://github.com/ajayyy/SponsorBlock/blob/e39de9fd852adb9196e0358ed827ad38d9933e29/src/js-components/previewBar.ts#L12 }, @@ -616,46 +615,6 @@ export default { this.$refs.videoEl.currentTime = time; } }, - async getWatchedRelatedVideos() { - var tx = window.db.transaction("watch_history", "readwrite"); - var store = tx.objectStore("watch_history"); - const results = []; - for (let i = 0; i < this.video.relatedStreams.length; i++) { - const video = this.video.relatedStreams[i]; - const id = video.url.replace("/watch?v=", ""); - const request = store.get(id); - results.push(request); - } - const data = results.map(result => { - return new Promise(resolve => { - result.onsuccess = function (event) { - const video = event.target.result; - resolve(video); - }; - result.onerror = function () { - resolve(null); - }; - }); - }); - return Promise.all(data); - }, - async setNextVideo() { - const data = (await this.getWatchedRelatedVideos()).filter(video => video); - for (let i = 0; i < this.video.relatedStreams.length; i++) { - const video = this.video.relatedStreams[i]; - const id = video.url.replace("/watch?v=", ""); - const watched = data.find(video => video.videoId === id); - if (!watched) { - if (video.uploaderUrl === this.video.uploaderUrl) { - this.nextVideo = video; - return; - } - this.nextVideo = video; - return; - } - this.nextVideo = this.video.relatedStreams[0]; - } - }, navigateNext() { const params = this.$route.query; const relatedUrl = this.nextVideo?.url ?? this.video.relatedStreams[0].url; diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue index 0f7c5d6a..e9398c29 100644 --- a/src/components/WatchVideo.vue +++ b/src/components/WatchVideo.vue @@ -20,6 +20,7 @@
+
+

Next up:

+ +
{ + return _this.video.relatedStreams?.filter(video => video.url !== _this.nextVideo?.url); + }, + priorityAutoPlay: _this => { + return _this.getPreferenceBoolean("priorityAutoPlay", true) && !_this.isEmbed; + }, }, mounted() { // check screen size @@ -422,6 +436,9 @@ export default { }); xmlDoc.querySelectorAll("br").forEach(elem => (elem.outerHTML = "\n")); this.video.description = this.rewriteDescription(xmlDoc.querySelector("body").innerHTML); + if (this.priorityAutoPlay) { + this.setNextVideo(); + } } }); }, @@ -556,6 +573,50 @@ export default { onTimeUpdate(time) { this.currentTime = time; }, + async getWatchedRelatedVideos() { + var tx = window.db.transaction("watch_history", "readwrite"); + var store = tx.objectStore("watch_history"); + const results = []; + for (let i = 0; i < this.video.relatedStreams.length; i++) { + const video = this.video.relatedStreams[i]; + const id = video.url.replace("/watch?v=", ""); + const request = store.get(id); + results.push(request); + } + const data = results.map(result => { + return new Promise(resolve => { + result.onsuccess = function (event) { + const video = event.target.result; + resolve(video); + }; + result.onerror = function () { + resolve(null); + }; + }); + }); + return Promise.all(data); + }, + async setNextVideo() { + const data = (await this.getWatchedRelatedVideos()).filter(video => video); + for (let i = 0; i < this.video.relatedStreams.length; i++) { + let foundAuthorMatch = false; + const video = this.video.relatedStreams[i]; + const id = video.url.replace("/watch?v=", ""); + const watched = data.find(video => video.videoId === id); + if (!watched) { + if (video.uploaderUrl === this.video.uploaderUrl) { + this.nextVideo = video; + foundAuthorMatch = true; + break; + } else if (!foundAuthorMatch) { + this.nextVideo = video; + } + } + if (!this.nextVideo) { + this.nextVideo = this.video.relatedStreams[0]; + } + } + }, }, };