From 75e4d6b376ae6d9a0c74b945c30b121a7d3cf34c Mon Sep 17 00:00:00 2001 From: SReject Date: Thu, 7 Dec 2023 12:03:10 -0500 Subject: [PATCH 1/5] fix: non existent var preventing UI from loading --- src/backend/chat/commands/command-access.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/backend/chat/commands/command-access.js b/src/backend/chat/commands/command-access.js index a59bcf98c..39f2536a4 100644 --- a/src/backend/chat/commands/command-access.js +++ b/src/backend/chat/commands/command-access.js @@ -49,11 +49,8 @@ function refreshCommandCache(retry = 1) { try { cmdData = commandsDb.getData("/"); } catch (err) { - logger.info( - "Command cache update failed. Retrying. (Try " + retry + "/3)" - ); - retry = retry + 1; - logger.error("error getting command data", err); + logger.info("Command cache update failed. Retrying. (Try " + retry + "/3)"); + retry += 1; refreshCommandCache(retry); return; } @@ -72,11 +69,9 @@ function refreshCommandCache(retry = 1) { } logger.info("Updated Command cache."); + } else { - renderWindow.webContents.send( - "error", - "Could not sync up command cache. Reconnect to try resyncing." - ); + logger.error("Could not sync up command cache. Reconnect to try resyncing."); } } } @@ -124,7 +119,7 @@ function deleteCustomCommand(commandId) { try { commandDb.delete("/customCommands/" + commandId); } catch (err) { - logger.warn("error when deleting command", err); + logger.warn("error when deleting command", err.message); } } From e8135900254525ee91b6ccb4068ab1fc7d93a108 Mon Sep 17 00:00:00 2001 From: SReject Date: Thu, 7 Dec 2023 12:20:56 -0500 Subject: [PATCH 2/5] revert: youtube play duration --- src/backend/effects/builtin/play-video.js | 27 ++++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/backend/effects/builtin/play-video.js b/src/backend/effects/builtin/play-video.js index e6bc7ac99..ee5187b4a 100644 --- a/src/backend/effects/builtin/play-video.js +++ b/src/backend/effects/builtin/play-video.js @@ -443,24 +443,29 @@ const playVideo = { let resourceToken; let duration; + if (effect.videoType === "YouTube Video") { const youtubeData = parseYoutubeId(data.youtubeId); data.youtubeId = youtubeData.id; - if (data.videoStarttime == null || data.videoStarttime == "" || data.videoStarttime == 0) { + + if (data.videoStarttime == null || data.videoStarttime === "" || data.videoStarttime === 0) { data.videoStarttime = youtubeData.startTime; } - } - if (effect.videoType === "YouTube Video" && !effect.wait) { - logger.debug("Play Video Effect: Proceeding without Youtube Video Duration because wait is false"); - } else if (effect.videoType === "YouTube Video" && effect.wait) { - const result = await frontendCommunicator.fireEventAsync("getYoutubeVideoDuration", data.youtubeId); - if (!isNaN(result)) { - duration = result; + + if (effect.wait) { + const result = await frontendCommunicator.fireEventAsync("getYoutubeVideoDuration", data.youtubeId); + if (!isNaN(result)) { + duration = result; + + } else { + // Error + logger.error("Play Video Effect: Unable to retrieve Youtube Video Duration", result); + return; + } } else { - // Error - logger.error("Play Video Effect: Unable to retrieve Youtube Video Duration", result); - return; + logger.debug("Play Video Effect: Proceeding without Youtube Video Duration because wait is false"); } + } else if (effect.videoType === "Local Video" || effect.videoType === "Random From Folder") { const result = await frontendCommunicator.fireEventAsync("getVideoDuration", data.filepath); if (!isNaN(result)) { From 5b9611bcdec4a72719e81e78f23f8cbb31f05c17 Mon Sep 17 00:00:00 2001 From: SReject Date: Thu, 7 Dec 2023 12:22:40 -0500 Subject: [PATCH 3/5] feat: better logging for youtube effect --- src/backend/effects/builtin/play-video.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/backend/effects/builtin/play-video.js b/src/backend/effects/builtin/play-video.js index ee5187b4a..7a9ce81f2 100644 --- a/src/backend/effects/builtin/play-video.js +++ b/src/backend/effects/builtin/play-video.js @@ -453,15 +453,20 @@ const playVideo = { } if (effect.wait) { - const result = await frontendCommunicator.fireEventAsync("getYoutubeVideoDuration", data.youtubeId); - if (!isNaN(result)) { - duration = result; - - } else { - // Error - logger.error("Play Video Effect: Unable to retrieve Youtube Video Duration", result); - return; + try { + const result = await frontendCommunicator.fireEventAsync("getYoutubeVideoDuration", data.youtubeId); + if (!isNaN(result)) { + duration = result; + + } else { + // Error + logger.error("Play Video Effect: Unable to retrieve Youtube Video Duration", result); + return; + } + } catch (err) { + logger.error("Play Video Effect: Unable to retrieve Youtube Video Duration", err.message); } + } else { logger.debug("Play Video Effect: Proceeding without Youtube Video Duration because wait is false"); } From aa0dc77f5745d4dfdce471aa2d67a89664bffddf Mon Sep 17 00:00:00 2001 From: Dennis Rijsdijk <70665154+dennisrijsdijk@users.noreply.github.com> Date: Sat, 9 Dec 2023 14:46:54 +0100 Subject: [PATCH 4/5] revert: youtube duration changes (#2282) --- src/backend/effects/builtin/play-video.js | 79 ++++++++++++++----- .../variables/builtin-variable-loader.js | 3 +- .../builtin/youtube-video-duration.js | 30 ------- src/gui/app/index.html | 2 - src/gui/app/services/video.service.js | 46 ----------- 5 files changed, 60 insertions(+), 100 deletions(-) delete mode 100644 src/backend/variables/builtin/youtube-video-duration.js diff --git a/src/backend/effects/builtin/play-video.js b/src/backend/effects/builtin/play-video.js index 7a9ce81f2..0c1662f36 100644 --- a/src/backend/effects/builtin/play-video.js +++ b/src/backend/effects/builtin/play-video.js @@ -13,6 +13,7 @@ const path = require("path"); const frontendCommunicator = require('../../common/frontend-communicator'); const { wait } = require("../../utility"); const { parseYoutubeId } = require("../../../shared/youtube-url-parser"); +const uuid = require("uuid"); /** * The Play Video effect @@ -452,24 +453,7 @@ const playVideo = { data.videoStarttime = youtubeData.startTime; } - if (effect.wait) { - try { - const result = await frontendCommunicator.fireEventAsync("getYoutubeVideoDuration", data.youtubeId); - if (!isNaN(result)) { - duration = result; - - } else { - // Error - logger.error("Play Video Effect: Unable to retrieve Youtube Video Duration", result); - return; - } - } catch (err) { - logger.error("Play Video Effect: Unable to retrieve Youtube Video Duration", err.message); - } - - } else { - logger.debug("Play Video Effect: Proceeding without Youtube Video Duration because wait is false"); - } + resourceToken = uuid(); } else if (effect.videoType === "Local Video" || effect.videoType === "Random From Folder") { const result = await frontendCommunicator.fireEventAsync("getVideoDuration", data.filepath); @@ -478,14 +462,52 @@ const playVideo = { } resourceToken = resourceTokenManager.storeResourcePath(data.filepath, duration); } - if ((data.videoDuration == null || data.videoDuration == "" || data.videoDuration == 0) && duration != null) { + if ((data.videoDuration == null || data.videoDuration === "" || data.videoDuration === 0) && duration != null) { data.videoDuration = duration; } data.resourceToken = resourceToken; + let waitPromise; + + if (effect.wait) { + if (effect.videoType === "YouTube Video") { + + let overlayTimeout; + waitPromise = new Promise((resolve, reject) => { + function callbackAvailable({name}) { + if (name === `play-video:callback:available:${resourceToken}`) { + clearTimeout(overlayTimeout); + webServer.off("overlay-event", callbackAvailable); + } + } + + function callbackDuration({name, data}) { + if (name === `play-video:callback:duration:${resourceToken}`) { + webServer.off("overlay-event", callbackDuration); + wait(data.duration).then(resolve); + } + } + + overlayTimeout = setTimeout(() => { + webServer.off("overlay-event", callbackAvailable); + webServer.off("overlay-event", callbackDuration); + reject(); + }, 2500); + webServer.on("overlay-event", callbackAvailable); + webServer.on("overlay-event", callbackDuration); + }); + } else { + waitPromise = wait(data.videoDuration * 1000); + } + } + webServer.sendToOverlay("video", data); if (effect.wait) { - await wait(data.videoDuration * 1000); + try { + await waitPromise; + } catch (error) { + return false; + } } return true; }, @@ -506,6 +528,11 @@ const playVideo = { startedVidCache = {}; // eslint-disable-line no-undef } + if (event.videoType === "YouTube Video") { + // eslint-disable-next-line no-undef + sendWebsocketEvent(`play-video:callback:available:${event.resourceToken}`); + } + function animateVideoExit(idString, animation, duration, inbetweenAnimation) { if (inbetweenAnimation) { $(idString).find(".inner-position").css("animation-duration", ""); @@ -702,10 +729,22 @@ const playVideo = { event.target.setVolume(parseInt(videoVolume) * 10); event.target.playVideo(); + if (event.target.getDuration() === 0) { // Error state + // eslint-disable-next-line no-undef + sendWebsocketEvent(`play-video:callback:duration:${data.resourceToken}`, {duration: 0}); + } else if (videoDuration) { + // eslint-disable-next-line no-undef + sendWebsocketEvent(`play-video:callback:duration:${data.resourceToken}`, {duration: videoDuration}); + } else { + // eslint-disable-next-line no-undef + sendWebsocketEvent(`play-video:callback:duration:${data.resourceToken}`, {duration: (event.target.getDuration() - parseInt(videoStarttime)) * 1000}); + } + $(`#${ytPlayerId}`).show(); }, onError: (event) => { console.log(event); + animateVideoExit(`#${wrapperId}`, exitAnimation, exitDuration, inbetweenAnimation); }, onStateChange: (event) => { if (event.data === 0 && !videoDuration) { diff --git a/src/backend/variables/builtin-variable-loader.js b/src/backend/variables/builtin-variable-loader.js index 37a50a7fd..23009f586 100644 --- a/src/backend/variables/builtin-variable-loader.js +++ b/src/backend/variables/builtin-variable-loader.js @@ -208,8 +208,7 @@ exports.loadReplaceVariables = () => { 'video-duration', 'view-time', 'whisper-message', - 'word', - 'youtube-video-duration' + 'word' ].forEach(filename => { const definition = require(`./builtin/${filename}`); replaceVariableManager.registerReplaceVariable(definition); diff --git a/src/backend/variables/builtin/youtube-video-duration.js b/src/backend/variables/builtin/youtube-video-duration.js deleted file mode 100644 index 9c032ebc0..000000000 --- a/src/backend/variables/builtin/youtube-video-duration.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; - -const { OutputDataType, VariableCategory } = require("../../../shared/variable-constants"); -const logger = require("../../logwrapper"); -const frontendCommunicator = require("../../common/frontend-communicator"); -const { parseYoutubeId } = require("../../../shared/youtube-url-parser"); - -const model = { - definition: { - handle: "youtubeVideoDuration", - usage: "youtubeVideoDuration[urlOrId]", - description: "Attempts to retrieve youtube video duration.", - categories: [VariableCategory.ADVANCED], - possibleDataOutput: [OutputDataType.TEXT] - }, - evaluator: async (trigger, id) => { - if (id == null) { - return "[NO VIDEO ID PROVIDED]"; - } - const result = await frontendCommunicator.fireEventAsync("getYoutubeVideoDuration", parseYoutubeId(id).id); - - if (isNaN(result)) { - logger.error("Error while retrieving youtube video duration", result); - return "[ERROR FETCHING DURATION]"; - } - return result; - } -}; - -module.exports = model; diff --git a/src/gui/app/index.html b/src/gui/app/index.html index 15cd3484c..859f72502 100644 --- a/src/gui/app/index.html +++ b/src/gui/app/index.html @@ -89,8 +89,6 @@ - - diff --git a/src/gui/app/services/video.service.js b/src/gui/app/services/video.service.js index 2b0f1e8e8..ec222531e 100644 --- a/src/gui/app/services/video.service.js +++ b/src/gui/app/services/video.service.js @@ -35,56 +35,10 @@ }); }; - service.getYoutubeVideoDuration = function (videoId) { - return new Promise((resolve) => { - const id = "video-" + uuid(); - $(document.documentElement).append(``); - // eslint-disable-next-line no-undef - const player = new YT.Player(id, { - videoId: videoId, - events: { - onReady: (event) => { - event.target.setVolume(0); - event.target.playVideo(); - if (player.getDuration() === 0) { - return; - } - resolve(player.getDuration()); - document.getElementById(id).remove(); - }, - onError: (event) => { - const error = { - code: event.data, - youtubeId: videoId - }; - if (event.data === "2") { - error.error = "The request contains an invalid parameter value."; - } - if (event.data === "5") { - error.error = "The requested content cannot be played in an HTML5 player or another error related to the HTML5 player has occurred."; - } - if (event.data === "100") { - error.error = "The video requested was not found. This error occurs when a video has been removed (for any reason) or has been marked as private."; - } - if (event.data === "101" || event.data === "150") { - error.error = "The owner of the requested video does not allow it to be played in embedded players."; - } - resolve(error); - document.getElementById(id).remove(); - } - } - }); - }); - }; - backendCommunicator.onAsync("getVideoDuration", async (path) => { return await service.getVideoDuration(path); }); - backendCommunicator.onAsync("getYoutubeVideoDuration", async (youtubeId) => { - return await service.getYoutubeVideoDuration(youtubeId); - }); - return service; }); }(window.angular)); From 44f2309af39ecf2a2a62fd502c29498bc9b02d6b Mon Sep 17 00:00:00 2001 From: SReject Date: Sat, 9 Dec 2023 11:03:30 -0500 Subject: [PATCH 5/5] chore: update version to 5.59.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 86367ec17..e917b8bf7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "firebotv5", - "version": "5.59.0", + "version": "5.59.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "firebotv5", - "version": "5.59.0", + "version": "5.59.1", "license": "GPL-3.0", "dependencies": { "@aws-sdk/client-polly": "^3.26.0", diff --git a/package.json b/package.json index d25410b02..d5bcbf74b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "firebotv5", - "version": "5.59.0", + "version": "5.59.1", "description": "Powerful all-in-one bot for Twitch streamers.", "main": "build/main.js", "scripts": {