fix
This commit is contained in:
1 parent
f6f6b41c5f
commit
4667afe295
3 files changed
+67
-39
No files matched your search
+56
-16
@@ -45,18 +45,7 @@ class CBZUtils:
|
|||||||
zf.write(path.joinpath(filename), arc_dir.joinpath(filename))
|
zf.write(path.joinpath(filename), arc_dir.joinpath(filename))
|
||||||
zf.close()
|
zf.close()
|
||||||
ntfy.sendMsg(f"打包完成:{target_file}")
|
ntfy.sendMsg(f"打包完成:{target_file}")
|
||||||
else:
|
cls.verCBZComic(target_file)
|
||||||
print("文件已存在:", target_file)
|
|
||||||
len_chapter_imgs = len(comicInfo.getChapterImgs())
|
|
||||||
if len_chapter_imgs != 0 and len_chapter_imgs != len(cls.zip_info(target_file)):
|
|
||||||
try:
|
|
||||||
os.remove(target_file)
|
|
||||||
comicInfo.setProgress(comicInfo.PROGRESS_NONE)
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
if remove:
|
|
||||||
filenames.remove(comicInfo.COMIC_ICON_NAME+".jpg")
|
|
||||||
filenames.remove(comicInfo.COMIC_INFO_XML)
|
|
||||||
return filenames
|
return filenames
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -72,9 +61,7 @@ class CBZUtils:
|
|||||||
print(f"删除 {file} 发生错误,已跳过")
|
print(f"删除 {file} 发生错误,已跳过")
|
||||||
cls.zip_compression(comicInfo.getDirComicChapter(), cls.getCBZ_Path())
|
cls.zip_compression(comicInfo.getDirComicChapter(), cls.getCBZ_Path())
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
fileUtils.remove(comicInfo.getDirComicChapter())
|
fileUtils.remove(comicInfo.getDirComic())
|
||||||
cls.zip_compression(comicInfo.getDirComicChapter(), cls.getCBZ_Path())
|
|
||||||
verUtils.verNextCBZ()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def replaceZip(cls,filepath,unpack_dir=None):
|
def replaceZip(cls,filepath,unpack_dir=None):
|
||||||
@@ -127,9 +114,62 @@ class CBZUtils:
|
|||||||
print(e)
|
print(e)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def verCBZComic(cls,path=None,list_img=None):
|
||||||
|
if path == None:
|
||||||
|
path = cls.getCBZ_Path()
|
||||||
|
if list_img == None:
|
||||||
|
list_img = comicInfo.getChapterImgs()
|
||||||
|
if not os.path.exists(path): return False
|
||||||
|
if os.path.exists(path) and len(cls.zip_info(path)) == len(list_img):
|
||||||
|
print(f"文件校验成功:{path}")
|
||||||
|
comicInfo.setProgress(comicInfo.PROGRESS_DONE)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
print(f"文件删除中:{path}")
|
||||||
|
os.remove(path)
|
||||||
|
comicInfo.setProgress(comicInfo.PROGRESS_NONE)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return False
|
||||||
|
return False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def existsUnzipCBZ(cls,filesname,result=False):
|
||||||
|
unzip_base_path = pathStr.base_unzip_path
|
||||||
|
zipfile_path = os.path.join(unzip_base_path,comicInfo.str_comic_name,comicInfo.str_chapter+".CBZ")
|
||||||
|
#判断是否存在已下载CBZ文件
|
||||||
|
if os.path.exists(zipfile_path) and not os.path.exists(CBZUtils.getCBZ_Path()):
|
||||||
|
print(f"存在CBZ文件{zipfile_path},解压中")
|
||||||
|
zip_file = ZipFile(zipfile_path)
|
||||||
|
#CBZ中文件数量,剔除ComicInfo.xml
|
||||||
|
if len(filesname) == len(zip_file.namelist())-1:
|
||||||
|
unzip_path = comicInfo.getDirComicChapter()
|
||||||
|
zip_file.extractall(unzip_path)
|
||||||
|
zip_file.close()
|
||||||
|
print(f"解压完成: CBZ文件{zipfile_path}")
|
||||||
|
print(f"文件校验中")
|
||||||
|
for file in os.listdir(unzip_path):
|
||||||
|
if file.endswith(".jpg") and not fileUtils.ver_file(os.path.join(unzip_path,file),type="image"):
|
||||||
|
#清空文件
|
||||||
|
try:
|
||||||
|
shutil.rmtree(unzip_path)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return False
|
||||||
|
comicInfo.writeComicInfoXML(overlay=True)
|
||||||
|
result = True
|
||||||
|
return result
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def nextCBZ(cls,list_img=None):
|
||||||
|
return not cls.verCBZComic(list_img=list_img)
|
||||||
|
|
||||||
|
|
||||||
class verUtils:
|
class verUtils:
|
||||||
@classmethod
|
@classmethod
|
||||||
def verNextCBZ(cls,list_img=None):
|
def depverNextCBZ(cls,list_img=None):
|
||||||
#验证数据是已存在且是否完整
|
#验证数据是已存在且是否完整
|
||||||
if list_img == None:
|
if list_img == None:
|
||||||
comicInfo.getChapterImgs()
|
comicInfo.getChapterImgs()
|
||||||
|
|||||||
+4
-4
@@ -9,19 +9,19 @@ class imageUtils:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def encodeImage(cls,str_en):
|
def encodeImage(cls,str_en):
|
||||||
print("en",str_en)
|
#print("en",str_en)
|
||||||
enc = base64.b64decode(str_en)
|
enc = base64.b64decode(str_en)
|
||||||
print("解密:",enc)
|
#print("解密:",enc)
|
||||||
m = hashlib.md5()
|
m = hashlib.md5()
|
||||||
m.update(enc)
|
m.update(enc)
|
||||||
md5 = m.digest()
|
md5 = m.digest()
|
||||||
d = md5[-1]
|
d = md5[-1]
|
||||||
print(md5)
|
#print(md5)
|
||||||
try:
|
try:
|
||||||
blocks = d % 10 + 5
|
blocks = d % 10 + 5
|
||||||
except:
|
except:
|
||||||
blocks = 0 %10 + 5
|
blocks = 0 %10 + 5
|
||||||
print("blocks=",blocks)
|
#print("blocks=",blocks)
|
||||||
return blocks
|
return blocks
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ class baseComic:
|
|||||||
读取某章节下所有图片
|
读取某章节下所有图片
|
||||||
'''
|
'''
|
||||||
@classmethod
|
@classmethod
|
||||||
def comicChapter(cls,chapter_url,scramble=None,sleep=None):
|
def comicChapter(cls,chapter_url,scramble=None,sleep=None,is_next=True):
|
||||||
is_next = True
|
|
||||||
try:
|
try:
|
||||||
is_next = cls.Onechapter(chapter_url,scramble)
|
is_next = cls.Onechapter(chapter_url,scramble)
|
||||||
#进入下个阶段
|
#进入下个阶段
|
||||||
@@ -78,7 +77,7 @@ class baseComic:
|
|||||||
except Exception as e: is_next = ntfy.sendMsg(f"{ci.getComicName()} 下载出错了",error=e)
|
except Exception as e: is_next = ntfy.sendMsg(f"{ci.getComicName()} 下载出错了",error=e)
|
||||||
ntfy.sendMsg(f"预计总章节大小:{cls.count_chapter + 1} / "+ str(ci.getLenChapters()))
|
ntfy.sendMsg(f"预计总章节大小:{cls.count_chapter + 1} / "+ str(ci.getLenChapters()))
|
||||||
ci.setChapterIndex(cls.count_chapter + 1)
|
ci.setChapterIndex(cls.count_chapter + 1)
|
||||||
if sleep != None and is_next == True: ntfy.sendMsg(f"{sleep} 秒后开始下载下一个章节",sleep=sleep)
|
if sleep != None and is_next: ntfy.sendMsg(f"{sleep} 秒后开始下载下一个章节",sleep=sleep)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -120,31 +119,20 @@ class baseComic:
|
|||||||
cbz_path = ci.getNewCBZComicChapter()+".CBZ"
|
cbz_path = ci.getNewCBZComicChapter()+".CBZ"
|
||||||
#更新Icon
|
#更新Icon
|
||||||
ci.getNewIconComicChapter()
|
ci.getNewIconComicChapter()
|
||||||
if os.path.exists(cbz_path):
|
if os.path.exists(cbz_path): CBZUtils.verCBZComic(cbz_path)
|
||||||
if CBZUtils.PackCBZAndequZipLength:
|
|
||||||
ntfy.sendMsg(f"{book_name} {chapter_name} 数据完整,已跳过")
|
|
||||||
ci.nextDoneSave(list_img)
|
|
||||||
is_next = False
|
|
||||||
else:
|
|
||||||
ntfy.sendMsg(f"{book_name} {chapter_name} 数据不完整,尝试删除配置CBZ文件后重试")
|
|
||||||
try:
|
|
||||||
if os.path.getsize(cbz_path) < 300000: fileUtils.remove(cbz_path)
|
|
||||||
else: is_next = False
|
|
||||||
except:
|
|
||||||
ntfy(f"删除失败 {cbz_path}")
|
|
||||||
if is_next:
|
if is_next:
|
||||||
if not os.path.exists(ci.getPathComicInfoXML()):
|
if not os.path.exists(ci.getPathComicInfoXML()):
|
||||||
#print("不存在ComicInfo.xml 生成中...")
|
#print("不存在ComicInfo.xml 生成中...")
|
||||||
ci.setPages(files_name)
|
ci.setPages(files_name)
|
||||||
ci.writeComicInfoXML(chapter_name)
|
ci.writeComicInfoXML(chapter_name)
|
||||||
ntfy.sendMsg(f"{book_name} {chapter_name} 下载中")
|
ntfy.sendMsg(f"{book_name} {chapter_name} 下载中")
|
||||||
is_next = verUtils.verNextCBZ(list_img)
|
is_next = CBZUtils.nextCBZ(list_img)
|
||||||
is_unzip = verUtils.existsUnzipCBZ(files_name)
|
is_unzip = CBZUtils.existsUnzipCBZ(files_name)
|
||||||
repeat = 1
|
repeat = 1
|
||||||
while not is_next and repeat <= 2 and not is_unzip:
|
while is_next and repeat <= 2 and not is_unzip:
|
||||||
download_images(list_img,ci.getDirComicChapter(), files_name=files_name,concurrency=10,timeout=60)
|
download_images(list_img,ci.getDirComicChapter(), files_name=files_name,concurrency=10,timeout=60)
|
||||||
is_next = len(",".join(os.listdir(ci.getDirComicChapter())).split(".jpg"))-1 == len(list_img)
|
is_next = len(",".join(os.listdir(ci.getDirComicChapter())).split(".jpg"))-1 == len(list_img)
|
||||||
if not is_next:
|
if is_next:
|
||||||
sleep_time = 3+int(repeat)*2
|
sleep_time = 3+int(repeat)*2
|
||||||
time.sleep(sleep_time)
|
time.sleep(sleep_time)
|
||||||
ntfy.sendMsg(f"下载数据(不完整,{sleep_time}秒钟后尝试第{repeat}次")
|
ntfy.sendMsg(f"下载数据(不完整,{sleep_time}秒钟后尝试第{repeat}次")
|
||||||
|
|||||||
Reference in new issue
Block a user