PyComicPackRouMan/entity/down/RouMan.py
2023-04-01 13:23:34 +08:00

58 lines
2.4 KiB
Python

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")
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')
chapter_api_url = comicInfo.getBaseUrl(chapter_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,images) = [data.get("name"),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)