Skip to content

Commit

Permalink
v5.59.1
Browse files Browse the repository at this point in the history
  • Loading branch information
SReject committed Dec 9, 2023
2 parents 8149db8 + 44f2309 commit a2b5114
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 108 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
15 changes: 5 additions & 10 deletions src/backend/chat/commands/command-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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.");
}
}
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
79 changes: 64 additions & 15 deletions src/backend/effects/builtin/play-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -443,39 +444,70 @@ 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;
} else {
// Error
logger.error("Play Video Effect: Unable to retrieve Youtube Video Duration", result);
return;
}

resourceToken = uuid();

} else if (effect.videoType === "Local Video" || effect.videoType === "Random From Folder") {
const result = await frontendCommunicator.fireEventAsync("getVideoDuration", data.filepath);
if (!isNaN(result)) {
duration = result;
}
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;
},
Expand All @@ -496,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", "");
Expand Down Expand Up @@ -692,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) {
Expand Down
3 changes: 1 addition & 2 deletions src/backend/variables/builtin-variable-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 0 additions & 30 deletions src/backend/variables/builtin/youtube-video-duration.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/gui/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@

<script src="./app-main.js"></script>

<script src="https://www.youtube.com/iframe_api"></script>

<!-- include: "type": "js", "files": "controllers/**/*.js" -->
<script type="text/javascript" src="./controllers/channel-rewards.controller.js"></script>
<script type="text/javascript" src="./controllers/chat-messages.controller.js"></script>
Expand Down
46 changes: 0 additions & 46 deletions src/gui/app/services/video.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,56 +35,10 @@
});
};

service.getYoutubeVideoDuration = function (videoId) {
return new Promise((resolve) => {
const id = "video-" + uuid();
$(document.documentElement).append(`<div id="${id}" style="display: none;"></div>`);
// 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));

0 comments on commit a2b5114

Please sign in to comment.