fix rouman

This commit is contained in:
caiwx86 2023-01-09 19:50:57 +08:00
parent fd694cce81
commit 41a1e81fef
7 changed files with 81 additions and 21 deletions

15
main.py
View File

@ -1,16 +1,9 @@
from utils.entity.JMTI import comicEntity
from utils.entity.RouMan import comicEntity
from utils.comic.ComicInfo import comicInfo
import os,shutil
def comics():
for x in range(1,2):
comicEntity.downladsComcis("https://jmcomic.moe/albums/hanman?page="+str(x))
for x in range(0,50):
comicEntity.downladsComcis("https://rm01.xyz/books?&page="+str(x))
if __name__ == '__main__':
# os.environ["http_proxy"] = "http://127.0.0.1:7890"
# os.environ["https_proxy"] = "http://127.0.0.1:7890"
# url = "https://rm01.xyz/books/3700b70b-c5a9-4328-9ae3-cffda6a77339/15"
# comicEntity.comicChapter(url,scramble=True)
# comicEntity.oneComic("https://rm01.xyz/books/c94f80c1-a673-4c74-bb5e-ad5ac7dd766b")
# comicEntity.oneComic("https://jmcomic2.onl/album/403327/")
comicEntity.downladsComcis("https://jmcomic2.onl/albums/hanman?shunt=2")
comics()

View File

@ -75,7 +75,7 @@ class htmlUtils:
if count <= 3:
try:
print(f"请求地址:{curl}")
res = s.get(curl,stream=True, headers=cls.headers, timeout=1000)
res = s.get(curl,stream=True, headers=cls.headers, timeout=180,allow_redirects=True)
if type == "bytes":
url_text = res
if type == "json":
@ -85,8 +85,8 @@ class htmlUtils:
if type == None:
url_text = html.fromstring(res.text)
cls.saveHtml(curl,res.text)
# if res.status_code != 200:
# cls.remove_HtmlCache(curl)
if res.status_code != 200:
cls.remove_HtmlCache(curl)
except:
print(f'Retry! 第{count}')
time.sleep(1)

View File

@ -1,4 +1,5 @@
import base64,hashlib,os,shutil
import math
import numpy as np
from PIL import Image
@ -143,4 +144,57 @@ class imageUtils:
scrambleFileCache = cls.scrambleImage(path)
if not scrambleFileCache == None:
if os.path.exists(scrambleFileCache):
os.remove(scrambleFileCache)
os.remove(scrambleFileCache)
@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)
print("解密成功=",save_path)
if os.path.exists(imgpath):
os.remove(imgpath)
print("remove=",imgpath)

View File

@ -145,6 +145,7 @@ class comicInfo():
root_node = cls.document.createElement(cls.pages)
for page in value:
c_node = cls.document.createElement("Page")
page = page.split("_")[-1]
c_node.setAttribute("Image",page)
root_node.appendChild(c_node)
cls.pages_node = root_node

View File

@ -2,7 +2,8 @@ import os,datetime
from time import strftime
class pathStr:
#base_comic_out = "COMICOUT"
base_comic_out = os.path.join("/mnt", "bigTComics","JM")
#base_comic_out = os.path.join("/mnt", "bigTComics","JM")
base_comic_out = os.path.join("/mnt", "bigTComics")
base_CBZ = os.path.join(base_comic_out,"CBZ")
base_comic_img = os.path.join(base_comic_out,"outputComic")
base_conf_path = os.path.join(base_comic_out,".conf")

View File

@ -12,12 +12,21 @@ from utils.downloader import download_images
from utils.Ntfy import ntfy
from utils.VerUtils import verUtils
from PIL import Image
import get_jm_url
class comicEntity:
count_chapter = 0
aid = None
repeat = 0
@classmethod
def baseReUrl(cls,url):
newurl_list=get_jm_url.app()
if newurl_list:
if re.findall(r'https://(.*?)/\w+/\d+/',url)[0] not in newurl_list:
for newurl in newurl_list:
url = re.sub(re.findall(r'https://(.*?)/\w+/\d+/', url)[0], newurl, url)
return url
@classmethod
def downladsComcis(cls,url):

View File

@ -152,7 +152,8 @@ class comicEntity:
isScramble = str(img).startswith("scramble=")
if isScramble:
c_path = os.path.join(chapter_dir, img)
imageUtils.getScrambleImage(c_path)
#imageUtils.getScrambleImage(c_path)
imageUtils.encode_scramble_image(c_path)
#进入下一阶段
comicInfo.nextImgToDownloadChapter()
return is_next
@ -172,10 +173,6 @@ class comicEntity:
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:
chapterAPIPath = str(chapterAPIPath).encode('utf-8').decode('unicode_escape')
@ -237,6 +234,11 @@ class comicEntity:
except:
ntfy(f"删除失败 {cbz_path}")
if is_next:
pathComicInfo = comicInfo.getPathComicInfoXML()
if not os.path.exists(pathComicInfo):
#print("不存在ComicInfo.xml 生成中...")
comicInfo.setPages(list_fileName)
comicInfo.writeComicInfoXML(chapterName)
ntfy.sendMsg(f"{bookName} {chapterName} 下载中")
download_images(list_img,comicInfo.getDirComicChapter(), filesName=list_fileName)
return is_next