JScript to find album covers that measure less than 1000x1000 px. Perfect for those who like to manage their large music libraries.
Last active
October 18, 2015 15:07
-
-
Save guilhermesimoes/a9e9eb87e8f5b4a864bb to your computer and use it in GitHub Desktop.
JScript: Find small album covers
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 fso, shellApp, wiaImg; | |
/* global WScript, ActiveXObject */ | |
fso = new ActiveXObject("Scripting.FileSystemObject"); | |
shellApp = new ActiveXObject("Shell.Application"); | |
wiaImg = new ActiveXObject("WIA.ImageFile"); | |
run(); | |
function run () { | |
var folder; | |
folder = selectFolder(); | |
if (folder !== null) { | |
outputResult( | |
sortFiles( | |
findFiles(folder) | |
) | |
); | |
} | |
} | |
function selectFolder () { | |
return shellApp.BrowseForFolder(0, "Select your Music folder", 0); | |
} | |
function findFiles (folder) { | |
var files, items, item, path, width, height; | |
files = []; | |
items = folder.Items(); | |
for (var i=0; i<items.Count; i++) { | |
item = items.Item(i); | |
if (item.IsFolder) { | |
files = files.concat(findFiles(item.GetFolder)); | |
} | |
else if (item.Type.indexOf('image') !== -1) { | |
path = item.Path; | |
wiaImg.LoadFile(path); | |
width = wiaImg.Width; | |
height = wiaImg.Height; | |
if (width < 1000) { | |
files.push({ | |
path: path, | |
width: width, | |
height: height | |
}); | |
} | |
} | |
} | |
return files; | |
} | |
function sortFiles (files) { | |
return files.sort(function (fileA, fileB) { return fileA.width - fileB.width; }); | |
} | |
function outputResult (files) { | |
var currentDir, outputPath, outputFile, file; | |
currentDir = fso.GetAbsolutePathName("."); | |
outputPath = fso.BuildPath(currentDir, "covers.txt"); | |
outputFile = fso.CreateTextFile(outputPath, true, true); | |
for (var i=0; i<files.length; i++) { | |
file = files[i]; | |
outputFile.WriteLine(file.path + " " + file.width + "x" + file.height); | |
} | |
outputFile.Close(); | |
WScript.Echo("Done!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment