diff --git a/baseunits/modules/MangaHere.pas b/baseunits/modules/MangaHere.pas index 4d64ca0f0..eaa16f6bd 100644 --- a/baseunits/modules/MangaHere.pas +++ b/baseunits/modules/MangaHere.pas @@ -5,131 +5,10 @@ interface uses - Classes, SysUtils, WebsiteModules, uData, uBaseUnit, uDownloadsManager, - XQueryEngineHTML, httpsendthread, synautil; + Classes, SysUtils, WebsiteModules; implementation -const - dirurl = '/mangalist/'; - imagepath = '//*[@id="viewer"]//img[@id="image"]/@src'; - -function GetNameAndLink(const MangaInfo: TMangaInformation; - const ANames, ALinks: TStringList; const AURL: String; - const Module: TModuleContainer): Integer; -var - v: IXQValue; -begin - if MangaInfo = nil then Exit(UNKNOWN_ERROR); - Result := NET_PROBLEM; - if MangaInfo.FHTTP.GET(Module.RootURL + dirurl) then - begin - Result := NO_ERROR; - with TXQueryEngineHTML.Create(MangaInfo.FHTTP.Document) do - try - for v in XPath('//a[@class="manga_info"]') do - begin - ALinks.Add(v.toNode.getAttribute('href')); - ANames.Add(v.toNode.getAttribute('rel')); - end; - finally - Free; - end; - end; -end; - -function GetInfo(const MangaInfo: TMangaInformation; - const AURL: String; const Module: TModuleContainer): Integer; -var - v: IXQValue; -begin - Result := NET_PROBLEM; - if MangaInfo = nil then Exit(UNKNOWN_ERROR); - with MangaInfo.mangaInfo, MangaInfo.FHTTP do - begin - url := MaybeFillHost(Module.RootURL, AURL); - if GET(url) then - begin - Result := NO_ERROR; - with TXQueryEngineHTML.Create(Document) do - try - coverLink := MaybeFillHost(Module.RootURL, XPathString('//*[@class="manga_detail"]//img[@class="img"]/@src')); - if title = '' then title := XPathString('//meta[@property="og:title"]/@content'); - authors := SeparateRight(XPathString('//*[@class="detail_topText"]/li[starts-with(.,"Author")]'), ':'); - artists := SeparateRight(XPathString('//*[@class="detail_topText"]/li[starts-with(.,"Artist")]'), ':'); - genres := SeparateRight(XPathString('//*[@class="detail_topText"]/li[starts-with(.,"Genre")]'), ':'); - status := MangaInfoStatusIfPos(XPathString( - '//*[@class="detail_topText"]/li[starts-with(.,"Status")]'), - 'Ongoing', - 'Completed'); - summary := XPathString('//*[@class="detail_topText"]/li/p[@id="show"]/text()'); - for v in XPath('//*[@class="detail_list"]/ul/li/span[@class="left"]') do - begin - chapterLinks.Add(XPathString('a/@href', v)); - chapterName.Add(XPathString('string-join((a,span,text()[3])," ")', v)); - end; - InvertStrings([chapterLinks, chapterName]); - finally - Free; - end; - end; - end; -end; - -function GetPageNumber(const DownloadThread: TDownloadThread; - const AURL: String; const Module: TModuleContainer): Boolean; -begin - Result := False; - if DownloadThread = nil then Exit; - with DownloadThread, FHTTP, Task.Container do - begin - PageLinks.Clear; - PageNumber := 0; - if GET(MaybeFillHost(Module.RootURL, AURL)) then - begin - Result := True; - with TXQueryEngineHTML.Create(Document) do - try - PageNumber := XPath('(//span[@class="right"]/select)[1]/option[not(.="Featured")]').Count; - PageLinks.Add(XPathString(imagepath)); - finally - Free; - end; - end; - end; -end; - -function GetImageURL(const DownloadThread: TDownloadThread; - const AURL: String; const Module: TModuleContainer): Boolean; -var - s: String; -begin - Result := False; - if DownloadThread = nil then Exit; - with DownloadThread, FHTTP, Task.Container do - begin - if (WorkId = PageLinks.Count - 1) and (Pos('/featured.', AURL) <> 0) then - begin - PageLinks.Delete(WorkId); - Exit; - end; - - s := AppendURLDelim(MaybeFillHost(Module.RootURL, AURL)); - if WorkId > 0 then - s := s + IncStr(WorkId) + '.html'; - if GET(s) then - begin - Result := True; - with TXQueryEngineHTML.Create(Document) do - try - PageLinks[WorkId] := XPathString(imagepath); - finally - Free; - end; - end; - end; -end; - procedure RegisterModule; begin with AddModule do @@ -137,12 +16,6 @@ procedure RegisterModule; Website := 'MangaHere'; RootURL := 'http://www.mangahere.cc'; Category := 'English'; - OnGetNameAndLink := @GetNameAndLink; - OnGetInfo := @GetInfo; - OnGetPageNumber := @GetPageNumber; - OnGetImageURL := @GetImageURL; - MaxConnectionLimit := 1; - MaxTaskLimit := 1; end; end; diff --git a/lua/modules/MangaHere.lua b/lua/modules/MangaHere.lua new file mode 100644 index 000000000..003393f32 --- /dev/null +++ b/lua/modules/MangaHere.lua @@ -0,0 +1,93 @@ +function GetInfo() + mangainfo.url=MaybeFillHost(module.rooturl,url) + http.cookies.values['isAdult'] = '1' + if http.get(mangainfo.url) then + local x=TXQuery.Create(http.Document) + if mangainfo.title == '' then + mangainfo.title=x.XPathString('//span[@class="detail-info-right-title-font"]') + end + mangainfo.coverLink=MaybeFillHost(module.rooturl, x.XPathString('//img[@class="detail-info-cover-img"]/@src')) + mangainfo.status = MangaInfoStatusIfPos(x.XPathString('css("table.table-borderless")//tr[th="Status"]/td')) + mangainfo.authors = x.XPathString('//p[@class="detail-info-right-say"]/a') + mangainfo.genres = x.XPathStringAll('//p[@class="detail-info-right-tag-list"]/a') + mangainfo.summary = x.XPathString('//p[@class="fullcontent"]') + mangainfo.status = MangaInfoStatusIfPos(x.XPathString('//span[@class="detail-info-right-title-tip"]')) + local v=x.xpath('//ul[@class="detail-main-list"]/li/a') + for i=1, v.count do + local v1=v.get(i) + mangainfo.chapterlinks.add(v1.getAttribute('href'):gsub('1%.html', '')) + mangainfo.chapternames.add(x.xpathstring('./div/p[@class="title3"]', v1)) + end + InvertStrings(mangainfo.chapterlinks,mangainfo.chapternames) + return no_error + else + return net_problem + end +end + +function GetPageNumber() + task.pagelinks.clear() + task.pagenumber = 0 + http.cookies.values['isAdult'] = '1' + local aurl = MaybeFillHost(module.rooturl, url) .. '1.html' + if http.get(aurl) then + local x=TXQuery.Create(http.Document) + local s = x.XPathString('//script[contains(., "eval")]') + s = 'var $=function(){return{val:function(){}}},newImgs,guidkey;' .. s + s = s .. ';newImgs||guidkey;' + local key = ExecJS(s) + if string.len(key) > 16 then + task.pagelinks.commatext = key + else + s = x.XPathString('//script[contains(., "chapterid")]'); + local cid = Trim(GetBetween('chapterid', ';', s):gsub('=', '')) + task.pagenumber = tonumber(Trim(GetBetween('imagecount', ';', s):gsub('=', ''))) + if task.pagenumber == nil then task.pagenumber = 1 end + local page = 1 + while page <= task.pagenumber do + http.reset() + http.headers.values['Pragma'] = 'no-cache' + http.headers.values['Cache-Control'] = 'no-cache' + http.headers.values['Referer'] = aurl + s = string.format('chapterfun.ashx?cid=%s&page=%d&key=%s', cid, page, key) + if http.xhr(MaybeFillHost(module.rooturl, url) .. s) then + s = Trim(StreamToString(http.document)) + if s ~= '' then + s = ExecJS(s .. ';d;') + local lst = TStrings.Create() + lst.commatext = s + if page > 1 then lst.delete(0) end + task.pagelinks.addtext(lst.text) + lst = nil + end + end + if task.pagelinks.count >= task.pagenumber then break end + page = page + 1 + Sleep(3000) + end + end + return true + else + return false + end +end + +function GetNameAndLink() + if http.get(module.rooturl..'/mangalist/') then + local x=TXQuery.Create(http.Document) + x.xpathhrefall('css(".browse-new-block > .browse-new-block-content > a")', links, names) + return no_error + else + return net_problem + end +end + +function Init() + m=NewModule() + m.category='English' + m.website='MangaHere' + m.rooturl='https://www.mangahere.cc' + m.ongetinfo='GetInfo' + m.ongetpagenumber='GetPageNumber' + m.ongetnameandlink='GetNameAndLink' +end