DownloadImages is a Node.js script that allows you to download images from a wiki.
Script
var bot = require('nodemw');
var download = require('download-file');
// Pass configuration object
var client = new bot({
protocol: 'https', // Wikipedia now enforces HTTPS
server: 'pcj.fandom.com', // Host name of MediaWiki-powered site
path: '', // Path to api.php script
debug: false // Is more verbose when set to true
});
client.getPagesInNamespace(6,function(err,data) {
// Error handling
if (err) {
console.error(err);
return;
}
for (p of data) {
client.getImageInfo(p.title, function(e,d) {
if (e) {
console.error(e);
return;
}
if (d == null) {
console.log(p.title);
return;
}
var options = {
directory: "./images/",
filename: d.descriptionurl.replace(/^http.*?\/File:/,"")
};
download(d.url, options, function(err) {
if (err) throw err;
});
});
}
});
Requirements
The script cannot be run on-wiki; you must run it using Node.js.
Packages required:
Configuration and execution
The script will need to be edited to specify the wiki to download images from. By default it will download all images (based on all pages in the File namespace) into a "images" subdirectory of the current path.
As written, the script will not log in, which can limit the number of images downloaded. By logging using a bot account this limitation is removed. Add the following before the client.getPagesInNamespace in order to allow the script to log in:
client.logIn ('bot-name', 'bot-password',function(err,data) {
if (err) {
console.error(err);
return;
}
})
Text above can be found here (edit)