Skip to content

Instantly share code, notes, and snippets.

@EusthEnoptEron
Created April 4, 2016 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EusthEnoptEron/4e032a5bd8ee4049654b1d828816d9e1 to your computer and use it in GitHub Desktop.
Save EusthEnoptEron/4e032a5bd8ee4049654b1d828816d9e1 to your computer and use it in GitHub Desktop.
Very quick 'n dirty example for a parsing server for Mangaroll
"use strict"
var express = require('express')
var morgan = require('morgan');
var app = express()
var cheerio = require('cheerio');
var request = require('request');
var _ = require("underscore");
// #### ROUTES #####
app.use(morgan("short"));
app.get('/mr/browse/:page', function (req, res) {
var page = (req.params.page || 0) * 1;
var id = (req.query.id || null);
if(id) {
request("http://www.mangareader.net/" + id,
(error, response, html) => {
if (!error && response.statusCode == 200) {
res.send(parseMRManga(html, page));
} else {
res.send({success: false});
}
});
} else {
request("http://www.mangareader.net/popular/"+ page * 30,
(error, response, html) => {
if (!error && response.statusCode == 200) {
res.send(parseMRGallery(html, page));
} else {
res.send({success: false});
}
});
}
})
app.get('/mr/show/:id', function (req, res) {
var id = req.params.id;
if(!id) {
console.log("no id");
res.send({success: false});
} else {
request("http://www.mangareader.net/" + id,
(error, response, html) => {
if (!error && response.statusCode == 200) {
res.send(parseMRChapter(html, id));
} else {
res.send({success: false, message: error});
}
});
}
})
app.listen(3000)
// ######### PARSE FUNCTIONS
function parseMRGallery(html, p) {
var $ = cheerio.load(html);
return {
success: true,
page: p,
hasMore: $("#sp strong").next("a").length > 0,
mangaList: $(".mangaresultitem").map((i, el) => {
var name = $(el).find(".manga_name a").text().trim();
var id = $(el).find(".manga_name a").attr("href").substring(1);
return {
name: name,
id : (id),
container: true,
thumb: $(el).find(".imgsearchresults").css("background-image").match(/url\('(.+?)'\)/)[1]
};
}).get()
};
}
function parseMRManga(html, p) {
var $ = cheerio.load(html);
return {
success: true,
page: 0,
hasMore: false,
mangaList: $("#chapterlist tr+tr a").map((i, el) => {
return {
name: $(el).text(),
id : ($(el).attr("href").substring(1)),
container: false
};
}).get()
};
}
function parseMRChapter(html, id) {
var $ = cheerio.load(html);
var pageCount = $("#pageMenu option").length;
console.log(pageCount);
return {
success: true,
images: _.range(1,pageCount+1).map(i => "http://192.168.1.39:3000/mr/forward?url=" + encodeURI("http://www.mangareader.net/" + id + "/" + i) )
};
}
{
"name": "Mangaroll Server Example",
"version": "0.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "EusthEnoptEron",
"license": "ISC",
"dependencies": {
"cheerio": "^0.20.0",
"connect": "^3.4.1",
"express": "^4.13.4",
"morgan": "^1.7.0",
"request": "^2.69.0",
"underscore": "^1.8.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment