This commit is contained in:
cwx committed 2023-01-23 09:40:53 +08:00
1 parent 4f0023881e
commit 7aa548214d
15 files changed
+245 -518

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
import json
from utils.HtmlUtils import htmlUtils
from utils.comic.ComicInfo import comicInfo
from utils.downloader import download_images
from utils.base.BaseComicEntity import baseComic
class comicEntity:
@classmethod
def baseComicData(cls,url,update=False):
data = htmlUtils.xpathData('//script[@id="__NEXT_DATA__"]/text()',url=url,update=update)
data = json.loads(data[0])
data = data.get("props")
x = data.get("pageProps")
return x
@classmethod
def downladsComcis(cls,url):
#漫画名
x = cls.baseComicData(url)
books = x.get("books")
len_books = len(books)
base_url = comicInfo.getBaseUrl(url)
for x in range(0, len_books):
book = books[x]
book_id = book.get("id")
book_name = book.get("name")
updated = book.get("updatedAt")
comic_href = base_url+"/books/"+book_id
href = baseComic.downladsComcis(book_name=book_name,comic_href=comic_href,updated=updated)
cls.oneComic(href)
comicInfo.updateComicDate()
@classmethod
def oneComic(cls,c_url,sleep=None):
#漫画名
title = htmlUtils.xpathData('//div[@class="gb-inside-container"]/h1[contains(@class,"gb-headline-text")]/text()',url=c_url,update=True,num=0)
#别名
#alias = htmlUtils.xpathData('//span[contains(@class,"bookid_alias")]/text()',num=1)
#icon = htmlUtils.xpathData('//div[contains(@class,"gb-container")]/div[@class="gb-inside-container"]/img[contains(@class,"dynamic-featured-image")]/@src')
icon = htmlUtils.xpathData('//noscript/img[contains(@class,"dynamic-featured-image")]/@src',num=0)
author = htmlUtils.xpathData('//div[@class="gb-inside-container"]/div[@class="author-content"]/a/text()', num=0)
tags = htmlUtils.xpathData('//div[@class="gb-inside-container"]/div[@class="genres-content"]/a/text()')
dep = htmlUtils.xpathData('//div[@class="gb-inside-container"]/div/p/text()')
dep = "".join(dep)
#update_date = htmlUtils.xpathData('//div[@class="chapter-content-listing"]//a[@class="wp-manga-chapterlist"]//span[@class="chapter-release-date"]/i/text()')
chapters_url = htmlUtils.xpathData('//div[@class="chapter-content-listing"]//a[@class="c-chapter-readmore"]/@href',url=c_url,num=0)
chapters = htmlUtils.xpathData('//div[@class="chapter-content-listing"]//a[@class="wp-manga-chapterlist"]/text()',not_eq=' ',url=chapters_url)
chapter_href = htmlUtils.xpathData('//div[@class="chapter-content-listing"]//a[@class="wp-manga-chapterlist"]/@href',url=chapters_url)
#chapter_href = htmlUtils.xpathData('//div[@class="chapter-content-listing"]//a[@class="wp-manga-chapter"]/@href',url=c_url,next_xpath='//div[@class="chapter-content-listing"]//a[@class="c-chapter-readmore"]/@href')
baseComic.oneComic(url=c_url,title=title,author=author,
icon=icon,tags=tags,dep=dep,chapters=chapters,chapter_href=chapter_href,
alias=None)
+74
View File
@@ -0,0 +1,74 @@
import json
import re
from utils.HtmlUtils import htmlUtils
from utils.comic.ComicInfo import comicInfo
from utils.downloader import download_images
from utils.base.BaseComicEntity import baseComic
class comicEntity:
@classmethod
def baseComicData(cls,url,update=False):
data = htmlUtils.xpathData('//script[@id="__NEXT_DATA__"]/text()',url=url,update=update)
data = json.loads(data[0])
data = data.get("props")
x = data.get("pageProps")
return x
@classmethod
def downladsComcis(cls,url):
#漫画名
x = cls.baseComicData(url)
books = x.get("books")
len_books = len(books)
base_url = comicInfo.getBaseUrl(url)
for x in range(0, len_books):
book = books[x]
book_id = book.get("id")
book_name = book.get("name")
updated = book.get("updatedAt")
comic_href = base_url+"/books/"+book_id
href = baseComic.downladsComcis(book_name=book_name,comic_href=comic_href,updated=updated)
cls.oneComic(href)
comicInfo.updateComicDate()
@classmethod
def oneComic(cls,c_url,sleep=None):
nums = htmlUtils.xpathData("//div[@class='row']/div[6]/div[1]/div[1]/ul[contains(@class,'btn-toolbar')]/a",url=c_url,update=True)
book_name = htmlUtils.xpathData("//div[@itemprop='name']/h1[@id='book-name']/text()",num=0)
title = re.sub(r'[\\\/\|\(\)\~\?\.\:\:\-\*\<\>]', '', book_name)
tags = htmlUtils.xpathData("//div[@class='row']/div[@class='col-lg-7']/div[1]/div[@class='tag-block']/span[@data-type='tags']/a[@class='btn btn-sm btn-primary']/text()")
author = htmlUtils.xpathData("//div[@class='row']/div[@class='col-lg-7']/div[1]/div[@class='tag-block']/span[@data-type='author']/a[@class='btn btn-sm btn-primary']/text()")
book_msg = htmlUtils.xpathData("//div[@class='row']/div[@class='col-lg-7']/div[1]/div[@class='p-t-5 p-b-5']/text()")
jmid = book_msg[0]
dep = str(book_msg[1]).replace("叙述:","")
icon = htmlUtils.xpathData("//div[@class='row']//div[@class='thumb-overlay']/img/@src",num=0)
referer = re.search(r'(https://\w+\.\w+)/', c_url).group(1)
if nums:
list_chapter_name = []
list_chapter_href = []
list_chapter_update = []
cls.count_chapter = 0
for i in nums:
photo_name_list = i.xpath("li/text()")[0].split()
photo_date = i.xpath("li/span/text()")[0].split()
#print(re.findall(r'[\u4E00-\u9FA5]+.*?', i.xpath("li/text()")[0]))
try:
if re.findall(r'[\u4E00-\u9FA5]', photo_name_list[2]):
photo_name=re.sub(r'\s','',photo_name_list[0])+' '+photo_name_list[2]
else:photo_name=re.sub(r'\s','',photo_name_list[0])
except Exception as e:
photo_name = re.sub(r'\s', '', photo_name_list[0])
photo_name = re.sub(r'[\\\/\|\(\)\~\?\.\:\:\-\*\<\>\-]', '',photo_name)
#print(photo_name)
photoid=i.attrib['data-album']
cls.aid = photoid
comicInfo.setValue1(cls.aid)
list_chapter_name.append(photo_name)
list_chapter_href.append(referer+i.attrib['href'])
list_chapter_update.append(photo_date[0])
baseComic.oneComic(url=c_url,title=title,author=author,
icon=icon,tags=tags,dep=dep,chapters=list_chapter_name,chapter_href=list_chapter_href,
alias=None)
+54
View File
@@ -0,0 +1,54 @@
import json
from utils.HtmlUtils import htmlUtils
from utils.comic.ComicInfo import comicInfo
from utils.downloader import download_images
from utils.base.BaseComicEntity import baseComic
class comicEntity:
@classmethod
def baseComicData(cls,url,update=False):
data = htmlUtils.xpathData('//script[@id="__NEXT_DATA__"]/text()',url=url,update=update)
data = json.loads(data[0])
data = data.get("props")
x = data.get("pageProps")
return x
@classmethod
def downladsComcis(cls,url):
#漫画名
x = cls.baseComicData(url,True)
books = x.get("books")
len_books = len(books)
base_url = comicInfo.getBaseUrl(url)
for x in range(0, len_books):
book = books[x]
book_id = book.get("id")
book_name = book.get("name")
updated = book.get("updatedAt")
comic_href = base_url+"/books/"+book_id
comicInfo.setUpdateAt(updated)
comicInfo.setComicName(book_name)
href = baseComic.downladsComcis(book_name=book_name,comic_href=comic_href,updated=updated)
if href != None:
cls.oneComic(href)
comicInfo.updateComicDate()
@classmethod
def oneComic(cls,c_url,sleep=None):
#漫画名
title = htmlUtils.xpathData('//div[@class="col"]/h5/text()',url=c_url,num=0,update=True)
#别名
alias = htmlUtils.xpathData('//span[contains(@class,"bookid_alias")]/text()',num=1)
icon = htmlUtils.xpathData('//img[@class="img-thumbnail"]/@src',num=0)
author = htmlUtils.xpathData('//div[contains(@class,"bookid_bookInfo")]/p[1]/text()',num=1)
tags = htmlUtils.xpathData('//div[contains(@class,"bookid_bookInfo")]/p[3]/b/text()',num=0)
action = htmlUtils.xpathData('//div[contains(@class,"bookid_bookInfo")]/p[2]/text()',num=1)
dep = htmlUtils.xpathData('//div[contains(@class,"bookid_bookInfo")]/p[4]/text()',num=1)
update_date = htmlUtils.xpathData('//div[contains(@class,"bookid_bookInfo")]/p[5]/small/text()',num=1)
chapters = htmlUtils.xpathData('//div[contains(@class,"bookid_chapterBox")]//div[contains(@class,"bookid_chapter")]/a/text()')
chapter_href = htmlUtils.xpathData('//div[contains(@class,"bookid_chapterBox")]//div[contains(@class,"bookid_chapter")]/a/@href')
baseComic.oneComic(url=c_url,title=title,author=author,
icon=icon,tags=tags,dep=dep,chapters=chapters,chapter_href=chapter_href,
alias=alias)
+26
View File
@@ -0,0 +1,26 @@
import hashlib
import json
import os
from utils.HtmlUtils import htmlUtils
from utils.FileUtils import imageUtils
from utils.comic.ComicInfo import comicInfo
from utils.Ntfy import ntfy
class comicCommon:
@classmethod
def comicChapterDownload(cls,chapter_url):
imgs_url =htmlUtils.xpathData("//div[@class='gb-inside-container']/img/@data-src",url=chapter_url,update=True)
# pages_imgs =htmlUtils.xpathData("//div[@class='center scramble-page']/@id",url=chapter_url)
#print("img_list:",len(img_list))
list_img = []
list_file_name = []
count = 1
for i in imgs_url:
img_su = str(i).split('.')[-1]
count_image = "{:0>3d}".format(count)
list_file_name.append(count_image+"."+img_su)
list_img.append(count_image)
count += 1
comicInfo.setPages(list_img)
comicInfo.writeComicInfoXML(comicInfo.str_chapter)
comicInfo.comicChapterDownload(imgs_url,list_file_name)
+108
View File
@@ -0,0 +1,108 @@
import hashlib
import json
import os
from utils.HtmlUtils import htmlUtils
from utils.FileUtils import imageUtils
from utils.comic.ComicInfo import comicInfo
from utils.Ntfy import ntfy
class comicCommon:
@classmethod
def comicChapterDownload(cls,chapter_url):
chapter_url = chapter_url+"?shunt=2"
img_list =htmlUtils.xpathData("//div[@class='panel-body']/div/div[contains(@class,'center scramble-page')]/img/@data-original",url=chapter_url,update=True)
pages_imgs =htmlUtils.xpathData("//div[@class='center scramble-page']/@id",url=chapter_url)
comicInfo.setPages(pages_imgs)
comicInfo.writeComicInfoXML(comicInfo.str_chapter)
#print("img_list:",len(img_list))
list_img = []
list_file_name = []
for i in img_list:
img_url= i
img_name = os.path.basename(img_url).split('.')[0]
aid = int(comicInfo.getValue1())
if aid > 220980:
#if is_scramble:
img_name = "scramble="+str(cls.get_scramble_num(aid,img_name))+"_"+img_name
#path_img = "%s\\%s.jpg" % (cls.aid, img_name)
path_img = "%s.jpg" % (img_name)
list_img.append(img_url)
list_file_name.append(path_img)
comicInfo.comicChapterDownload(list_img,list_file_name)
@classmethod
def get_md5(cls,num):
result1 = hashlib.md5(num.encode()).hexdigest()
print('get_md5-', result1)
return result1
@classmethod
def get_scramble_num(cls,e, t):
#print(type(e),e, type(t),t)
a = 10
try:
num_dict = {}
for i in range(10):
num_dict[i] = i * 2 + 2
if (int(e) >= 268850):
n = str(e) + t;
# switch(n=(n = (n = md5(n)).substr(-1)), n %= 10) {
#print("n=",n)
tmp = ord(cls.get_md5(n)[-1])
result = num_dict[tmp % 10]
a = result
return a
except Exception as e:
print(e.__traceback__.tb_lineno,e)
return False
@classmethod
def encode_scramble_image(cls,imgpath):
image = Image.open(imgpath)
w, h = image.size
#image.show()
file_str = str(imgpath).split("=")
#10_29.jpg
base_dir = file_str[0].replace("scramble","")
base_name = file_str[-1]
base_fn = base_name.split("_")
save_name = base_fn[1]
save_name_delesu = save_name.split(".")[0]
blocks = int(base_fn[0])
img_type = os.path.basename(imgpath).split('.')[-1]
save_path = os.path.join(os.path.dirname(imgpath),save_name_delesu+"."+img_type)
# print(type(aid),type(img_name))
if blocks:
s = blocks # 随机值
# print(s)
l = h % s # 切割最后多余的值
box_list = []
hz = 0
for i in range(s):
c = math.floor(h / s)
g = i * c
hz += c
h2 = h - c * (i + 1) - l
if i == 0:
c += l;hz += l
else:
g += l
box_list.append((0, h2, w, h - g))
# print(box_list,len(box_list))
item_width = w
# box_list.reverse() #还原切图可以倒序列表
# print(box_list, len(box_list))
newh = 0
image_list = [image.crop(box) for box in box_list]
# print(box_list)
newimage = Image.new("RGB", (w, h))
for image in image_list:
# image.show()
b_w, b_h = image.size
newimage.paste(image, (0, newh))
newh += b_h
newimage.save(save_path)
if os.path.exists(imgpath):
os.remove(imgpath)
+63
View File
@@ -0,0 +1,63 @@
import json
from utils.HtmlUtils import htmlUtils
from utils.FileUtils import imageUtils
from utils.comic.ComicInfo import comicInfo
from utils.Ntfy import ntfy
class comicCommon:
@classmethod
def baseComicData(cls,url,update=False):
data = htmlUtils.xpathData('//script[@id="__NEXT_DATA__"]/text()',url=url,update=update)
data = json.loads(data[0])
data = data.get("props")
x = data.get("pageProps")
return x
@classmethod
def comicChapterDownload(cls,chapter_url):
x = cls.baseComicData(chapter_url,update=True)
book_name = x.get("bookName")
chapter_name = x.get("chapterName")
#fileUtils.saveConfComicChapterInfo(chapterName,x,bookName)
#if comicInfo.nextExistsGetPath("info_"):
# print(f"{bookName} {chapterName} info文件已存在跳过")
alias = x.get("alias")
description = x.get("description")
images = x.get("images")
chapter_api_path = x.get("chapterAPIPath")
comicInfo.setComicName(book_name)
comicInfo.setChapterName(chapter_name)
comicInfo.setDep(description)
if chapter_api_path != None:
chapter_api_path = str(chapter_api_path).encode('utf-8').decode('unicode_escape')
base_url = comicInfo.getBaseUrl(chapter_url)
chapter_api_url = base_url+chapter_api_path
ntfy.sendMsg(f"chapterApiUrl= {chapter_api_url}",alert=False)
data = htmlUtils.getJSON(chapter_api_url,update=True)
if data != None:
data = data.get("chapter")
chapter_name = data.get("name")
images = data.get("images")
if images == None:
ntfy.sendMsg(f"未获取到章节图像 comic_name={book_name} chapter={chapter_name}")
count = 1
list_img = []
list_file_name = []
for image in images:
image_src = image.get("src")
scramble = image.get("scramble")
count_image = "{:0>3d}".format(count)
list_img.append(image_src)
image_src_prefix = "."+str(image_src).split(".")[-1]
if scramble:
su = "."+str(image_src).split(".")[-1]
de_str = str(image_src).split("/")[-1].replace(su,"==")
blocks = imageUtils.encodeImage(de_str)
count_image = "scramble="+str(blocks)+"_"+count_image
list_file_name.append(count_image+image_src_prefix)
count+=1
#print("count_all_img=", count)
#netUtils.downloadComicChapterImages(list_img,scrambles=list_scramble)
comicInfo.comicChapterDownload(list_img,list_file_name)