Skip to content

Commit

Permalink
Filter by number of files and file extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
mmgoodnow committed Jun 8, 2020
1 parent b2fa7f0 commit 5a04e7c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ dist
.pnp.*

*.torrent
torrents/
33 changes: 31 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
#!/usr/bin/env node

import parseTorrent from "parse-torrent";
const parseTorrent = require("parse-torrent");
const fs = require("fs");
const path = require("path");

console.log(parseTorrent);
function parseTorrentFromFilename(filename) {
const data = fs.readFileSync(filename);
const torrentInfo = parseTorrent(data);
return torrentInfo;
}

function filterTorrentFile(info) {
if (info.files.length < 4) {
console.log(`not enough files: ${info.name}`);
return false;
}
const allMkvs = info.files.every(file => file.path.endsWith(".mkv"));
if (!allMkvs) {
console.log(`not all mkvs: ${info.name}`);
return false;
}
return true;
}

function main() {
const dirContents = fs.readdirSync("torrents")
.map(fn => path.join("torrents", fn));
const parsedTorrents = dirContents.map(parseTorrentFromFilename);
const filteredTorrents = parsedTorrents.filter(filterTorrentFile);
console.log(filteredTorrents.map(x => x.name));
}

main();
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
"dependencies": {
"parse-torrent": "^7.1.3"
},
"type": "module"
"type": "module",
"devDependencies": {
"prettier": "^2.0.5"
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ parse-torrent@^7.1.3:
simple-get "^3.0.1"
simple-sha1 "^3.0.0"

prettier@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==

queue-microtask@^1.1.2:
version "1.1.3"
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.1.3.tgz#9188ce1b10f9350330c509982c8b1c640e0592a7"
Expand Down

0 comments on commit 5a04e7c

Please sign in to comment.