Optimizing scan torrent files.js
This commit is contained in:
parent
bb086e0231
commit
9f2220233c
|
@ -38,14 +38,21 @@ async function fillTorrentCsvHashes() {
|
||||||
|
|
||||||
async function scanFolder() {
|
async function scanFolder() {
|
||||||
console.log('Scanning dir: ' + argv.dir + '...');
|
console.log('Scanning dir: ' + argv.dir + '...');
|
||||||
|
var fileHashes = new Set(Object.keys(torrentFiles));
|
||||||
|
|
||||||
var files = fs.readdirSync(argv.dir).filter(f => {
|
var files = fs.readdirSync(argv.dir).filter(f => {
|
||||||
var f = f.split('.');
|
var sp = f.split('.');
|
||||||
var ext = f[1];
|
var ext = sp[1];
|
||||||
var hash = f[0];
|
var hash = sp[0];
|
||||||
// It must be a torrent file, NOT already be in the files json,
|
var fullPath = argv.dir + '/' + f;
|
||||||
// and be an infohash in the csv file.
|
// It must be a torrent file,
|
||||||
|
// NOT in the torrent_files.json
|
||||||
|
// must be in the CSV file
|
||||||
|
// must have a file size
|
||||||
return (ext == 'torrent' &&
|
return (ext == 'torrent' &&
|
||||||
!Object.keys(torrentFiles).includes(hash));
|
!fileHashes.has(hash) &&
|
||||||
|
torrentCsvHashes.has(hash) &&
|
||||||
|
getFilesizeInBytes(fullPath) > 0);
|
||||||
});
|
});
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
var fullPath = argv.dir + '/' + file;
|
var fullPath = argv.dir + '/' + file;
|
||||||
|
@ -56,12 +63,18 @@ async function scanFolder() {
|
||||||
console.log('Done scanning.')
|
console.log('Done scanning.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFilesizeInBytes(filename) {
|
||||||
|
var stats = fs.statSync(filename)
|
||||||
|
var fileSizeInBytes = stats["size"]
|
||||||
|
return fileSizeInBytes
|
||||||
|
}
|
||||||
|
|
||||||
function writeFile() {
|
function writeFile() {
|
||||||
torrentFiles = Object.keys(torrentFiles)
|
torrentFiles = Object.keys(torrentFiles)
|
||||||
.sort()
|
.sort()
|
||||||
.filter(hash => torrentCsvHashes.has(hash))
|
.filter(hash => torrentCsvHashes.has(hash))
|
||||||
.reduce((r, k) => (r[k] = torrentFiles[k], r), {});
|
.reduce((r, k) => (r[k] = torrentFiles[k], r), {});
|
||||||
fs.writeFileSync(jsonFile, JSON.stringify(torrentFiles));
|
fs.writeFileSync(jsonFile, JSON.stringify(torrentFiles, null, 2));
|
||||||
console.log(`${jsonFile} written.`);
|
console.log(`${jsonFile} written.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue