meme refinery

This commit is contained in:
Chris Ham
2018-09-25 15:05:32 -07:00
parent d9ee7b468c
commit 641b708ce5
3 changed files with 108 additions and 81 deletions

View File

@@ -460,7 +460,7 @@
"filePath": "Y:\\media\\videos\\ALttP\\my-vids\\personal-bests\\100%-mg-ahp\\2017-12-22-100mg-11912.mp4", "filePath": "Y:\\media\\videos\\ALttP\\my-vids\\personal-bests\\100%-mg-ahp\\2017-12-22-100mg-11912.mp4",
"sceneItem": "16x9ph", "sceneItem": "16x9ph",
"length": 4786, "length": 4786,
"includeInShuffle": true "includeInShuffle": false
}, },
{ {
"id": "pb-ab", "id": "pb-ab",
@@ -482,7 +482,7 @@
"filePath": "Y:\\media\\videos\\ALttP\\my-vids\\personal-bests\\all-dungeons\\2017-11-19-ad-11459.mp4", "filePath": "Y:\\media\\videos\\ALttP\\my-vids\\personal-bests\\all-dungeons\\2017-11-19-ad-11459.mp4",
"sceneItem": "16x9ph", "sceneItem": "16x9ph",
"length": 4555, "length": 4555,
"includeInShuffle": true "includeInShuffle": false
}, },
{ {
"id": "pb-any-nmg", "id": "pb-any-nmg",
@@ -493,7 +493,7 @@
"filePath": "Y:\\media\\videos\\ALttP\\my-vids\\personal-bests\\any%-nmg-nsq\\2018-05-27-nmg-12624.mp4", "filePath": "Y:\\media\\videos\\ALttP\\my-vids\\personal-bests\\any%-nmg-nsq\\2018-05-27-nmg-12624.mp4",
"sceneItem": "16x9ph", "sceneItem": "16x9ph",
"length": 5190, "length": 5190,
"includeInShuffle": true "includeInShuffle": false
}, },
{ {
"id": "pb-any-no-eg", "id": "pb-any-no-eg",
@@ -526,7 +526,7 @@
"filePath": "Y:\\media\\videos\\ALttP\\my-vids\\personal-bests\\mirror-shield\\2017-06-20-mirror-shield-5032.mp4", "filePath": "Y:\\media\\videos\\ALttP\\my-vids\\personal-bests\\mirror-shield\\2017-06-20-mirror-shield-5032.mp4",
"sceneItem": "16x9ph", "sceneItem": "16x9ph",
"length": 3068, "length": 3068,
"includeInShuffle": true "includeInShuffle": false
}, },
{ {
"id": "pb-ms-no-eg", "id": "pb-ms-no-eg",
@@ -548,7 +548,7 @@
"filePath": "Y:\\media\\videos\\ALttP\\my-vids\\personal-bests\\rbo\\2017-12-01-rbo-11813.mp4", "filePath": "Y:\\media\\videos\\ALttP\\my-vids\\personal-bests\\rbo\\2017-12-01-rbo-11813.mp4",
"sceneItem": "16x9ph", "sceneItem": "16x9ph",
"length": 4725, "length": 4725,
"includeInShuffle": true "includeInShuffle": false
}, },
{ {
"id": "pb-100-nmg", "id": "pb-100-nmg",

110
fgfm.js
View File

@@ -103,43 +103,24 @@ const streamInit = (config, twitch) => {
// Also handles "commercial breaks" if enabled // Also handles "commercial breaks" if enabled
const nextVideo = () => { const nextVideo = () => {
// Show a "commercial break" if it's been long enough since the last one // Show a "commercial break" if it's been long enough since the last one
/* let secondsSinceLastCommercial = (Date.now() - state.lastCommercialShownAt) / 1000; let secondsSinceLastCommercial = (Date.now() - state.lastCommercialShownAt) / 1000;
if (config.commercialsEnabled === true && secondsSinceLastCommercial >= config.commercialInterval) { if (config.commercialsEnabled === true && secondsSinceLastCommercial >= config.commercialInterval) {
state.commercialPlaying = true; state.commercialPlaying = true;
console.log(`It has been ${secondsSinceLastCommercial} seconds since the last commercial break!`); console.log(`It has been ${secondsSinceLastCommercial} seconds since the last commercial break!`);
// Random chance for it to be "everybody wow" // Random chance for it to be "everybody wow"
let memeId = false;
if ((Math.floor(Math.random() * 100) + 1) <= config.auwChance) { if ((Math.floor(Math.random() * 100) + 1) <= config.auwChance) {
console.log(`Showing AUW!`); console.log(`Showing AUW!`);
auw(() => { memeId = 'auw';
// show next video in queue once the commercial is done
state.lastCommercialShownAt = Date.now();
state.commercialPlaying = false;
nextVideo();
});
} else {
let commercial = config.vods.memes.sort(util.randSort)[0];
console.log(`Showing random meme: ${commercial.name}`);
let handleCommercialFinish = () => {
// unmute songrequest audio
twitch.editorChat.say(config.twitch.channel, `!volume ${config.defaultSRVolume}`);
// update commercial state and show next video in queue
state.lastCommercialShownAt = Date.now();
state.commercialPlaying = false;
nextVideo();
};
obs.playVideoInScene(commercial, config.commercialSceneName, handleCommercialFinish)
.then(res => {
// mute songrequest audio
twitch.editorChat.say(config.twitch.channel, `!volume 0`);
});
} }
showMeme(memeId).then(() => {
state.lastCommercialShownAt = Date.now();
state.commercialPlaying = false;
nextVideo();
}).catch(console.error);
return; return;
}*/ }
// Keep track of recently played videos // Keep track of recently played videos
if (state.recentlyPlayed.length === config.recentlyPlayedMemory) { if (state.recentlyPlayed.length === config.recentlyPlayedMemory) {
@@ -147,10 +128,8 @@ const streamInit = (config, twitch) => {
} }
state.recentlyPlayed.push(state.currentVideo.id); state.recentlyPlayed.push(state.currentVideo.id);
// If a commercial is playing, wait until it's done // If a commercial is playing, wait until it's done to switch
while (state.commercialPlaying === true) { while (state.commercialPlaying === true) {}
//
}
// play the next video in the queue, or pick one at random if the queue is empty // play the next video in the queue, or pick one at random if the queue is empty
if (state.videoQueue.length > 0) { if (state.videoQueue.length > 0) {
@@ -160,16 +139,11 @@ const streamInit = (config, twitch) => {
if ((Math.floor(Math.random() * 100) + 1) <= config.roomGrindChance) { if ((Math.floor(Math.random() * 100) + 1) <= config.roomGrindChance) {
console.log(`Room grind selected!`); console.log(`Room grind selected!`);
// show room-grind source // show room-grind source
// obs.showRoomGrind(config.roomGrindPlaytime); obs.showRoomGrind(config.roomGrindPlaytime, () => {nextVideo()})
obs.websocket.setSceneItemProperties({"item": "room-grind", "scene-name": config.defaultSceneName, "visible": true}) .then(timer => {
.then(res => { videoTimer = timer;
obs.showActivity("NOW SHOWING: TTAS Room Grind !ttas"); })
state.videoTimer = setTimeout(() => { .catch(console.error);
// after timeout, hide room-grind and call nextVideo()
obs.websocket.setSceneItemProperties({"item": "room-grind", "scene-name": config.defaultSceneName, "visible": false});
nextVideo();
}, config.roomGrindPlaytime*1000)
});
return; return;
} }
@@ -188,6 +162,7 @@ const streamInit = (config, twitch) => {
state.currentVideo = state.videoQueue.shift(); state.currentVideo = state.videoQueue.shift();
showVideo(state.currentVideo); showVideo(state.currentVideo);
// "Commercials"
const showCommercial = (video, callback) => { const showCommercial = (video, callback) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let handleFinish = () => { let handleFinish = () => {
@@ -206,25 +181,32 @@ const streamInit = (config, twitch) => {
}); });
}; };
// Everybody OwenWow // Memes-By-Id
const auw = (callback) => { const showMeme = (id) => {
return new Promise((resolve, reject) => {
// find the vod in memes // find the vod in memes
let video = config.vods.memes.find(e => e.id === 'auw'); let video = config.vods.memes.find(e => e.id === id);
if (!video) {
reject(`No meme found matching ID ${id}`);
}
let handleFinish = () => { let handleFinish = () => {
// hide owen if (id === 'auw') {
obs.websocket.setSceneItemProperties({"item": "owen", "scene-name": config.commercialSceneName, "visible": false}); obs.hide("owen", config.commercialSceneName);
// trigger user callback }
if (typeof callback !== 'undefined') callback(); resolve();
}; };
showCommercial(video, handleFinish) showCommercial(video, handleFinish)
.then(videoHasStarted => { .then(videoHasStarted => {
// show owen // in the case of 'auw', show owen + tell chat what's up
obs.websocket.setSceneItemProperties({"item": "owen", "scene-name": config.commercialSceneName, "visible": true}); if (id === 'auw') {
// tell chat what's up obs.show("owen", config.commercialSceneName);
twitch.botChat.say(config.twitch.channel, 'Everybody OwenWow'); twitch.botChat.say(config.twitch.channel, 'Everybody OwenWow');
}
}) })
.catch(console.error); .catch(console.error);
});
}; };
// Twitch Chat Commands // Twitch Chat Commands
@@ -322,18 +304,24 @@ const streamInit = (config, twitch) => {
// Black Box "Everybody Wow" // Black Box "Everybody Wow"
} else if (commandNoPrefix === 'auw') { } else if (commandNoPrefix === 'auw') {
state.commercialPlaying = true; state.commercialPlaying = true;
auw(() => { showMeme('auw').then(() => state.commercialPlaying = false).catch(console.error);
state.commercialPlaying = false;
});
// memes on-demand // Memes on-demand
} else if (commandNoPrefix === 'meme') { } else if (commandNoPrefix === 'meme') {
// @TODO: support request by ID let memeId = commandParts[1] || false;
if (memeId) {
console.log(`${memeId} meme requested`);
if ( config.vods.memes.findIndex(e => e.id === memeId) === -1) {
twitch.botChat.say(to, `No meme with that ID exists!`);
return;
}
} else {
memeId = config.vods.memes.sort(util.randSort)[0].id;
console.log(`${memeId} meme randomly selected`);
}
state.commercialPlaying = true; state.commercialPlaying = true;
let commercial = config.vods.memes.sort(util.randSort)[0]; showMeme(memeId).then(() => state.commercialPlaying = false).catch(console.error);
showCommercial(commercial, () => {
state.commercialPlaying = false;
});
// SWITCH SCENES // SWITCH SCENES
} else if (commandNoPrefix === 'switch') { } else if (commandNoPrefix === 'switch') {

View File

@@ -11,7 +11,10 @@ function GHOBS(config) {
.then(() => { .then(() => {
console.log(`Success! We're connected to OBS!`); console.log(`Success! We're connected to OBS!`);
this.websocket.getCurrentScene().then(res => this.currentScene = res.name); this.websocket.getCurrentScene().then(res => this.currentScene = res.name);
this.websocket.onSwitchScenes(data => this.currentScene = data['scene-name']); this.websocket.onSwitchScenes(data => {
console.log(`New Active Scene: ${data.sceneName}`);
this.currentScene = data.sceneName;
});
resolve(); resolve();
}) })
.catch(reject); .catch(reject);
@@ -28,19 +31,28 @@ function GHOBS(config) {
// Shows a video in the given scene/item and then hides it and switches back to the original scene when finished // Shows a video in the given scene/item and then hides it and switches back to the original scene when finished
this.playVideoInScene = (video, scene, callback) => { this.playVideoInScene = (video, scene, callback) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let originalScene = this.currentScene; let originalScene = this.currentScene || false;
console.log(`Changing scene from ${originalScene} to ${scene}`);
this.websocket.setCurrentScene({"scene-name": scene}) this.websocket.setCurrentScene({"scene-name": scene})
.then(res => { .then(res => {
// set the file path on the source // set the file path on the source
console.log(`Setting file path to: ${video.filePath}`);
this.websocket.setSourceSettings({"sourceName": video.sceneItem, "sourceSettings": {"local_file": video.filePath}}) this.websocket.setSourceSettings({"sourceName": video.sceneItem, "sourceSettings": {"local_file": video.filePath}})
// show the video scene item // show the video scene item
.then(data => this.websocket.setSceneItemProperties({"item": video.sceneItem, "scene-name": scene, "visible": true})) .then(data => {console.log(`Showing ${video.sceneItem}`); this.websocket.setSceneItemProperties({"item": video.sceneItem, "scene-name": scene, "visible": true})})
// when the video is over, hide it and trigger the user callback, but resolve promise immediately with the timer // when the video is over, hide it and trigger the user callback, but resolve promise immediately with the timer
.then(data => { .then(data => {
resolve(setTimeout(() => { resolve(setTimeout(() => {
console.log(`Hiding ${video.sceneItem}`);
this.websocket.setSceneItemProperties({"item": video.sceneItem, "scene-name": scene, "visible": false}); this.websocket.setSceneItemProperties({"item": video.sceneItem, "scene-name": scene, "visible": false});
if (originalScene) {
console.log(`Switching scene back to ${originalScene}`);
this.websocket.setCurrentScene({"scene-name": originalScene}); this.websocket.setCurrentScene({"scene-name": originalScene});
}
if (typeof callback !== 'undefined') {
console.log('Triggering user callback');
callback(data); callback(data);
}
}, video.length*1000)) }, video.length*1000))
}); });
}) })
@@ -65,6 +77,33 @@ function GHOBS(config) {
this.hideActivity = () => { this.hideActivity = () => {
return this.websocket.setSceneItemProperties({"item": this.config.currentActivitySceneItemName, "scene-name": this.config.defaultSceneName, "visible": false}); return this.websocket.setSceneItemProperties({"item": this.config.currentActivitySceneItemName, "scene-name": this.config.defaultSceneName, "visible": false});
}; };
this.showRoomGrind = (playTime, callback) => {
return new Promise((resolve, reject) => {
this.websocket.setSceneItemProperties({"item": "room-grind", "scene-name": this.config.defaultSceneName, "visible": true})
.then(res => {
this.showActivity("NOW SHOWING: TTAS Room Grind !ttas");
resolve(setTimeout(() => {
// after timeout, hide room-grind and call user callback
this.websocket.setSceneItemProperties({"item": "room-grind", "scene-name": this.config.defaultSceneName, "visible": false});
if (typeof callback !== 'undefined') callback();
}, playTime*1000));
})
.catch(reject);
});
};
this.setVisible = (item, scene, visible) => {
return this.websocket.setSceneItemProperties({"item": item, "scene-name": scene, "visible": visible});
};
this.show = (item, scene) => {
return this.setVisible(item, scene, true);
};
this.hide = (item, scene) => {
return this.setVisible(item, scene, false);
};
}; };
module.exports = GHOBS; module.exports = GHOBS;