Created
October 5, 2016 06:24
-
-
Save ryanstevens/ad5caaee1826635ec00fd82620ab2375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var md5 = require('md5'); | |
var fs = require('fs'); | |
var crypto = require('crypto'); | |
var async = require('async'); | |
var md5File = require('md5-file'); | |
var path = require('path'); | |
var argv = require('yargs') | |
.alias('d', 'd') | |
.default('d', './') | |
.argv; | |
var photos = {}; | |
var files = walkSync(argv.d); | |
files = files.filter(file => { | |
return (file.toLowerCase().indexOf('.jpg') > 0); | |
}) | |
async.eachLimit(files, 10, function(file, cb) { | |
md5File(file, (err, hash) => { | |
// console.log(hash +'\t\t'+ file); | |
if (!photos[hash]) photos[hash] = []; | |
photos[hash].push(file); | |
setTimeout(cb, 0); | |
}); | |
}, function() { | |
Object.keys(photos).forEach((key) => { | |
if (photos[key].length>1) { | |
photos[key].forEach((file) => console.log(file)); | |
} | |
}); | |
}); | |
function walkSync(dir, filelist) { | |
var fs = fs || require('fs'), | |
files = fs.readdirSync(dir); | |
filelist = filelist || []; | |
files.forEach(function(file) { | |
if (fs.statSync(dir + '/' + file).isDirectory()) { | |
filelist = walkSync(dir + '/' + file, filelist); | |
} | |
else { | |
filelist.push(dir + '/' + file); | |
} | |
}); | |
return filelist; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment