forked from DebaucheryLibrarian/traxxx
Displaying results in terminal table with select, scroll and experimental search. Expanded broken character handling for PervCity scraper.
This commit is contained in:
39
src/app.js
39
src/app.js
@@ -1,11 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const config = require('config');
|
||||
const { terminal } = require('terminal-kit');
|
||||
const moment = require('moment');
|
||||
const blessed = require('neo-blessed');
|
||||
|
||||
const networks = require('../networks.js');
|
||||
const scrapers = require('./scrapers');
|
||||
const render = require('./tui/render');
|
||||
|
||||
function initScreen() {
|
||||
const screen = blessed.screen({
|
||||
title: `traxxx ${new Date().getTime()}`,
|
||||
smartCSR: true,
|
||||
mouse: false,
|
||||
});
|
||||
|
||||
screen.enableInput();
|
||||
|
||||
screen.key(['escape', 'q', 'C-c'], () => {
|
||||
screen.render();
|
||||
screen.destroy();
|
||||
});
|
||||
|
||||
return screen;
|
||||
}
|
||||
|
||||
function accumulateIncludedSites() {
|
||||
return config.include.reduce((acc, network) => {
|
||||
@@ -83,7 +101,7 @@ function accumulateSites() {
|
||||
}
|
||||
|
||||
async function fetchScenes(sites) {
|
||||
return Promise.all(sites.map(async (site) => {
|
||||
const scenesPerSite = await Promise.all(sites.map(async (site) => {
|
||||
const scraper = scrapers[site.id] || scrapers[site.network];
|
||||
|
||||
if (scraper) {
|
||||
@@ -92,25 +110,18 @@ async function fetchScenes(sites) {
|
||||
|
||||
return [];
|
||||
}));
|
||||
}
|
||||
|
||||
function exit() {
|
||||
terminal.grabInput(false);
|
||||
terminal.clear();
|
||||
terminal.processExit();
|
||||
return scenesPerSite.reduce((acc, siteScenes) => ([...acc, ...siteScenes]), []);
|
||||
}
|
||||
|
||||
async function init() {
|
||||
const screen = initScreen();
|
||||
|
||||
const sites = accumulateSites();
|
||||
const scenes = await fetchScenes(sites);
|
||||
const sortedScenes = scenes.sort(({ date: dateA }, { date: dateB }) => moment(dateB).diff(dateA));
|
||||
|
||||
terminal.singleColumnMenu(scenes[0].latest.map(scene => `[${scene.siteId} ${moment(scene.date).format('YYYY-MM-DD')}] ${scene.title} (${scene.actors.join(', ')}) ★ ${scene.rating.stars.toFixed(2)}`));
|
||||
|
||||
terminal.on('key', (name) => {
|
||||
if (name === 'CTRL_C') {
|
||||
exit();
|
||||
}
|
||||
});
|
||||
render(sortedScenes, screen);
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
Reference in New Issue
Block a user