From 08c0d568039eb0dac2a5cb0b0b55621f176ceb3d Mon Sep 17 00:00:00 2001 From: Yu-Jen Lin Date: Wed, 10 May 2017 20:14:09 -0400 Subject: [PATCH 1/2] add new parser --- renderer-process/models/values.js | 10 +- .../parsers/readcomicbooksonline.js | 282 ++++++++++++++++++ .../viewcontrollers/read-viewcontroller.js | 6 +- 3 files changed, 294 insertions(+), 4 deletions(-) create mode 100644 renderer-process/parsers/readcomicbooksonline.js diff --git a/renderer-process/models/values.js b/renderer-process/models/values.js index c3eeeed..25aee86 100644 --- a/renderer-process/models/values.js +++ b/renderer-process/models/values.js @@ -9,6 +9,7 @@ var sfacg = require("../parsers/sfacg"); var _8comic = require("../parsers/8comic"); var dm5 = require("../parsers/dm5"); +var readcomicbooksonline = require("../parsers/readcomicbooksonline"); module.exports = { // from host path @@ -23,7 +24,11 @@ module.exports = { }, "www.dm5.com": { name: "dm5", - parsers: dm5, + parsers: dm5 + }, + "readcomicbooksonline.net": { + name: "read-comicbooks-online", + parsers: readcomicbooksonline } }, // from host name @@ -36,6 +41,9 @@ module.exports = { }, "dm5": { parsers: dm5 + }, + "read-comicbooks-online": { + parsers: readcomicbooksonline } } } \ No newline at end of file diff --git a/renderer-process/parsers/readcomicbooksonline.js b/renderer-process/parsers/readcomicbooksonline.js new file mode 100644 index 0000000..b9a2673 --- /dev/null +++ b/renderer-process/parsers/readcomicbooksonline.js @@ -0,0 +1,282 @@ +/** + * Parser Module + * + * A parser module needs to have three functions + * + * * Function: search(searchTerm, callback) + * function callback(result) + * result is a list of obj contains following + * fields: + * link + * titlekey + * imguri + * title + * host + * updateinfo + * description + * + * * Function: GrabChapters(searchResponse, callback) + * function callback(result) + * result is a list of obj contains following + * fields: + * ch_name, + * ch_link, + * domid, + * index + * + * * Function: loadChapters(searchResponse, callback) + * function callback(result) + * result is a list of obj contains following + * fields: + * imgurl, + * id, + * idx + * + * + */ + +var requestModule = require("request"); +const util = require("../util"); +var async = require('async'); +var jar = requestModule.jar(); + + +var request = requestModule.defaults({jar: jar}); + + +module.exports = { + search: search, + grabChapters: grabChapters, + loadChapter: loadChapter +} +var host = "read-comicbooks-online"; +var searchuri = "http://readcomicbooksonline.net/search/node/{search}"; +var baseuri = "http://readcomicbooksonline.net"; + +/** + * Search comic books + * @param {string} searchTerm: Keywords to search + * @param {function} callback(result, host) + * + * result {Array}: List of obj (see below) that contains information about the comic + * host {String} : name of the host + * + * obj {Object}: + * link {String} + * titlekey {String} + * imguri {String} + * title {String} + * host {String} + * updateinfo {String} + * description {String} + */ +function search(search_term, callback) { + // console.log(encodeURI(searchuri.replace("{search}", search_term))) + request({ + method: "GET", + uri: encodeURI(searchuri.replace("{search}", search_term)) + }, searchResponse.bind({callback:callback})); +} + +/** + * HTML request callback function. Response from search + * @param see npm request module + */ +function searchResponse(error, response, body) { + // console.log(body); + // // var tmp2 = $("
" + body + "
"); + // // console.log(tmp2.html()); + var tmp = $("#block-system-main", "
" + body + "
").find(".search-result"); + console.log (tmp); + var result = []; + var callback = this.callback; + async.each(tmp, function(e, callback1){ + console.log(e); + let titleinfo = e.querySelector(".title"); + let title = titleinfo.textContent.replace(/^\s+|\s+$/g, ''); + // console.log(title); + var link = titleinfo.querySelector('a').getAttribute('href'); + var titlekey = link.substr(link.lastIndexOf('/') + 1); + // console.log(titlekey); + // var imguri = $(e).find('img').attr('src'); + // var updateinfo = "作者:" + $(e).find('dt>a:first-of-type').text(); + // // console.log(updateinfo); + // var description = $(e).find('.info .value').text().replace(/^\s+|\s+$/g, ''); + var obj = {}; + obj.link = link; + obj.titlekey = titlekey; + // obj.imguri = imguri; + obj.title = title; + obj.host = host; + // obj.updateinfo = updateinfo; + // obj.description = description; + request({ + method: "GET", + uri: link + }, onDetailInfoGet.bind({ + callback: callback1, + obj: obj, + result: result + })); + // result.push(obj); + // callback1(); + }, function () { + console.log("All Search dm5 done"); + callback(result, host); + }); + + // this.callback(result, host); +} + +function onDetailInfoGet(error, response, body) { + // console.log(response); + var tmp = $("#infoblock", "
" + body + "
"); + console.log(tmp); + this.obj.imguri = baseuri + tmp.find('img').attr('src'); + this.obj.updateinfo = tmp.find("#statsblock").find('tr:nth-child(4) .info').text(); + this.obj.description = tmp.find("#summary").children().remove().end().text(); + + this.result.push(this.obj); + this.callback(); +} + + +/** + * + * @param {String} titlekey + * @param {String} link + * @param {function} callback (result) + * + * + * {List} result: List of obj (see below) + * {Object} obj + * {String} ch_name : Chapter's name + * {String} ch_link : URL to the chapter + * {String} ch_group: Chapter's Group + * {String} chKey : Chapter's unique key + * {String} domid : HTML DOM object id + * {int} index : index + * + */ +function grabChapters(titlekey, link, callback) { + request({ + methos: 'GET', + uri: link, + }, onChapterGrabbed.bind({callback: callback, titlekey: titlekey})); +} + +function onChapterGrabbed(error, response, body) { + var hostpath = response.request.host; + var tmp = $("#chapterlist", "
" + body + "
").find(".chapter"); + // console.log(tmp); + // var tmp = $("
" + body + "
").find('[id^=cbc] li a'); + var comic_title = $("#content-wrap", "
" + body + "
").find(".page-title").text(); + var comic_title_alt = comic_title.replace(/[^\w\s]/gi, ''); +console.log(comic_title); + var result = []; + var result_keys = {}; + var newest = ""; + var titlekey = this.titlekey; + tmp.each(function(i, e){ + // console.log(e); + var ch_name = $(e).text().replace(comic_title, ''); + ch_name = ch_name.replace(comic_title_alt, ""); + + var ch_link = $(e).find('a').attr("href"); + var ch_group = "cr_main"; + + var ch_key = ch_link.substr(ch_link.lastIndexOf('/') + 1).replace(/[^\w\s]/gi, '');; + var domid = ch_key; + // var ch_key = domid; + // console.log(ch_name + ":" + ch_link + ":" + ch_group + ":" + domid + ":" + ch_key); + var obj = { + ch_name: ch_name, + ch_link: ch_link, + ch_group: ch_group, + ch_key: ch_key, + domid: domid, + index: i + }; + result.push(obj); + + }); + newest = result[0].ch_name; + + this.callback(result, newest); +} + + +/** + * + * @param {String} ch_link : Link to the chapter + * @param {String} ch_group: Chapter's Group + * @param {String} ch_key : Chapter's unique key + * @param {String} ch_name : Chapter name (User-readable) + * @param {function} callback(result, chName) + * @param result: list of obj contains information for images to load + * {String} imgurl: Image URL + * {String} id : HTML DOM object id + * {int} idx : index + */ +function loadChapter(ch_link, ch_group, ch_key, callback) { + request({ + method: 'GET', + uri: ch_link + }, onSingleChapterLoaded.bind({callback:callback, ch_group: ch_group, ch_key: ch_key})) + +} + + + +/** + * Load the page to find the javascript file location that contains info we need + * @param see npm request module + */ +function onSingleChapterLoaded(error, response, body) { + // var doc = body; + // console.log(body); + console.log(response.request.href); + var tmp = $("
" + body + "
"); + var omv = tmp.find("#omv"); + var num_pages = omv.find(".pager:first-child select:nth-child(2) option").length; + var rel_img_url_template = omv.find(".picture").attr("src"); + // console.log(num_pages) + // console.log(rel_img_url_template); + var result = []; + var callback = this.callback; + var ch_group = this.ch_group; + var ch_key = this.ch_key; + async.times(num_pages, function(i, next) { + var rel_img_url = rel_img_url_template.replace(/-\d*\./g, "-" + util.pad(i+1, 3) + "."); + var img_url = baseuri + "/reader/" + rel_img_url; + request({ + method:'GET', + uri: img_url, + headers: { + Referer: 'http://readcomicbooksonline.net/reader/', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36', + cookie: 'has_js=1' + } + + }, function(error, response, body) { + console.log(error); + console.log(response); + console.log(body); + // console.log(rel_img_url); + var id = "pic" + i; + var obj = { + imgurl: img_url, + id: id, + idx: i + }; + next(null, obj); + }); + + }, function(err, result){ + callback(result, ch_group, ch_key); + + }); + + + +} diff --git a/renderer-process/viewcontrollers/read-viewcontroller.js b/renderer-process/viewcontrollers/read-viewcontroller.js index c2289b2..0f83013 100644 --- a/renderer-process/viewcontrollers/read-viewcontroller.js +++ b/renderer-process/viewcontrollers/read-viewcontroller.js @@ -236,7 +236,7 @@ function prevChapter() { } function scrollToPage(page_idx) { - // console.log("scroll to page: " + page_idx); + // console.log("scroll to page: " + page_idx + ":" + page_id_list.length); if (page_idx >= 0) { current_page_idx = page_idx; } @@ -245,7 +245,7 @@ function scrollToPage(page_idx) { // console.log("pos.top: " + pos.top); var read_area = $('#read-area'); read_area.animate({ - scrollTop: (current_chapter_idx >= page_id_list.length)? read_area[0].scrollHeight :current_page_idx * height + scrollTop: (current_page_idx >= page_id_list.length)? read_area[0].scrollHeight :current_page_idx * height }, 100) } @@ -513,7 +513,7 @@ $(function(){ // curPageIdx = Math.round(pos / height); // console.log("scroll: " + height + "," + pos + "," +curPageIdx); // console.log("scrolled: " + curPageIdx); - EA.send("MOUSE_SCROLL_READVIEW"); + // EA.send("MOUSE_SCROLL_READVIEW"); did_scroll = true; // console.log("scroll"); From a92d99233b5ca2f75cef465c23e24a56fb6cdf28 Mon Sep 17 00:00:00 2001 From: Yu-Jen Lin Date: Wed, 10 May 2017 20:14:36 -0400 Subject: [PATCH 2/2] bumped version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cf176e4..1250906 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "comic-reader", "productName": "Comic Reader", "author": "Team Comic Reader", - "version": "0.1.39", + "version": "0.1.40", "description": "Quickly, smoothly and cooler reading experience. The best move to read comics.", "main": "main.js", "devDependencies": {