update
This commit is contained in:
1 parent
4f0023881e
commit
7aa548214d
15 files changed
+245
-518
No files matched your search
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user