From a4bca8af456665a25c09ebfd60f552aa5623c77c Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Thu, 4 Jun 2020 21:51:22 +0200 Subject: [PATCH] =?UTF-8?q?Additional=20fixes=20for=20#101=20=E2=80=94=20i?= =?UTF-8?q?f=20illegal=20video=20dimensions=20are=20detected,=20tell=20Vid?= =?UTF-8?q?eoData=20to=20reset/reapply=20aspect=20ratio=20when=20video=20s?= =?UTF-8?q?tarts=20playing=20again?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ext/lib/video-data/VideoData.js | 25 +++++++++++++++++++++++- src/ext/lib/video-transform/Resizer.js | 27 ++++++-------------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/ext/lib/video-data/VideoData.js b/src/ext/lib/video-data/VideoData.js index 64e59e0..9c3f79c 100644 --- a/src/ext/lib/video-data/VideoData.js +++ b/src/ext/lib/video-data/VideoData.js @@ -20,6 +20,7 @@ class VideoData { this.userCssClassName = `uw-fuck-you-and-do-what-i-tell-you_${this.vdid}`; this.videoLoaded = false; + this.videoDimensionsLoaded = true; this.dimensions = { width: this.video.offsetWidth, @@ -34,7 +35,7 @@ class VideoData { // this one is in case extension loads after the video is loaded video.addEventListener('timeupdate', () => { - this.onVideoLoaded() + this.onVideoLoaded(); }); } @@ -43,12 +44,16 @@ class VideoData { this.logger.log('info', 'init', '%c[VideoData::onVideoLoaded] ——————————— Initiating phase two of videoData setup ———————————', 'color: #0f9'); this.videoLoaded = true; + this.videoDimensionsLoaded = true; try { await this.setupStageTwo(); this.logger.log('info', 'init', '%c[VideoData::onVideoLoaded] ——————————— videoData setup stage two complete ———————————', 'color: #0f9'); } catch (e) { this.logger.log('error', 'init', '%c[VideoData::onVideoLoaded] ——————————— Setup stage two failed. ———————————\n', 'color: #f00', e); } + } else if (!this.videoDimensionsLoaded) { + this.restoreCrop(); + this.videoDimensionsLoaded = true; } } @@ -115,6 +120,24 @@ class VideoData { } } + restoreCrop() { + this.logger.log('info', 'debug', "%c[VideoData::restoreCrop] Recovering from illegal video dimensions. Resetting aspect ratio.", {background: '#afd', color: '#132'}); + + // if we have default crop set for this page, apply this. + // otherwise, reset crop + if (this.pageInfo.defaultCrop) { + this.resizer.setAr(this.pageInfo.defaultCrop); + } else { + this.resizer.reset(); + + try { + this.startArDetection(); + } catch (e) { + this.logger.log('warn', 'debug', '[VideoData::restoreCrop] Autodetection not resumed. Reason:', e); + } + } + } + async fallbackChangeDetection() { while (!this.destroyed && !this.invalid) { await this.sleep(500); diff --git a/src/ext/lib/video-transform/Resizer.js b/src/ext/lib/video-transform/Resizer.js index 03d284b..7a5a6c6 100644 --- a/src/ext/lib/video-transform/Resizer.js +++ b/src/ext/lib/video-transform/Resizer.js @@ -267,28 +267,13 @@ class Resizer { return; } - // we could have issued calculate crop too early. Instead of spending 30 minutes trying to fix this the proper way by - // reading documentation, let's fix it in 30 seconds with some brute force code + // we could have issued calculate crop too early. Let's tell VideoData that there's something wrong + // and exit this function. When