From 2025547d3375d964da487ddf45b55901b4a8c62d Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Tue, 12 Jan 2021 23:28:17 +0100 Subject: [PATCH] Un-initalize videoData on illegal video dimensions ($ When youtube changes between two videos, video dimensions briefly become 0x0. This is super duper illegal and sometimes causes the behaviour described in issue #125. Setting VideoData.videoLoaded to false fixes this. --- src/ext/lib/video-data/VideoData.js | 7 +++++++ src/ext/lib/video-transform/Resizer.js | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ext/lib/video-data/VideoData.js b/src/ext/lib/video-data/VideoData.js index 19f6e40..f0252c9 100644 --- a/src/ext/lib/video-data/VideoData.js +++ b/src/ext/lib/video-data/VideoData.js @@ -33,6 +33,9 @@ class VideoData { async onVideoLoaded() { if (!this.videoLoaded) { + if (this.video.videoWidth && this.video.videoHeight) { + return; // onVideoLoaded is a lie in this case + } this.logger.log('info', 'init', '%c[VideoData::onVideoLoaded] ——————————— Initiating phase two of videoData setup ———————————', 'color: #0f9'); this.videoLoaded = true; @@ -52,6 +55,10 @@ class VideoData { } } + videoUnloaded() { + this.videoLoaded = false; + } + async injectBaseCss() { try { await this.pageInfo.injectCss(` diff --git a/src/ext/lib/video-transform/Resizer.js b/src/ext/lib/video-transform/Resizer.js index 7a5ec8f..6b056eb 100644 --- a/src/ext/lib/video-transform/Resizer.js +++ b/src/ext/lib/video-transform/Resizer.js @@ -146,7 +146,8 @@ class Resizer { } if (!this.video.videoWidth || !this.video.videoHeight) { - this.logger.log('warning', 'debug', '[Resizer::setAr] Video has no width or no height. This is not allowed. Aspect ratio will not be set.'); + this.logger.log('warning', 'debug', '[Resizer::setAr] Video has no width or no height. This is not allowed. Aspect ratio will not be set, and videoData will be uninitialized.'); + this.conf.videoUnloaded(); } this.logger.log('info', 'debug', '[Resizer::setAr] trying to set ar. New ar:', ar)