var config  = require('../config').rip.imgur.gallery,
    common  = require('../common'),
    log     = require('../log'),
    request = require('request');

module.exports.name = 'imgur - Gallery';
module.exports.url = /^https?:\/\/([a-zA-Z\d-]+\.){0,}imgur\.com\/?(?:gallery)?/;
module.exports.authority = 1;

module.exports.rip = function(site) {
	for (var i = 0; i < config.distance; i++) {
		var url = 'http://imgur.com/gallery/hot/viral/page/0/hit?scrolled&set=' + i;

		log.info(site.name + ' - Requesting gallery page #' + i);
		request(url, function(error, response, html) {
			if (!error && response.statusCode == 200) {
				var images = JSON.parse(html.split('\n')[6].substring(1, html.split('\n')[6].length - 9));

				images.forEach(function(image) {
					common.ripSite({ 
						name: site.name + (image.is_album ? '/' + image.hash : ''), 
						url: 'http://imgur.com/' + (image.is_album ? 'a/' : '') + image.hash,
						action: site.action
					});			
				});
			} else {
				log.warn(site.name + ' - Page scrape failed due to HTTP error. Retrying in ' + config.retryDelay + ' seconds.');
				setTimeout(function() { module.exports.rip(site); }, config.retryDelay * 1000);
			}
		});
	}
}
var config  = require('../config').rip.imgur.gallery,
    common  = require('../common'),
    log     = require('../log'),
    cheerio = require('cheerio');
    
module.exports.name = 'imgur - Gallery';
module.exports.url = /^https?:\/\/([a-zA-Z\d-]+\.){0,}imgur\.com\/?(?:gallery)?/;
module.exports.authority = 1;

module.exports.rip = function(site) {
	for (var i = 0; i < config.distance; i++) {
		common.getPage(site, 'http://imgur.com/gallery/hot/viral/page/0/hit?scrolled&set=' + i, config.retryDelay, null, function(html) {
			var $ = cheerio.load(html);

			$('div.post').each(function(i, element) {
				var isAlbum = $(element).find('.post-info').html().lastIndexOf('album', 0) === 0;
				var hash = $(element).find('.image-list-link').attr('href').split('/')[2];

				common.ripSite({ 
					name: site.name + (isAlbum ? '/' + hash : ''), 
					url: 'http://imgur.com/' + (isAlbum ? 'a/' : '') + hash,
					action: site.action
				});		
			});
		});
	}
}
Fix imgur-gallery. (Did the pages never have JSON on them or is this a new change?)