Fandom Developers Wiki
Advertisement

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.


Text above can be found here (edit)
Advertisement