Skip to content

Commit

Permalink
Fix focus issues and add new hotkeys
Browse files Browse the repository at this point in the history
pgup/pgdn now work for scrolling faster
1-3 focus one of the site lists for scrolling there
  • Loading branch information
jrudess committed Dec 28, 2017
1 parent 69b376a commit acc91aa
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 210 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"no-catch-shadow": "error",
"no-confusing-arrow": "error",
"no-console": "off",
"no-continue": "error",
"no-continue": "off",
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-else-return": "error",
Expand Down
61 changes: 24 additions & 37 deletions cb.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,35 @@ class Cb extends site.Site {
super("CB ", config, "_cb", screen, logbody, inst, total);
this.cbData = new Map();
this.timeOut = 20000;

for (let i = 0; i < this.listConfig.streamers.length; i++) {
const nm = this.listConfig.streamers[i];
this.streamerList.set(nm, {uid: nm, nm: nm, state: "Offline", filename: "", captureProcess: null});
}
}

updateList(nm, add, isTemp) {
return Promise.try(() => super.updateList({nm: nm, uid: nm}, add, isTemp));
return Promise.try(() => super.updateList({nm: nm, uid: nm}, add, isTemp));
}

checkStreamerState(nm) {
const url = "https://chaturbate.com/api/chatvideocontext/" + nm;
let msg = colors.name(nm);
let isBroadcasting = 0;
let isStreaming = 0;

return Promise.try(() => fetch(url, {timeout: this.timeOut})).then((res) => res.json()).then((json) => {
const listitem = this.streamerList.get(nm);
const streamer = this.streamerList.get(nm);
const prevState = streamer.state;

if (typeof json.status !== "undefined") {
if (json.detail === "This room requires a password.") {
listitem.streamerState = "Password Protected";
streamer.state = "Password Protected";
} else if (json.detail === "Room is deleted.") {
listitem.streamerState = "Deleted";
streamer.state = "Deleted";
} else {
listitem.streamerState = "Access Denied";
streamer.state = "Access Denied";
}
this.streamerState.set(nm, listitem.streamerState);
this.streamerList.set(nm, listitem);
this.streamerList.set(nm, streamer);
msg += ", " + json.detail;
this.dbgMsg(msg);
} else {
Expand All @@ -44,30 +49,29 @@ class Cb extends site.Site {
if (currState === "public") {
msg += " is in public chat!";
this.streamersToCap.push({uid: nm, nm: nm});
isBroadcasting = 1;
listitem.streamerState = "Public Chat";
isStreaming = 1;
streamer.state = "Public Chat";
} else if (currState === "private") {
msg += " is in a private show.";
listitem.streamerState = "Private";
streamer.state = "Private";
} else if (currState === "group") {
msg += " is in a group show.";
listitem.streamerState = "Group Show";
streamer.state = "Group Show";
} else if (currState === "away") {
msg += colors.name("'s") + " stream is off.";
listitem.streamerState = "Away";
streamer.state = "Away";
} else if (currState === "hidden") {
msg += " is online but hidden.";
listitem.streamerState = "Hidden";
streamer.state = "Hidden";
} else if (currState === "offline") {
msg += " has gone offline.";
listitem.streamerState = "Offline";
streamer.state = "Offline";
} else {
msg += " has unknown state: " + currState;
listitem.streamerState = currState;
streamer.state = currState;
}

super.checkStreamerState({nm: nm, uid: nm}, listitem, msg, isBroadcasting, currState === "offline", currState);

super.checkStreamerState(streamer, msg, isStreaming, prevState);
}
this.render();
return true;
Expand All @@ -80,37 +84,20 @@ class Cb extends site.Site {
}

checkStreamersState(batch) {
const me = this;
const queries = [];

for (let i = 0; i < batch.length; i++) {
queries.push(this.checkStreamerState(batch[i]));
}

return Promise.all(queries).then(() => true).catch((err) => {
me.errMsg(err.toString());
this.errMsg(err.toString());
});
}

getStreamersToCap() {
this.streamersToCap = [];

// TODO: This should be somewhere else
for (let i = 0; i < this.listConfig.streamers.length; i++) {
const nm = this.listConfig.streamers[i];
if (!this.streamerList.has(nm)) {
this.streamerList.set(nm, {uid: nm, nm: nm, streamerState: "Offline", filename: ""});
}
}
for (let i = 0; i < this.tempList.length; i++) {
const nm = this.tempList[i];
if (!this.streamerList.has(nm)) {
this.streamerList.set(nm, {uid: nm, nm: nm, streamerState: "Offline", filename: ""});
}
}

this.render();

const nms = [];
this.streamerList.forEach((value) => {
nms.push(value.nm);
Expand Down Expand Up @@ -141,7 +128,7 @@ class Cb extends site.Site {

setupCapture(streamer) {

if (!super.setupCapture(streamer)) {
if (!super.setupCapture(streamer.uid)) {
const empty = {spawnArgs: "", filename: "", streamer: ""};
return Promise.try(() => empty);
}
Expand Down
25 changes: 23 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ console.log = function(msg) {
const total = Number(config.enableMFC) + Number(config.enableCB) + Number(config.enableTwitch);
let inst = 1;

const screen = blessed.screen();
const screen = blessed.screen({smartCSR: true});
screen.title = "streamdvr";

const logbody = blessed.box({
top: "66%",
left: 0,
Expand Down Expand Up @@ -151,6 +153,7 @@ inputBar.on("submit", (text) => {
logbody.setScrollPerc(100);
break;
}
logbody.focus();
screen.render();
});

Expand Down Expand Up @@ -180,7 +183,7 @@ function mainSiteLoop(site) {
site.recordStreamers(streamersToCap)
).catch((err) => {
site.errMsg(err);
throw err;
// throw err;
}).finally(() => {
site.dbgMsg("Done, waiting " + config.scanInterval + " seconds.");
setTimeout(() => { mainSiteLoop(site); }, config.scanInterval * 1000);
Expand Down Expand Up @@ -232,6 +235,16 @@ function exit() {
}
}

screen.key("pageup", () => {
screen.focused.scroll(-screen.focused.height || -1);
screen.render();
});

screen.key("pagedown", () => {
screen.focused.scroll(screen.focused.height || 1);
screen.render();
});

screen.key("enter", () => {
inputBar.focus();
});
Expand Down Expand Up @@ -300,6 +313,13 @@ if (config.enableTwitch) {
mainSiteLoop(twitch);
}

const hotkeys = ["1", "2", "3", "4"];
for (let i = 0; i < hotkeys.length && i < SITES.length; i++) {
screen.key(hotkeys[i], () => {
SITES[i].list.focus();
});
}

if (!config.listshown) {
display("hide", "list");
}
Expand All @@ -313,6 +333,7 @@ screen.append(inputBar);

// Have to render screen once before printouts work
screen.render();
logbody.focus();

if (config.enableMFC) {
mfc.msg(mfc.listConfig.streamers.length + " streamer(s) in config");
Expand Down
63 changes: 32 additions & 31 deletions mfc.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,50 +47,51 @@ class Mfc extends site.Site {

checkStreamerState(uid) {

return Promise.try(() => this.mfcGuest.queryUser(uid)).then((streamer) => {
if (typeof streamer === "undefined") {
return Promise.try(() => this.mfcGuest.queryUser(uid)).then((model) => {
if (typeof model === "undefined") {
return true;
}

let isBroadcasting = 0;
let msg = colors.name(streamer.nm);
let isStreaming = 0;
let msg = colors.name(model.nm);

if (!this.streamerList.has(streamer.nm)) {
this.streamerList.set(streamer.nm, {uid: uid, nm: streamer.nm, streamerState: "Offline", filename: ""});
if (!this.streamerList.has(uid)) {
this.streamerList.set(uid, {uid: uid, nm: model.nm, state: "Offline", filename: "", captureProcess: null});
}

const listitem = this.streamerList.get(streamer.nm);
const streamer = this.streamerList.get(uid);
const prevState = streamer.state;

if (streamer.vs === mfc.STATE.FreeChat) {
listitem.streamerState = "Public Chat";
if (model.vs === mfc.STATE.FreeChat) {
streamer.state = "Public Chat";
msg += " is in public chat!";
this.streamersToCap.push(streamer);
isBroadcasting = 1;
} else if (streamer.vs === mfc.STATE.GroupShow) {
listitem.streamerState = "Group Show";
this.streamersToCap.push(model);
isStreaming = 1;
} else if (model.vs === mfc.STATE.GroupShow) {
streamer.state = "Group Show";
msg += " is in a group show";
} else if (streamer.vs === mfc.STATE.Private) {
if (streamer.truepvt === 1) {
listitem.streamerState = "True Private";
} else if (model.vs === mfc.STATE.Private) {
if (model.truepvt === 1) {
streamer.state = "True Private";
msg += " is in a true private show.";
} else {
listitem.streamerState = "Private";
streamer.state = "Private";
msg += " is in a private show.";
}
} else if (streamer.vs === mfc.STATE.Away) {
listitem.streamerState = "Away";
} else if (model.vs === mfc.STATE.Away) {
streamer.state = "Away";
msg += " is away.";
} else if (streamer.vs === mfc.STATE.Online) {
listitem.streamerState = "Away";
} else if (model.vs === mfc.STATE.Online) {
streamer.state = "Away";
msg += colors.name("'s") + " stream is off.";
} else if (streamer.vs === mfc.STATE.Offline) {
listitem.streamerState = "Offline";
} else if (model.vs === mfc.STATE.Offline) {
streamer.state = "Offline";
msg += " has logged off.";
}

super.checkStreamerState(streamer, listitem, msg, isBroadcasting, streamer.vs === mfc.STATE.Offline, streamer.vs);

super.checkStreamerState(streamer, msg, isStreaming, prevState);
this.render();

return true;
}).catch((err) => {
this.errMsg(err.toString());
Expand Down Expand Up @@ -118,21 +119,21 @@ class Mfc extends site.Site {
return Promise.all(queries).then(() => this.streamersToCap);
}

setupCapture(streamer) {
setupCapture(model) {

if (!super.setupCapture(streamer)) {
if (!super.setupCapture(model.uid)) {
const empty = {spawnArgs: "", filename: "", streamer: ""};
return Promise.try(() => empty);
}

return Promise.try(() => {
const filename = this.getFileName(streamer.nm);
const url = "http://video" + (streamer.u.camserv - 500) + ".myfreecams.com:1935/NxServer/ngrp:mfc_" + (100000000 + streamer.uid) + ".f4v_mobile/playlist.m3u8";
const filename = this.getFileName(model.nm);
const url = "http://video" + (model.u.camserv - 500) + ".myfreecams.com:1935/NxServer/ngrp:mfc_" + (100000000 + model.uid) + ".f4v_mobile/playlist.m3u8";
const spawnArgs = this.getCaptureArguments(url, filename);

return {spawnArgs: spawnArgs, filename: filename, streamer: streamer};
return {spawnArgs: spawnArgs, filename: filename, streamer: model};
}).catch((err) => {
this.errMsg(colors.name(streamer.nm) + " " + err.toString());
this.errMsg(colors.name(model.nm) + " " + err.toString());
return err;
});
}
Expand Down
Loading

0 comments on commit acc91aa

Please sign in to comment.