Skip to content

Commit

Permalink
Add colored output
Browse files Browse the repository at this point in the history
  • Loading branch information
mmgoodnow committed Jun 9, 2020
1 parent 7208108 commit 87b0e0b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
23 changes: 10 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const fs = require("fs");
const path = require("path");
const util = require("util");
const querystring = require("querystring");
const readline = require("readline");

const axios = require("axios");
const minimist = require("minimist");
const chalk = require("chalk");

const EPISODE_REGEX = /S\d\dE\d\d/i;
const jackettPath = "/api/v2.0/indexers/all/results";
Expand Down Expand Up @@ -119,7 +119,9 @@ async function findOnOtherSites(info, hashesToExclude) {
finished
.filter((e) => e !== null)
.forEach(({ tracker, type, info: { name } }) => {
console.log(`Found ${name} on ${tracker}`);
const styledName = chalk.green.bold(name);
const styledTracker = chalk.bold(tracker);
console.log(`Found ${styledName} on ${styledTracker}`);
saveTorrentFile(tracker, type, info);
});
}
Expand All @@ -137,11 +139,6 @@ async function main() {
const successfulParse = parseCommandLineArgs();
if (!successfulParse) return;

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

const dirContents = fs
.readdirSync(torrentDir)
.map((fn) => path.join(torrentDir, fn));
Expand All @@ -156,13 +153,13 @@ async function main() {
);

fs.mkdirSync(outputDir, { recursive: true });
const samples = filteredTorrents.slice(0, 16);
for (sample of samples) {
readline.clearLine(process.stdout, 0);
rl.write(`Searching for ${sample.name.replace(/.mkv$/, "")}...`);
readline.cursorTo(process.stdout, 0);
await new Promise((r) => setTimeout(r, delay));
const samples = filteredTorrents.slice();
for (const [i, sample] of samples.entries()) {
const name = sample.name.replace(/.mkv$/, "")
const progress = chalk.blue(`[${i+1}/${samples.length}]`);
console.log(progress, chalk.dim("Searching for"), name);
await findOnOtherSites(sample, hashesToExclude);
await new Promise((r) => setTimeout(r, delay));
}

rl.close();
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"axios": "^0.19.2",
"chalk": "^4.1.0",
"minimist": "^1.2.5",
"parse-torrent": "^7.1.3"
},
Expand Down
45 changes: 45 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
# yarn lockfile v1


"@types/color-name@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==

ansi-styles@^4.1.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.2.1.tgz#90ae75c424d008d2624c5bf29ead3177ebfcf359"
integrity sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==
dependencies:
"@types/color-name" "^1.1.1"
color-convert "^2.0.1"

axios@^0.19.2:
version "0.19.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"
Expand All @@ -21,6 +34,26 @@ blob-to-buffer@^1.2.6:
resolved "https://registry.yarnpkg.com/blob-to-buffer/-/blob-to-buffer-1.2.8.tgz#78eeeb332f1280ed0ca6fb2b60693a8c6d36903a"
integrity sha512-re0AIxakF504MgeMtIyJkVcZ8T5aUxtp/QmTMlmjyb3P44E1BEv5x3LATBGApWAJATyXHtkXRD+gWTmeyYLiQA==

chalk@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.0.tgz#4e14870a618d9e2edd97dd8345fd9d9dc315646a"
integrity sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

color-convert@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==
dependencies:
color-name "~1.1.4"

color-name@~1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

debug@=3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
Expand All @@ -47,6 +80,11 @@ get-stdin@^7.0.0:
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-7.0.0.tgz#8d5de98f15171a125c5e516643c7a6d0ea8a96f6"
integrity sha512-zRKcywvrXlXsA0v0i9Io4KDRaAw7+a1ZpjRwl9Wox8PFlVCCHra7E9c4kqXCoCM9nR5tBkaTTZRBoCm60bFqTQ==

has-flag@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==

magnet-uri@^5.1.3:
version "5.2.4"
resolved "https://registry.yarnpkg.com/magnet-uri/-/magnet-uri-5.2.4.tgz#7afe5b736af04445aff744c93a890a3710077688"
Expand Down Expand Up @@ -131,6 +169,13 @@ simple-sha1@^3.0.0:
queue-microtask "^1.1.2"
rusha "^0.8.1"

supports-color@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.1.0.tgz#68e32591df73e25ad1c4b49108a2ec507962bfd1"
integrity sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==
dependencies:
has-flag "^4.0.0"

thirty-two@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/thirty-two/-/thirty-two-1.0.2.tgz#4ca2fffc02a51290d2744b9e3f557693ca6b627a"
Expand Down

0 comments on commit 87b0e0b

Please sign in to comment.