mirror of
				https://github.com/TeamPiped/Piped.git
				synced 2024-08-14 23:57:27 +00:00 
			
		
		
		
	
							parent
							
								
									6ee9592218
								
							
						
					
					
						commit
						993fb15397
					
				
					 2 changed files with 36 additions and 2 deletions
				
			
		| 
						 | 
					@ -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", () => {
 | 
				
			||||||
                    if (this.sponsors && this.sponsors.segments) {
 | 
					 | 
				
			||||||
                    const time = videoEl.currentTime;
 | 
					                    const time = videoEl.currentTime;
 | 
				
			||||||
 | 
					                    this.updateProgressDatabase(time);
 | 
				
			||||||
 | 
					                    if (this.sponsors && this.sponsors.segments) {
 | 
				
			||||||
                        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();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue