This commit is contained in:
caiwx86 2022-12-13 06:36:57 +08:00
commit 9c9ce77e71
6 changed files with 29 additions and 14 deletions

View File

@ -2,6 +2,7 @@ import os
from pathlib import Path
from zipfile import ZipFile
from utils.comic.ComicInfo import comicInfo
from utils.Ntfy import ntfy
class CBZUtils:
@ -35,7 +36,7 @@ class CBZUtils:
print("打包中:" + str(y) + "/" + str(len(filenames)), os.path.join(source_dir, filename))
zf.write(path.joinpath(filename), arc_dir.joinpath(filename))
zf.close()
print("打包完成:", target_file)
ntfy.sendMsg(f"打包完成:{target_file}")
#md5_file = md5(target_file)
#print("md5:", md5_file)
#msg[target_file] = md5_file

View File

@ -5,6 +5,7 @@ import traceback
import time
from urllib3.util.retry import Retry
from requests.adapters import HTTPAdapter
from utils.Ntfy import ntfy
class htmlUtils:
headers = {'User-Agent': UserAgent().random}
@ -27,20 +28,20 @@ class htmlUtils:
while url_text == None:
if count <= 10:
try:
print("请求地址:",curl)
print(f"请求地址:{curl}")
res = s.get(curl,stream=True, headers=cls.headers, timeout=50)
if type == "bytes":
url_text = res
else:
url_text = html.fromstring(res.text)
except:
print(f'Retry! 第{count}')
ntfy.sendMsg(f'Retry! 第{count}')
time.sleep(3)
traceback.print_exc()
count += 1
continue
else:
print(f"fail 请求失败:{curl}")
ntfy.sendMsg(f"fail 请求失败:{curl}")
break
if type == "None":
data = { curl : url_text}
@ -60,7 +61,7 @@ class htmlUtils:
data_json = res.json()
return data_json
except:
print(f"请求失败,重试中...")
ntfy.sendMsg(f"请求失败,重试中... {curl}")
count += 1
time.sleep(1)
cls.getJSON(curl)

View File

@ -91,4 +91,4 @@ class netUtils:
save_path = os.path.join(pathCBZComic,comicInfo.getChapter()+icon_su)
shutil.copy(pathComicIcon, save_path)
print(f"{pathComicIcon} 已复制至: {save_path}")
comicInfo.nextDownloadToCBZChapter()
comicInfo.nextDownloadToCBZChapter()

8
utils/Ntfy.py Normal file
View File

@ -0,0 +1,8 @@
import requests
class ntfy:
@classmethod
def sendMsg(cls, msg):
print(f"#ntfy: {msg}")
requests.post("https://ntfy.caiwenxiu.cn/PyComic",
data=msg.encode(encoding='utf-8'))

View File

@ -11,6 +11,7 @@ import os
import concurrent.futures
import requests
import time
from utils.Ntfy import ntfy
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
@ -39,7 +40,7 @@ def download_image(image_url, dst_dir, file_name, timeout=20, proxy_type=None, p
image_url, headers=headers, timeout=timeout, proxies=proxies)
while response.status_code != 200 and repair_count <= 5:
download_image(image_url,dst_dir,file_name)
print(f'重试:第{repair_count}{image_url}')
ntfy.sendMsg(f'重试:第{repair_count}{image_url}')
repair_count += 1
with open(temp_path, 'wb') as f:
f.write(response.content)
@ -51,7 +52,7 @@ def download_image(image_url, dst_dir, file_name, timeout=20, proxy_type=None, p
response.close()
if repair_count < 5:
time.sleep(1)
print("## Repeat: {} {}".format(image_url))
ntfy.sendMsg("## Repeat: {} {}".format(image_url))
download_image(image_url,dst_dir,file_name)
repair_count += 1
else:

View File

@ -5,6 +5,7 @@ from utils.ImageUtils import imageUtils
from utils.comic.ComicInfo import comicInfo
from utils.CBZUtils import CBZUtils
from utils.downloader import download_images
from utils.Ntfy import ntfy
class comicEntity:
@ -29,13 +30,15 @@ class comicEntity:
book_name = book.get("name")
updatedAt = book.get("updatedAt")
comicHref = baseUrl+"/books/"+book_id
random_int = random.uniform(5,20)
random_int = random.randint(5,20)
comicInfo.setComicName(book_name)
dirConfComic = comicInfo.getDirConfComic()
if not os.path.exists(dirConfComic):
print(f"{random_int}秒后开始下载 漫画:{book_name}")
ntfy.sendMsg(f"{random_int}秒后开始下载 漫画:{book_name}")
time.sleep(random_int)
cls.oneComic(comicHref, random.uniform(0,3))
else:
ntfy.sendMsg(f"已存在 漫画:{book_name}")
cls.oneComic(comicHref, random.uniform(0,3))
print(books)
#for comicHref in comicsHref:
@ -76,7 +79,7 @@ class comicEntity:
chapter = chapters[count_chapter]
comicInfo.setChapterName(chapter)
if not comicInfo.nextExistsGetPath("done_"):
comicEntity.comicChapter(href,scramble=True,sleep=random.uniform(15,25))
comicEntity.comicChapter(href,scramble=True,sleep=random.randint(15,25))
count_chapter += 1
#一本漫画下载后等待
#清空文件夹
@ -113,7 +116,7 @@ class comicEntity:
shutil.rmtree(dirComicChapter)
cls.comicChapter(chapter_url,scramble,sleep)
if not sleep == None:
print(f"{sleep} 秒后开始下载下一个章节")
ntfy.sendMsg(f"{sleep} 秒后开始下载下一个章节")
time.sleep(sleep)
@classmethod
@ -149,6 +152,7 @@ class comicEntity:
description = x.get("description")
images = x.get("images")
chapterAPIPath = x.get("chapterAPIPath")
ntfy.sendMsg(f"{bookName} {chapterName} 下载中")
comicInfo.setComicName(bookName)
comicInfo.setChapterName(chapterName)
comicInfo.setDep(description)
@ -165,7 +169,7 @@ class comicEntity:
chapterName = data.get("name")
images = data.get("images")
if images == None:
print(f"未获取到章节图像 comic_name={bookName} chapter={chapterName}")
ntfy.sendMsg(f"未获取到章节图像 comic_name={bookName} chapter={chapterName}")
totalChapter = x.get("totalChapter")
tags = x.get("tags")
x = tags