This commit is contained in:
cwx committed 2022-12-13 00:24:45 +08:00
1 parent 3d00520c14
commit 99b2dabd1d
6 files changed
+25 -19

No files matched your search

+2 -1
View File
@@ -2,6 +2,7 @@ import os
from pathlib import Path from pathlib import Path
from zipfile import ZipFile from zipfile import ZipFile
from utils.comic.ComicInfo import comicInfo from utils.comic.ComicInfo import comicInfo
from utils.Ntfy import ntfy
class CBZUtils: class CBZUtils:
@@ -35,7 +36,7 @@ class CBZUtils:
print("打包中:" + str(y) + "/" + str(len(filenames)), os.path.join(source_dir, filename)) print("打包中:" + str(y) + "/" + str(len(filenames)), os.path.join(source_dir, filename))
zf.write(path.joinpath(filename), arc_dir.joinpath(filename)) zf.write(path.joinpath(filename), arc_dir.joinpath(filename))
zf.close() zf.close()
print("打包完成:", target_file) ntfy.sendMsg("打包完成:", target_file)
#md5_file = md5(target_file) #md5_file = md5(target_file)
#print("md5:", md5_file) #print("md5:", md5_file)
#msg[target_file] = md5_file #msg[target_file] = md5_file
+5 -4
View File
@@ -5,6 +5,7 @@ import traceback
import time import time
from urllib3.util.retry import Retry from urllib3.util.retry import Retry
from requests.adapters import HTTPAdapter from requests.adapters import HTTPAdapter
from utils.Ntfy import ntfy
class htmlUtils: class htmlUtils:
headers = {'User-Agent': UserAgent().random} headers = {'User-Agent': UserAgent().random}
@@ -27,20 +28,20 @@ class htmlUtils:
while url_text == None: while url_text == None:
if count <= 10: if count <= 10:
try: try:
print("请求地址:",curl) ntfy.sendMsg(f"请求地址:{curl}")
res = s.get(curl,stream=True, headers=cls.headers, timeout=50) res = s.get(curl,stream=True, headers=cls.headers, timeout=50)
if type == "bytes": if type == "bytes":
url_text = res url_text = res
else: else:
url_text = html.fromstring(res.text) url_text = html.fromstring(res.text)
except: except:
print(f'Retry! 第{count}次') ntfy.sendMsg(f'Retry! 第{count}次')
time.sleep(3) time.sleep(3)
traceback.print_exc() traceback.print_exc()
count += 1 count += 1
continue continue
else: else:
print(f"fail 请求失败:{curl}") ntfy.sendMsg(f"fail 请求失败:{curl}")
break break
if type == "None": if type == "None":
data = { curl : url_text} data = { curl : url_text}
@@ -60,7 +61,7 @@ class htmlUtils:
data_json = res.json() data_json = res.json()
return data_json return data_json
except: except:
print(f"请求失败,重试中...") ntfy.sendMsg(f"请求失败,重试中... {curl}")
count += 1 count += 1
time.sleep(1) time.sleep(1)
cls.getJSON(curl) cls.getJSON(curl)
+1 -7
View File
@@ -91,10 +91,4 @@ class netUtils:
save_path = os.path.join(pathCBZComic,comicInfo.getChapter()+icon_su) save_path = os.path.join(pathCBZComic,comicInfo.getChapter()+icon_su)
shutil.copy(pathComicIcon, save_path) shutil.copy(pathComicIcon, save_path)
print(f"{pathComicIcon} 已复制至: {save_path}") print(f"{pathComicIcon} 已复制至: {save_path}")
comicInfo.nextDownloadToCBZChapter() comicInfo.nextDownloadToCBZChapter()
@classmethod
def sendMsg(cls, msg):
print(f"#ntfy: {msg}")
requests.post("https://ntfy.caiwenxiu.cn/PyComic",
data=msg.encode(encoding='utf-8'))
+8
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'))
+3 -2
View File
@@ -11,6 +11,7 @@ import os
import concurrent.futures import concurrent.futures
import requests import requests
import time import time
from utils.Ntfy import ntfy
headers = { headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "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) image_url, headers=headers, timeout=timeout, proxies=proxies)
while response.status_code != 200 and repair_count <= 5: while response.status_code != 200 and repair_count <= 5:
download_image(image_url,dst_dir,file_name) download_image(image_url,dst_dir,file_name)
print(f'重试:第{repair_count}次 {image_url}') ntfy.sendMsg(f'重试:第{repair_count}次 {image_url}')
repair_count += 1 repair_count += 1
with open(temp_path, 'wb') as f: with open(temp_path, 'wb') as f:
f.write(response.content) 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() response.close()
if repair_count < 5: if repair_count < 5:
time.sleep(1) time.sleep(1)
print("## Repeat: {} {}".format(image_url)) ntfy.sendMsg("## Repeat: {} {}".format(image_url))
download_image(image_url,dst_dir,file_name) download_image(image_url,dst_dir,file_name)
repair_count += 1 repair_count += 1
else: else:
+6 -5
View File
@@ -5,6 +5,7 @@ from utils.ImageUtils import imageUtils
from utils.comic.ComicInfo import comicInfo from utils.comic.ComicInfo import comicInfo
from utils.CBZUtils import CBZUtils from utils.CBZUtils import CBZUtils
from utils.downloader import download_images from utils.downloader import download_images
from utils.Ntfy import ntfy
class comicEntity: class comicEntity:
@@ -33,7 +34,7 @@ class comicEntity:
comicInfo.setComicName(book_name) comicInfo.setComicName(book_name)
#dirConfComic = comicInfo.getDirConfComic() #dirConfComic = comicInfo.getDirConfComic()
#if not os.path.exists(dirConfComic): #if not os.path.exists(dirConfComic):
netUtils.sendMsg(f"{random_int}秒后开始下载 漫画:{book_name}") ntfy.sendMsg(f"{random_int}秒后开始下载 漫画:{book_name}")
time.sleep(random_int) time.sleep(random_int)
cls.oneComic(comicHref, random.uniform(0,3)) cls.oneComic(comicHref, random.uniform(0,3))
@@ -106,14 +107,14 @@ class comicEntity:
#完成删除原文件 #完成删除原文件
remove_path = comicInfo.getDirComicChapter() remove_path = comicInfo.getDirComicChapter()
shutil.rmtree(remove_path) shutil.rmtree(remove_path)
netUtils.sendMsg(f"文件已删除: {remove_path}") ntfy.sendMsg(f"文件已删除: {remove_path}")
except: except:
dirComicChapter = comicInfo.getDirComicChapter dirComicChapter = comicInfo.getDirComicChapter
if not dirComicChapter == None and os.path.exists(dirComicChapter): if not dirComicChapter == None and os.path.exists(dirComicChapter):
shutil.rmtree(dirComicChapter) shutil.rmtree(dirComicChapter)
cls.comicChapter(chapter_url,scramble,sleep) cls.comicChapter(chapter_url,scramble,sleep)
if not sleep == None: if not sleep == None:
netUtils.sendMsg(f"{sleep} 秒后开始下载下一个章节") ntfy.sendMsg(f"{sleep} 秒后开始下载下一个章节")
time.sleep(sleep) time.sleep(sleep)
@classmethod @classmethod
@@ -149,7 +150,7 @@ class comicEntity:
description = x.get("description") description = x.get("description")
images = x.get("images") images = x.get("images")
chapterAPIPath = x.get("chapterAPIPath") chapterAPIPath = x.get("chapterAPIPath")
netUtils.sendMsg(f"{bookName} {chapterName} 下载中") ntfy.sendMsg(f"{bookName} {chapterName} 下载中")
comicInfo.setComicName(bookName) comicInfo.setComicName(bookName)
comicInfo.setChapterName(chapterName) comicInfo.setChapterName(chapterName)
comicInfo.setDep(description) comicInfo.setDep(description)
@@ -166,7 +167,7 @@ class comicEntity:
chapterName = data.get("name") chapterName = data.get("name")
images = data.get("images") images = data.get("images")
if images == None: if images == None:
netUtils.sendMsg(f"未获取到章节图像 comic_name={bookName} chapter={chapterName}") ntfy.sendMsg(f"未获取到章节图像 comic_name={bookName} chapter={chapterName}")
totalChapter = x.get("totalChapter") totalChapter = x.get("totalChapter")
tags = x.get("tags") tags = x.get("tags")
x = tags x = tags