${task.id} | ${msg} | ${signMap[msg]||signMap['unknown']} | |
`;};elt.innerHTML=html;}},taskInfo:{object:this.pxer.pp.runtime,propertyName:'taskInfo',},state:{object:this.runtime,propertyName:'state',update(elt,value){var pt='';switch(value){case'wait':pt='待命中';break;case'getPageTask':pt='获取作品信息中';break;case'getWorks':pt='爬取作品中';break;case'finish':pt='已完成';break;case'error':pt='出现错误';break;case'stop':pt='手动停止';break;default:pt='未知';};elt.innerHTML=pt;},},};return obj[key];};PxerUI.prototype['signConfig']=function(elt,key){var configMap=this.configMap(key);if(configMap===undefined)return console.warn(`Count not find field"${key}"in PxerUI::configMap`);if(typeof configMap.toValue==='function'){elt.value=configMap.toValue(configMap.object[configMap.propertyName]);}else{elt.value=configMap.object[configMap.propertyName];};let eventType=elt.tagName==='SELECT'?'change':'input';elt.addEventListener(eventType,()=>{if(typeof configMap.toConfig==='function'){configMap.object[configMap.propertyName]=configMap.toConfig(elt.value);}else{configMap.object[configMap.propertyName]=elt.value;};})};PxerUI.prototype['configMap']=function(key){var obj={thread:{object:this.pxer.ptm.config,propertyName:'thread',},timeout:{object:this.pxer.ptm.config,propertyName:'timeout',},maxRetry:{object:this.pxer.ptm.config,propertyName:'retry',},score:{object:this.pxer.printFilter,propertyName:'score',},avg:{object:this.pxer.printFilter,propertyName:'avg',},yes_and_tag:{object:this.pxer.printFilter,propertyName:'yes_and_tag',toConfig:value=>value.trim().split(' '),toValue:config=>config.join(' '),},yes_or_tag:{object:this.pxer.printFilter,propertyName:'yes_or_tag',toConfig:value=>value.trim().split(' '),toValue:config=>config.join(' '),},no_and_tag:{object:this.pxer.printFilter,propertyName:'no_and_tag',toConfig:value=>value.trim().split(' '),toValue:config=>config.join(' '),},no_or_tag:{object:this.pxer.printFilter,propertyName:'no_or_tag',toConfig:value=>value.trim().split(' '),toValue:config=>config.join(' '),},illust_single:{object:this.pxer.printConfig,propertyName:'illust_single',},illust_medium:{object:this.pxer.printConfig,propertyName:'illust_medium',},manga_single:{object:this.pxer.printConfig,propertyName:'manga_single',},manga_medium:{object:this.pxer.printConfig,propertyName:'manga_medium',},ugoira:{object:this.pxer.printConfig,propertyName:'ugoira_zip',toConfig:value=>{var arr=value.split('-');this.pxer.printConfig['ugoira_frames']=arr[1];return arr[0];},toValue:config=>`${config}-${this.pxer.printConfig['ugoira_frames']}`,},};return obj[key]};
\ No newline at end of file
+`;return this};PxerPrint.prototype.countAddress=function(){this.runtime.address=[];for(let works of this.runtime.passWorks){switch(true){case works instanceof PxerUgoiraWorks:this.runtime.ugoira_frames[works.id]=works.frames;this.runtime.address.push(...PxerPrint.getUgoira(works,this.config));break;case works instanceof PxerMultipleWorks:this.runtime.address.push(...PxerPrint.getMultiple(works,this.config));break;case works instanceof PxerWorks:this.runtime.address.push(...PxerPrint.getWorks(works,this.config));break}};return this};PxerPrint.prototype.filterWorks=function(){this.runtime.passWorks=[];let isEmpty=function(filter){for(let key in filter){if(filter[key])return false};return true}(this.filter);if(isEmpty){this.runtime.passWorks=this.works;return this}for(let works of this.works){if(!(this.filter.score==0||isNaN(this.filter.score)||works.scoreCount>=this.filter.score))continue;if(!(this.filter['yes_and_tag'].length===0||this.filter['yes_and_tag'].every(tag=>works.tagList.indexOf(tag)!=-1)))continue;if(!(this.filter['yes_or_tag'].length===0||!this.filter['yes_or_tag'].some(tag=>works.tagList.indexOf(tag)!=-1)))continue;if(!(this.filter['no_and_tag'].length===0||!this.filter['no_and_tag'].every(tag=>works.tagList.indexOf(tag)==-1)))continue;if(!(this.filter['no_or_tag'].length===0||!this.filter['no_or_tag'].some(tag=>works.tagList.indexOf(tag)==-1)))continue;this.runtime.passWorks.push(works)};return this};'use strict';class PxerHtmlParser{constructor(config){this.config=config;this.task=null}};PxerHtmlParser.prototype['parseAll']=function(requests){var result=[];for(let request of requests){result.push(...this.parse(request))};return result};PxerHtmlParser.prototype['parse']=function(request){if(request instanceof PxerWorksRequest){this.task=request;return[this.parseWorks()]}else if(request instanceof PxerPageRequest){this.task=request;return this.parsePage()}else{return false}};PxerHtmlParser.prototype['parseWorks']=function(){var pw;for(let url in this.task.html){let data={task:this.task,dom:(new DOMParser()).parseFromString(this.task.html[url],'text/html'),url:url,pw:pw,};switch(true){case/mode=medium/.test(url):pw=PxerHtmlParser.parseMediumHtml(data);break;case/mode=big/.test(url):case/mode=manga_big/.test(url):pw=PxerHtmlParser.parseMangaBigHtml(data);break;case/mode=manga&/.test(url):pw=PxerHtmlParser.parseMangaHtml(data);break;default:console.warn(`Count not parse"${url}"`);};};return pw;};PxerHtmlParser.prototype['parsePage']=function(){var dom=(new DOMParser()).parseFromString(this.task.html,'text/html');var elts=dom.querySelectorAll('a.work._work');var taskList=[];for(let elt of elts){let task=new PxerWorksRequest({html:{},type:elt.matches('.ugoku-illust')?'ugoira':elt.matches(".manga")?'manga':"illust",isMultiple:elt.matches(".multiple"),id:elt.getAttribute('href').match(/illust_id=(\d+)/)[1]});task.url=getUrlList(task);taskList.push(task);};return taskList;function getUrlList(task,singleMangaMode){if(task.type==="ugoira"||(task.type==="illust"&&!task.isMultiple)){return["/member_illust.php?mode=medium&illust_id="+task.id];}else if(task.isMultiple){return["/member_illust.php?mode=medium&illust_id="+task.id,"/member_illust.php?mode=manga&illust_id="+task.id,"/member_illust.php?mode=manga_big&page=0&illust_id="+task.id];}else if(task.type==="manga"&&!task.isMultiple){return["http://www.pixiv.net/member_illust.php?mode=medium&illust_id="+task.id,"http://www.pixiv.net/member_illust.php?mode=big&illust_id="+task.id,];}else{console.warn('miss task '+task.id);return[];};};};PxerHtmlParser.parseMangaHtml=function({task,dom,url,pw}){var rePw=new PxerMultipleWorks(pw);rePw.multiple=+dom.querySelectorList(".page .total",".position .total").innerHTML;return rePw;};PxerHtmlParser.parseMangaBigHtml=function({task,dom,url,pw}){var rePw=new PxerMultipleWorks(pw);var src=dom.getElementsByTagName('img')[0].src;Object.assign(rePw,{server:src.match(/(i\d+)\.pixiv\.net/)[1],date:src.match(PxerHtmlParser.REGEXP['getDate'])[1],fileFormat:src.match(/\.(jpg|gif|png)$/)[1],});return rePw;};PxerHtmlParser.parseMediumHtml=function({task,dom,url,pw}){var rePw=new PxerWorks({id:task.id,type:task.type,tagList:[...dom.querySelectorAll(".tag a.text")].map(elt=>elt.innerHTML),viewCount:+dom.querySelector(".view-count").innerHTML,ratedCount:+dom.querySelector(".rated-count").innerHTML,scoreCount:+dom.querySelector(".score-count").innerHTML,fileFormat:'jpg',});if(task.type==='ugoira'){let script=[...dom.querySelectorAll("script")].filter(tag=>/zip/.test(tag.innerHTML))[0].innerHTML;let exp=/"src":"([^"<>]*?600x600\.zip)"[^<>]*?"frames":(\[.*?\])/mi;let arr=script.match(exp);rePw=new PxerUgoiraWorks(Object.assign(rePw,{server:arr[1].replace(/\\\//g,'\/').match(/(i\d+)\.pixiv\.net/)[1],date:arr[1].replace(/\\\//g,'\/').match(PxerHtmlParser.REGEXP['getDate'])[1],frames:JSON.parse(arr[2]),}));};if(task.type==='illust'&&!task.isMultiple){let src=dom.querySelector(".ui-modal-close-box img.original-image").getAttribute("data-src");Object.assign(rePw,{server:src.match(/(i\d+)\.pixiv\.net/)[1],date:src.match(PxerHtmlParser.REGEXP['getDate'])[1],fileFormat:src.match(/\.(jpg|gif|png)$/)[1],});}if(task.type==='manga'&&!task.isMultiple){let src=dom.querySelector("a._work.manga img").src;Object.assign(rePw,{server:src.match(/(i\d+)\.pixiv\.net/)[1],date:src.match(PxerHtmlParser.REGEXP['getDate'])[1],});}return rePw;};PxerHtmlParser.getMangaPath=function(pwr){var pw=PxerHtmlParser.parseMediumHtml({task:pwr,dom:(new DOMParser()).parseFromString(pwr.html[pwr.url[0]],'text/html'),url:pwr.url[0],pw:{},});pw.fileFormat='';return PxerPrint.getWorks(pw,{manga_single:'max'})[0];};PxerHtmlParser.REGEXP={'getDate':/img\/((?:\d+\/){5}\d+)/,};'use strict';class PxerThread extends PxerEvent{constructor({id,config,task}){super(['load','error','fail']);this.id=id;this.isFree=true;this.task=task;this.config=config||{timeout:5000,retry:3};this.runtime={};this.xhr=new XMLHttpRequest();this.xhr.timeout=this.config.timeout;this.xhr.responseType='text';};};PxerThread.checkRequest=function(url,html){if(!html)return'empty';if(html.indexOf("_no-item _error")!==-1){if(html.indexOf("sprites-r-18g-badge")!==-1)return'r-18g';if(html.indexOf("sprites-r-18-badge")!==-1)return'r-18';};if(html.indexOf("sprites-mypixiv-badge")!==-1)return'mypixiv';return true;};PxerThread.prototype['stop']=function(){this.xhr.abort();};PxerThread.prototype['init']=function(task){if(task)this.task=task;this.runtime={};this.isFree=false;if(this.task instanceof PxerWorksRequest){this.runtime.urlList=this.task.url.slice();}else if(this.task instanceof PxerPageRequest){this.runtime.urlList=[this.task.url];}else{console.error(`PxerThread:"${this.task}"is not PxerRequest`);return false;};};PxerThread.prototype['run']=function(){var prms=Promise.resolve();var thread=this;var xhr=this.xhr;xhr.removeEventListener('*');this.runtime.urlList.forEach((url)=>{prms=prms.then(()=>{return new Promise((resolve,reject)=>{var sendAjax=function(){xhr.addOneEventListener("timeout",function(){setDefalut(thread.runtime,"retry",0);if((+thread.config.retry!==0)&&(++thread.runtime.retry>=thread.config.retry)){reject({type:"timeout",url,xhr,});}else{sendAjax();};});if(thread.task.type==='manga'&&thread.task.isMultiple===false&&/mode=big/.test(url)){var referer;for(let url of thread.task.url){if(/mode=medium/.test(url)){referer=url;break;}};xhr.open('GET',url,true);xhr.refererSend(referer);}else{xhr.open('GET',url,true);xhr.send();};};xhr.addOneEventListener("load",function(){if(/^2/.test(xhr.status)||xhr.status===304){var msg=PxerThread.checkRequest(url,xhr.responseText);if(msg!==true){reject({type:msg,url,xhr,});return;};if(thread.task instanceof PxerWorksRequest){resolve(Object.assign(thread.task.html=Object(thread.task.html),{[url]:xhr.responseText}));}else{resolve(thread.task.html=xhr.responseText);};}else{reject({type:"http:"+xhr.status,url,xhr,});};});xhr.addOneEventListener("error",function(){reject({type:"error",url,xhr,});});sendAjax();});});});prms.finally(()=>{thread.isFree=true;}).then(()=>{thread.dispatch("load",thread.task);}).catch(function({type,url,xhr}){switch(type){case'error':console.error(`PxerThread#${thread.id}error!`);thread.dispatch("error",{task:thread.task,msg:type});break;case'empty':case'r-18g':case'r-18':case'mypixiv':console.warn(`Request check return ${type}form PxerThread#${thread.id}@${url}`);break;case'timeout':console.warn(`Request timeout form PxerThread#${thread.id}@${url}`);break;default:console.error(`PxerThread#${thread.id}error!`);thread.dispatch("error",{task:thread.task,msg:'unknown'});};thread.dispatch("fail",{task:thread.task,msg:type});});return true;};'use strict';class PxerThreadManager extends PxerEvent{constructor(config){super(['load','error','fail']);this.config=config||{timeout:5000,retry:3,thread:8,};this.taskList=[];this.resultSet=[];this.runtime={};this.threads=[];};};PxerThreadManager.prototype['stop']=function(){for(let thread of this.threads){thread.off('*');thread.stop();};};PxerThreadManager.prototype['init']=function(taskList){if(taskList)this.taskList=taskList.slice();this.resultSet=[];this.runtime={};this.threads=[];for(let i=0;i