diff options
-rw-r--r-- | src/client/views/nodes/VideoBox.tsx | 2 | ||||
-rw-r--r-- | src/server/ApiManagers/UploadManager.ts | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/client/views/nodes/VideoBox.tsx b/src/client/views/nodes/VideoBox.tsx index a3abaedfa..6b1e6ae18 100644 --- a/src/client/views/nodes/VideoBox.tsx +++ b/src/client/views/nodes/VideoBox.tsx @@ -111,7 +111,7 @@ export class VideoBox extends ViewBoxAnnotatableComponent<FieldViewProps, VideoD this._videoRef && ctx.drawImage(this._videoRef, 0, 0, canvas.width, canvas.height); } - if (!this._videoRef) { // can't find a way to take snapshots of videos + if (!this._videoRef) { const b = Docs.Create.LabelDocument({ x: (this.layoutDoc.x || 0) + width, y: (this.layoutDoc.y || 1), _width: 150, _height: 50, title: (this.layoutDoc.currentTimecode || 0).toString(), diff --git a/src/server/ApiManagers/UploadManager.ts b/src/server/ApiManagers/UploadManager.ts index 60c52bcfc..756bde738 100644 --- a/src/server/ApiManagers/UploadManager.ts +++ b/src/server/ApiManagers/UploadManager.ts @@ -277,10 +277,12 @@ export default class UploadManager extends ApiManager { } } - +function delay(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); +} /** * On success, returns a buffer containing the bytes of a screenshot - * of the video specified by @param url at timecode @param t. + * of the video (optionally, at a timecode) specified by @param targetUrl. * * On failure, returns undefined. */ @@ -289,9 +291,15 @@ async function captureYoutubeScreenshot(targetUrl: string): Promise<Opt<Buffer>> const page = await browser.newPage(); await page.setViewport({ width: 1920, height: 1080 }); - await page.goto(targetUrl, { waitUntil: 'networkidle2' as any }); + await page.goto(targetUrl, { waitUntil: 'domcontentloaded' as any }); const videoPlayer = await page.$('.html5-video-player'); + videoPlayer && await page.focus("video"); + await delay(7000); + const ad = await page.$('.ytp-ad-skip-button-text'); + await ad?.click(); + await videoPlayer?.click(); + await delay(1000); // hide youtube player controls. await page.evaluate(() => (document.querySelector('.ytp-chrome-bottom') as any).style.display = 'none'); |