This commit is contained in:
cwx
2022-12-06 10:16:29 +08:00
parent 499cb29fa3
commit a8148ac383
11 changed files with 606 additions and 178 deletions
+132 -47
View File
@@ -1,63 +1,148 @@
import json,os
import json,os,time
from utils.comic.ComicStr import comicStr
from utils.ComicUtils import comicUtils
from utils.FileUtils import fileUtils
class comicEntityRM:
from utils.comic.PathStr import pathStr
from utils.NetUtils import netUtils
from utils.HtmlUtils import htmlUtils
from utils.ImageUtils import imageUtils
from utils.comic.ComicInfo import comicInfo
from utils.CBZUtils import CBZUtils
from utils.downloader import download_images
class comicEntity:
@classmethod
def oneComic(cls,c_url):
#漫画名
title = comicUtils.xpathData(comicStr.title,
'//div[@class="col"]/h5/text()',url=c_url,num=0)
title = htmlUtils.xpathData('//div[@class="col"]/h5/text()',url=c_url,num=0)
#别名
alias = comicUtils.xpathData(comicStr.alias,
'//span[contains(@class,"bookid_alias")]/text()',num=1)
icon = comicUtils.xpathData(comicStr.icon,
'//img[@class="img-thumbnail"]/@src')
alias = htmlUtils.xpathData('//span[contains(@class,"bookid_alias")]/text()',num=1)
icon = htmlUtils.xpathData('//img[@class="img-thumbnail"]/@src',num=0)
author = comicUtils.xpathData(comicStr.author,
'//div[contains(@class,"bookid_bookInfo")]/p[1]/text()',num=1)
tags = comicUtils.xpathData(comicStr.tags,
'//div[contains(@class,"bookid_bookInfo")]/p[3]/b/text()')
action = comicUtils.xpathData(comicStr.action,
'//div[contains(@class,"bookid_bookInfo")]/p[2]/text()',num=1)
dep = comicUtils.xpathData(comicStr.dep,
'//div[contains(@class,"bookid_bookInfo")]/p[4]/text()',num=1)
update_date = comicUtils.xpathData(comicStr.last_update,
'//div[contains(@class,"bookid_bookInfo")]/p[5]/small/text()',num=1)
chapters = comicUtils.xpathData(comicStr.chapters,
'//div[contains(@class,"bookid_chapterBox")]//div[contains(@class,"bookid_chapter")]/a/text()')
chapter_href = comicUtils.xpathData(comicStr.chapter_href,
'//div[contains(@class,"bookid_chapterBox")]//div[contains(@class,"bookid_chapter")]/a/@href')
comicUtils.setComic(title,alias,icon,author,tags,action,dep,update_date,chapters,chapter_href)
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')
#{'title': ['社區重建協會']}
#主页
#homepage = {comicStr.homepage : [c_url] }
#图片
#comicUtils.setComic(titles,homepage,icons,authors,deps,chapters, chapter_hrefs,last_update)
comicData = comicUtils.getComic()
print(comicData)
wait = input("数据暂停查看y/n")
if not wait == "y":
exit()
return comicData
author = str(author).replace("&",",").replace(" ",",")
comicInfo.setHomePage(c_url)
comicInfo.setComicName(str(title))
comicInfo.setComicNames(title+","+alias)
comicInfo.setAuthor(author)
comicInfo.setIcon(icon)
comicInfo.setTag(tags)
comicInfo.setTags(tags)
comicInfo.setDep(dep)
comicInfo.setCBS("韩漫")
comicInfo.setLang("zh")
comicInfo.setComicNames(title+","+alias)
#comicUtils.setComic(title,alias,icon,author,tags,action,dep,update_date,chapters,chapter_href)
count_chapter = 0
for href in chapter_href:
chapter = chapters[count_chapter]
comicInfo.setChapterName(chapter)
if not comicInfo.nextExistsGetPath("done_"):
comicEntity.comicChapter(href,scramble=True,sleep=8)
count_chapter += 1
'''
'''
读取某章节下所有图片
'''
@classmethod
def comicChapter(cls,c_url,chapter):
xpath_str = '//img[contains(@class,"id_comicImage")]/@src'
not_eq = "/loading.jpg"
#章节下所有图片链接
list_img = comicUtils.xpathData(comicStr.list_img,
xpath_str,url=c_url,type=chapter,not_eq=not_eq)
def comicChapter(cls,chapter_url,scramble=None,sleep=None):
cls.Onechapter(chapter_url,scramble,sleep)
#进入下个阶段
comicInfo.nextImgToDownloadChapter()
if comicInfo.nextExistsGetPath("down_"):
#章节图片全部下载后,调用下载封面
netUtils.downloadComicIcon()
#下个阶段
comicInfo.nextDownloadToCBZChapter()
if comicInfo.nextExistsGetPath("cbz_"):
#下载后自动打包
CBZUtils.packAutoComicChapterCBZ()
comicInfo.nextCBZToDoneChapter()
@classmethod
def Onechapter(cls,chapter_url,scramble=None,sleep=None):
if not str(chapter_url).startswith("http"):
chapter_url = comicInfo.getBaseUrl() + chapter_url
chapter_dir = cls.comicChapterDownload(chapter_url)
if sleep == None:
print("not sleep")
#time.sleep(3)
else:
time.sleep(int(sleep))
#下载完成后, 开始解密图片
if scramble:
dirs = os.listdir(chapter_dir)
for img in dirs:
isScramble = str(img).startswith("scramble=")
if isScramble:
c_path = os.path.join(chapter_dir, img)
imageUtils.getScrambleImage(c_path)
#进入下一阶段
comicInfo.nextInfoToImgChapter()
@classmethod
def comicChapterDownload(cls,chapter_url):
#漫画名
data = htmlUtils.xpathData('//script[@id="__NEXT_DATA__"]/text()',url=chapter_url)
# #
data = json.loads(data[0])
data = data.get("props")
x = data.get("pageProps")
bookName = x.get("bookName")
chapterName = x.get("chapterName")
#fileUtils.saveConfComicChapterInfo(chapterName,x,bookName)
#if comicInfo.nextExistsGetPath("info_"):
# print(f"{bookName} {chapterName} info文件已存在跳过")
comicInfo.nextSaveInfoChapter(chapterName,x)
alias = x.get("alias")
description = x.get("description")
images = x.get("images")
chapterAPIPath = x.get("chapterAPIPath")
comicInfo.setComicName(bookName)
comicInfo.setChapterName(chapterName)
comicInfo.setDep(description)
pathComicInfo = comicInfo.getPathComicInfoXML()
if not os.path.exists(pathComicInfo):
print("不存在ComicInfo.xml 生成中...")
comicInfo.writeComicInfoXML(chapterName)
if not chapterAPIPath == None:
base_url = comicUtils.getBaseUrl(chapter_url)
chapterAPIUrl = base_url+chapterAPIPath
data = htmlUtils.getJSON(chapterAPIUrl)
data = data.get("chapter")
chapterName = data.get("name")
images = data.get("images")
if images == None:
print(f"未获取到章节图像 comic_name={bookName} chapter={chapterName}")
totalChapter = x.get("totalChapter")
tags = x.get("tags")
x = tags
print(x)
count_image = 1
list_img = []
list_scramble = []
for image in images:
image_src = image.get("src")
scramble = image.get("scramble")
print("count=",count_image)
list_img.append(image_src)
list_scramble.append(scramble)
print(image_src)
print(scramble)
count_image+=1
print(count_image)
print(list_img)
wait = input("暂停查看数据y/n")
if not wait == "y":
exit()
return list_img
print(totalChapter)
#netUtils.downloadComicChapterImages(list_img,scrambles=list_scramble)
download_images(list_img,comicInfo.getDirComicChapter(),scrambles=list_scramble)