This commit is contained in:
cwx committed 2023-03-30 02:01:06 +08:00
1 parent eaf15969f0
commit 25be464102
8 files changed
+119 -121

No files matched your search

Binary file not shown.
+16 -25
View File
@@ -5,33 +5,24 @@ from utils.downloader import download_images
from utils.base.BaseComicEntity import baseComic from utils.base.BaseComicEntity import baseComic
class comicEntity: class comicEntity:
@classmethod
def baseComicData(cls,url,update=False):
data = htmlUtils.xpathData('//script[@id="__NEXT_DATA__"]/text()',url=url,update=update)
data = json.loads(data[0])
data = data.get("props")
x = data.get("pageProps")
return x
@classmethod
def downladsComcis(cls,url):
#漫画名
x = cls.baseComicData(url,True)
books = x.get("books")
len_books = len(books)
base_url = comicInfo.getBaseUrl(url)
for x in range(0, len_books):
book = books[x]
book_id = book.get("id")
book_name = book.get("name")
updated = book.get("updatedAt")
comic_href = base_url+"/books/"+book_id
comicInfo.setUpdateAt(updated)
comicInfo.setComicName(book_name)
cls.oneComic(baseComic.comics(book_name=book_name,comic_href=comic_href,updated=updated),date=updated)
@classmethod @classmethod
def oneComic(cls,c_url,sleep=None,date=None): def booksJson(cls,url,update=False):
data = htmlUtils.xpathData('//script[@id="__NEXT_DATA__"]/text()',url=url,update=update)
return json.loads(data[0]).get("props").get("pageProps").get("books")
@classmethod
def downladsComcis(cls,url):
#漫画名
books = cls.booksJson(url,True)
for x in range(0, len(books)):
comicInfo.setComicInfo(comicname=books[x].get("name"),
current_chapter_img=comicInfo.getBaseUrl(url)+"/books/"+books[x].get("id"),
update_at=books[x].get("updatedAt"))
cls.oneComic(baseComic.updateComics())
@classmethod
def oneComic(cls,c_url,sleep=None,date=comicInfo.getUpdateAt()):
if c_url == None: return None if c_url == None: return None
#漫画名 #漫画名
title = htmlUtils.xpathData('//div[@class="col"]/h5/text()',url=c_url,num=0,update=True) title = htmlUtils.xpathData('//div[@class="col"]/h5/text()',url=c_url,num=0,update=True)
+29 -40
View File
@@ -5,7 +5,7 @@ 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 from utils.Ntfy import ntfy
from utils.FileUtils import fileUtils from utils.FileUtils import fileUtils as fu
from utils.comic.PathStr import pathStr from utils.comic.PathStr import pathStr
class CBZUtils: class CBZUtils:
@@ -14,7 +14,7 @@ class CBZUtils:
def getCBZ_Dir(cls): return comicInfo.getNewCBZComicChapter() def getCBZ_Dir(cls): return comicInfo.getNewCBZComicChapter()
@classmethod @classmethod
def getCBZ_Path(cls): return cls.getCBZ_Dir()+".CBZ" def getCBZ_Path(cls): return comicInfo.getNewFileCBZComicChapter()
@classmethod @classmethod
def readDirsOrFiles(cls,dir,type): def readDirsOrFiles(cls,dir,type):
@@ -62,7 +62,7 @@ class CBZUtils:
return False return False
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()) fu.remove(comicInfo.getDirComicChapter())
return True return True
@classmethod @classmethod
@@ -82,14 +82,7 @@ class CBZUtils:
print(f"已更新文件时间 {filepath}") print(f"已更新文件时间 {filepath}")
if os.path.exists(unpack_dir): if os.path.exists(unpack_dir):
shutil.rmtree(unpack_dir) shutil.rmtree(unpack_dir)
# 删除删除main.ftl文件
#delete_filename = ''
#if os.path.exists(delete_filename):
# os.remove(delete_filename)
# time.sleep(60)
# shutil.copy(文件的路径,另一个目录);拷贝main.ftl到准备压缩的目录下
#cls.zip_compression()
#小于则运行
@classmethod @classmethod
def compareFileDate(cls,filepath): def compareFileDate(cls,filepath):
if os.path.exists(filepath): if os.path.exists(filepath):
@@ -110,57 +103,53 @@ class CBZUtils:
with ZipFile(path, "r") as zip_file: with ZipFile(path, "r") as zip_file:
result = zip_file.namelist() result = zip_file.namelist()
if filter: if filter:
result.remove(comicInfo.COMIC_ICON_NAME+".jpg") filter_icon = comicInfo.COMIC_ICON_NAME+".jpg"
result.remove(comicInfo.COMIC_INFO_XML) filter_info_xml = comicInfo.COMIC_INFO_XML
if filter_icon in result: result.remove(filter_icon)
if filter_info_xml in result: result.remove(filter_info_xml)
except Exception as e: except Exception as e:
print(e) print(e)
return result return result
#CBZ检验是否完整
@classmethod @classmethod
def verCBZComic(cls,path=None,list_img=None): def verCBZComic(cls,path=None,list_img=None,min_size=300000):
if path == None: #数据检验
path = cls.getCBZ_Path() if path == None: path = cls.getCBZ_Path()
if list_img == None: #文件不存在 则返回
list_img = comicInfo.getChapterImgs() if fu.notExists(path): return False
if not os.path.exists(path): return False if list_img == None: list_img = comicInfo.getChapterImgs()
if os.path.exists(path) and len(cls.zip_info(path)) == len(list_img):
if fu.exists(path) and len(cls.zip_info(path)) == len(list_img):
print(f"文件校验成功:{path}") print(f"文件校验成功:{path}")
comicInfo.setProgress(comicInfo.PROGRESS_DONE) comicInfo.setProgress(comicInfo.PROGRESS_DONE)
return True return True
else: else:
try: try:
if len(cls.zip_info(path)) < len(list_img) or os.path.getsize(path) < 300000: if len(cls.zip_info(path)) < len(list_img) or os.path.getsize(path) < min_size:
print(f"文件删除中:{path}") fu.remove(path)
os.remove(path)
comicInfo.setProgress(comicInfo.PROGRESS_NONE) comicInfo.setProgress(comicInfo.PROGRESS_NONE)
except Exception as e: except Exception as e:
print(e) print(e)
return False
return False return False
@classmethod @classmethod
def existsUnzipCBZ(cls,filesname,result=False): def updateOldCBZ(cls,filesname,result=False):
unzip_base_path = pathStr.base_unzip_path old_zipfile_path = os.path.join(pathStr.old_cbz_path,comicInfo.str_comic_name,comicInfo.str_chapter+".CBZ")
zipfile_path = os.path.join(unzip_base_path,comicInfo.str_comic_name,comicInfo.str_chapter+".CBZ")
#判断是否存在已下载CBZ文件 #判断是否存在已下载CBZ文件
if os.path.exists(zipfile_path) and not os.path.exists(CBZUtils.getCBZ_Path()): if fu.exists(old_zipfile_path) and fu.notExists(CBZUtils.getCBZ_Path()):
print(f"存在CBZ文件{zipfile_path},解压中") print(f"存在CBZ文件{old_zipfile_path},解压中...")
zip_file = ZipFile(zipfile_path) zip_file = ZipFile(old_zipfile_path)
#CBZ中文件数量,剔除ComicInfo.xml #CBZ中文件数量,剔除ComicInfo.xml
if len(filesname) == len(zip_file.namelist())-1: if len(filesname) == len(zip_file.namelist())-1:
unzip_path = comicInfo.getDirComicChapter() unzip_path = comicInfo.getDirComicChapter()
zip_file.extractall(unzip_path) zip_file.extractall(unzip_path)
zip_file.close() zip_file.close()
print(f"解压完成: CBZ文件{zipfile_path}") print(f"解压完成: CBZ文件{old_zipfile_path}")
print(f"文件校验中") print("文件校验中...")
for file in os.listdir(unzip_path): for file in os.listdir(unzip_path):
if file.endswith(".jpg") and not fileUtils.ver_file(os.path.join(unzip_path,file),type="image"): #检验图片损坏则删除
#清空文件 if file.endswith(".jpg") and not fu.ver_file(os.path.join(unzip_path,file),type="image"): fu.remove(unzip_path)
try:
shutil.rmtree(unzip_path)
except Exception as e:
print(e)
return False
comicInfo.writeComicInfoXML(overlay=True) comicInfo.writeComicInfoXML(overlay=True)
result = True result = True
return result return result
+6
View File
@@ -203,6 +203,9 @@ class fileUtils:
@classmethod @classmethod
def exists(cls,path): def exists(cls,path):
return os.path.exists(path) return os.path.exists(path)
@classmethod
def notExists(cls,path):
return not cls.exists(path)
@classmethod @classmethod
def ver_file(cls,file_path,type): def ver_file(cls,file_path,type):
@@ -234,13 +237,16 @@ class fileUtils:
if not os.path.exists(path): if not os.path.exists(path):
return None return None
try: try:
print(f"{path} 删除中...")
if os.path.isfile(path): if os.path.isfile(path):
os.remove(path) os.remove(path)
if os.path.isdir(path): if os.path.isdir(path):
shutil.rmtree(path) shutil.rmtree(path)
print(f"已删除:{path}") print(f"已删除:{path}")
return True
except: except:
print(f"删除错误:{path}") print(f"删除错误:{path}")
return False
class dbUtils: class dbUtils:
@classmethod @classmethod
+27 -30
View File
@@ -10,19 +10,21 @@ from entity.down.RouMan import comicCommon as RouManComicCommon
from entity.down.JM import comicCommon as JMComicCommon from entity.down.JM import comicCommon as JMComicCommon
from entity.down.BaoZi import comicCommon as BaoZiComicCommon from entity.down.BaoZi import comicCommon as BaoZiComicCommon
from utils.comic.PathStr import pathStr from utils.comic.PathStr import pathStr
from utils.FileUtils import fileUtils from utils.FileUtils import fileUtils as fu
class baseComic: class baseComic:
count_chapter = 0 count_chapter = 0
#校验该漫画是否为最新
# Y/跳过 N/下载 返回下载链接
@classmethod @classmethod
def comics(cls,book_name,comic_href,updated=None): def updateComics(cls):
#不判断是否为空,ComicInfo方法内会自动判断 (book_name,comic_href,updated) = [ci.getComicName(),ci.getCurrentChapterImg(),ci.getUpdateAt()]
ci.setComicInfo(comicname=book_name,update_at=updated)
#白名单跳过 #白名单跳过
if ci.getIsComicNameSkips(book_name): return None if ci.getIsComicNameSkips(book_name): return None
if not os.path.exists(ci.getDirConfComic()): ntfy.sendMsg(f"{random.randint(5,20)}秒后开始下载 漫画:{book_name}") if not ci.isUpdateComic():
else: ntfy.sendMsg(f"已存在 漫画:{book_name}") ntfy.sendMsg(f"开始下载 漫画:{book_name}")
if not ci.isUpdateComic(): return comic_href return comic_href
else: else:
ntfy.sendMsg(f"{book_name} 已是最新") ntfy.sendMsg(f"{book_name} 已是最新")
chapters = htmlUtils.xpathData('//div[contains(@class,"bookid_chapterBox")]//div[contains(@class,"bookid_chapter")]/a/text()',url=comic_href,update=False) chapters = htmlUtils.xpathData('//div[contains(@class,"bookid_chapterBox")]//div[contains(@class,"bookid_chapter")]/a/text()',url=comic_href,update=False)
@@ -49,13 +51,10 @@ class baseComic:
for href in chapter_href: for href in chapter_href:
ci.setChapterName(chapters[cls.count_chapter]) ci.setChapterName(chapters[cls.count_chapter])
ci.setChapterIndex(cls.count_chapter+1) ci.setChapterIndex(cls.count_chapter+1)
if ci.isProgress(ci.PROGRESS_DONE) and not os.path.exists(ci.getNewCBZComicChapter("file")): ci.isProgress(ci.PROGRESS_DONE,remove=True) #存在完成配置文件 但文件不存在 将清空完成配置文件
if not ci.isProgress(ci.PROGRESS_DONE): cls.comicChapter(href,scramble=True,sleep=random.randint(5,15)) if ci.isProgress(ci.PROGRESS_DONE) and not fu.exists(ci.getNewCBZComicChapter("file")): ci.isProgress(ci.PROGRESS_DONE,remove=True)
#存在就校验CBZ包是否完整 #不存在完成配置文件 则允许下载
#if ci.nextExistsGetPath("done_"): if not ci.isProgress(ci.PROGRESS_DONE): cls.comicChapters(href,scramble=True,sleep=random.randint(5,15))
# verUtils.verCBZ()
#if ci.isProgress(ci.PROGRESS_DONE):
# CBZUtils.verCBZComic()
cls.count_chapter += 1 cls.count_chapter += 1
#一本漫画下载后等待 #一本漫画下载后等待
#清空文件夹 #清空文件夹
@@ -67,9 +66,9 @@ class baseComic:
读取某章节下所有图片 读取某章节下所有图片
''' '''
@classmethod @classmethod
def comicChapter(cls,chapter_url,scramble=None,sleep=None,is_next=True): def comicChapters(cls,chapter_url,scramble=None,sleep=None):
try: try:
is_next = cls.Onechapter(chapter_url,scramble) cls.Onechapter(chapter_url,scramble)
#进入下个阶段 #进入下个阶段
#章节图片全部下载后,调用下载封面 #章节图片全部下载后,调用下载封面
if ci.isProgress(ci.PROGRESS_DOWN): download_comic_icon() if ci.isProgress(ci.PROGRESS_DOWN): download_comic_icon()
@@ -80,15 +79,14 @@ class baseComic:
ci.setChapterIndex(cls.count_chapter + 1) ci.setChapterIndex(cls.count_chapter + 1)
if sleep != None and is_next: ntfy.sendMsg(f"{sleep} 秒后开始下载下一个章节",sleep=sleep) if sleep != None and is_next: ntfy.sendMsg(f"{sleep} 秒后开始下载下一个章节",sleep=sleep)
#根据章节地址下载全部图片,并将文件名scramble开头的图片进行解密
@classmethod @classmethod
def Onechapter(cls,chapter_url,scramble=None): def Onechapter(cls,chapter_url,scramble=None):
is_next = True is_next = True
if not str(chapter_url).startswith("http"): chapter_url = ci.getBaseUrl() + chapter_url if not str(chapter_url).startswith("http"): chapter_url = ci.getBaseUrl() + chapter_url
try: #下载图片
is_next = cls.comicChapterDownload(chapter_url) try: is_next = cls.comicChapterDownload(chapter_url)
except: except: htmlUtils.remove_HtmlCache(chapter_url)
htmlUtils.remove_HtmlCache(chapter_url)
ci.nextInfoToImgChapter() ci.nextInfoToImgChapter()
#下载完成后, 开始解密图片 #下载完成后, 开始解密图片
chapter_dir = ci.getDirComicChapter() chapter_dir = ci.getDirComicChapter()
@@ -103,33 +101,32 @@ class baseComic:
@classmethod @classmethod
def comicChapterDownload(cls,url,is_next=True): def comicChapterDownload(cls,url,is_next=True):
#获取本次工程的HOME目录
comic_main = pathStr.getComicMain() comic_main = pathStr.getComicMain()
if comic_main == pathStr.comic_jm: JMComicCommon.comicChapterDownload(url) if comic_main == pathStr.comic_jm: JMComicCommon.comicChapterDownload(url)
if comic_main == pathStr.comic_bz: BaoZiComicCommon.comicChapterDownload(url) if comic_main == pathStr.comic_bz: BaoZiComicCommon.comicChapterDownload(url)
if comic_main == pathStr.comic_rm: RouManComicCommon.comicChapterDownload(url) if comic_main == pathStr.comic_rm: RouManComicCommon.comicChapterDownload(url)
if comic_main == None: print("comic_main为空,退出中...") & exit() if comic_main == None: print("comic_main为空,退出中...") & exit()
list_img = ci.getChapterListImg()
files_name = ci.getChapterFilesName() (list_img,files_name,chapter_name,book_name) = [ci.getChapterListImg(),ci.getChapterFilesName(),ci.getChapter(),ci.getComicName()]
chapter_name = ci.getChapter()
book_name = ci.getComicName()
ci.setChapterImgs(list_img) ci.setChapterImgs(list_img)
#保存信息 #保存信息
ci.nextSaveInfoChapter(chapter_name, list_img) ci.nextSaveInfoChapter(chapter_name, list_img)
#验证数据是已存在且是否完整 #验证数据是已存在且是否完整
#cbz_path = ci.getDirCBZComicChapter()+".CBZ" #cbz_path = ci.getDirCBZComicChapter()+".CBZ"
cbz_path = ci.getNewCBZComicChapter()+".CBZ" cbz_file = ci.getNewFileCBZComicChapter()
#更新Icon #更新Icon
ci.getNewIconComicChapter() ci.getNewIconComicChapter()
if os.path.exists(cbz_path): CBZUtils.verCBZComic(cbz_path) #检验CBZ文件
CBZUtils.verCBZComic(cbz_file)
is_unzip = CBZUtils.existsUnzipCBZ(files_name) if is_next and fu.notExists(ci.getPathComicInfoXML()):
if is_next and 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)
is_next = CBZUtils.nextCBZ(list_img) is_next = CBZUtils.nextCBZ(list_img)
repeat = 1 repeat = 1
while is_next and repeat <= 2 and not is_unzip: while is_next and repeat <= 2 and not CBZUtils.updateOldCBZ(files_name):
ntfy.sendMsg(f"{book_name} {chapter_name} 下载中") ntfy.sendMsg(f"{book_name} {chapter_name} 下载中")
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)
equ_next = len(",".join(os.listdir(ci.getDirComicChapter())).split(".jpg"))-1 == len(list_img) equ_next = len(",".join(os.listdir(ci.getDirComicChapter())).split(".jpg"))-1 == len(list_img)
+24 -11
View File
@@ -13,6 +13,8 @@ class comicInfo():
PROGRESS_CBZ = "cbz" PROGRESS_CBZ = "cbz"
PROGRESS_DONE = "done" PROGRESS_DONE = "done"
PROGRESS_NONE = "none" PROGRESS_NONE = "none"
IS_NEW_ICON = False
document = Document() document = Document()
path_comic_info = None path_comic_info = None
@@ -50,6 +52,7 @@ class comicInfo():
str_files_img = None str_files_img = None
str_chapter_index= None str_chapter_index= None
str_value1 = None str_value1 = None
str_current_chapter_img = None
list_skip = [] list_skip = []
chapter_node = None chapter_node = None
@@ -88,8 +91,7 @@ class comicInfo():
@classmethod @classmethod
def setComicValue(cls,value): def setComicValue(cls,value):
result = None result = None
if value != None or value != "": if value != None or value != "": result = value
result = value
return result return result
@classmethod @classmethod
@@ -97,6 +99,10 @@ class comicInfo():
@classmethod @classmethod
def setChapterImgs(cls, value): cls.str_chapter_imgs = cls.setComicValue(value) def setChapterImgs(cls, value): cls.str_chapter_imgs = cls.setComicValue(value)
@classmethod @classmethod
def setCurrentChapterImg(cls, value): cls.str_current_chapter_img = cls.setComicValue(value)
@classmethod
def getCurrentChapterImg(cls): return cls.str_current_chapter_img
@classmethod
def getChapterImgs(cls): return cls.str_chapter_imgs def getChapterImgs(cls): return cls.str_chapter_imgs
@classmethod @classmethod
def getLenChapters(cls): return len(cls.str_list_chapter) def getLenChapters(cls): return len(cls.str_list_chapter)
@@ -142,7 +148,7 @@ class comicInfo():
@classmethod @classmethod
def setPageCount(cls,value): def setPageCount(cls,value):
cls.str_page_count = cls.setComicValue(int(value)+1) cls.str_page_count = cls.setComicValue(int(value))
cls.page_count_node = cls.setNodeAndValue(cls.page_count,cls.str_page_count) cls.page_count_node = cls.setNodeAndValue(cls.page_count,cls.str_page_count)
@classmethod @classmethod
@@ -151,13 +157,14 @@ class comicInfo():
su = "."+str(value[0]).split(".")[-1] su = "."+str(value[0]).split(".")[-1]
join_list=",".join(value).replace(su,"") join_list=",".join(value).replace(su,"")
value = join_list.split(",") value = join_list.split(",")
cls.setPageCount(str(len(value))) cls.setPageCount(len(value)+1 if cls.IS_NEW_ICON else len(value))
root_node = cls.document.createElement(cls.pages) root_node = cls.document.createElement(cls.pages)
#添加封面 if cls.IS_NEW_ICON:
icon_node = cls.document.createElement("Page") #添加封面
icon_node.setAttribute("Image","000") icon_node = cls.document.createElement("Page")
icon_node.setAttribute("Type","FrontCover") icon_node.setAttribute("Image","000")
root_node.appendChild(icon_node) icon_node.setAttribute("Type","FrontCover")
root_node.appendChild(icon_node)
for page in value: for page in value:
c_node = cls.document.createElement("Page") c_node = cls.document.createElement("Page")
page = page.split("_")[-1] page = page.split("_")[-1]
@@ -275,6 +282,11 @@ class comicInfo():
def getNewCBZComicChapter(cls,type="dir"): return cls.getNewToComicChapter(".CBZ", type) def getNewCBZComicChapter(cls,type="dir"): return cls.getNewToComicChapter(".CBZ", type)
@classmethod @classmethod
def getNewIconComicChapter(cls,type="dir"): return cls.getNewToComicChapter(".jpg", type) def getNewIconComicChapter(cls,type="dir"): return cls.getNewToComicChapter(".jpg", type)
@classmethod
def getNewFileCBZComicChapter(cls,type="file"): return cls.getNewToComicChapter(".CBZ", type)
@classmethod
def getNewFileIconComicChapter(cls,type="file"): return cls.getNewToComicChapter(".jpg", type)
@classmethod @classmethod
def getNewToComicChapter(cls,su,type="dir"): def getNewToComicChapter(cls,su,type="dir"):
@@ -437,7 +449,7 @@ class comicInfo():
@classmethod @classmethod
def setComicInfo(cls,comicname=None,homepage=None,alias=None,author=None,icon=None,tags=None, def setComicInfo(cls,comicname=None,homepage=None,alias=None,author=None,icon=None,tags=None,
dep=None,genre=None,lang=None,chapters=None,update_at=None): dep=None,genre=None,lang=None,chapters=None,update_at=None,current_chapter_img=None):
author = str(author).replace("&",",").replace(" ",",") author = str(author).replace("&",",").replace(" ",",")
cls.setHomePage(homepage) cls.setHomePage(homepage)
cls.setComicName(str(comicname)) cls.setComicName(str(comicname))
@@ -450,4 +462,5 @@ class comicInfo():
if genre != None: cls.setGenre(genre) if genre != None: cls.setGenre(genre)
cls.setLang(lang) cls.setLang(lang)
cls.setListChapter(chapters) cls.setListChapter(chapters)
cls.setUpdateAt(update_at) cls.setUpdateAt(update_at)
cls.setCurrentChapterImg(current_chapter_img)
+1 -1
View File
@@ -9,7 +9,7 @@ class pathStr:
comic_url_main = None comic_url_main = None
base_comic_out = os.path.join("/mnt", "Comics") base_comic_out = os.path.join("/mnt", "Comics")
base_unzip_path = os.path.join("/mnt","OldComics") old_cbz_path = os.path.join("/mnt","OldComics")
@classmethod @classmethod
def base_cbz(cls): return cls.getBaseComicPath("CBZ") def base_cbz(cls): return cls.getBaseComicPath("CBZ")
@classmethod @classmethod
+16 -14
View File
@@ -14,7 +14,7 @@ import time
from utils.Ntfy import ntfy from utils.Ntfy import ntfy
from utils.comic.ComicInfo import comicInfo from utils.comic.ComicInfo import comicInfo
from utils.HtmlUtils import htmlUtils from utils.HtmlUtils import htmlUtils
from utils.FileUtils import fileUtils from utils.FileUtils import fileUtils as fu
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",
@@ -53,7 +53,7 @@ def download_image(image_url, dst_dir, file_name, timeout=20, proxy_type=None, p
f.write(response.content) f.write(response.content)
response.close() response.close()
#验证是否是图像 #验证是否是图像
if fileUtils.ver_file(temp_path,type=type): if fu.ver_file(temp_path,type=type):
shutil.move(temp_path, file_path) shutil.move(temp_path, file_path)
print("## OK: {} {}".format(file_path, image_url)) print("## OK: {} {}".format(file_path, image_url))
except Exception as e: except Exception as e:
@@ -94,7 +94,7 @@ def download_images(image_urls, dst_dir,concurrency=None,timeout=30,proxy_type=N
count += 1 count += 1
concurrent.futures.wait(future_list, timeout) concurrent.futures.wait(future_list, timeout)
def download_comic_icon(): def download_comic_icon(is_new=comicInfo.IS_NEW_ICON):
icon_url = comicInfo.getIcon() icon_url = comicInfo.getIcon()
if icon_url == None: if icon_url == None:
print("icon 不存在,已跳过") print("icon 不存在,已跳过")
@@ -104,23 +104,25 @@ def download_comic_icon():
icon_prefix = icon_prefix.split("?")[0] icon_prefix = icon_prefix.split("?")[0]
#判断漫画名路径是否已存在comicname/cover.jpg, 存在跳过 #判断漫画名路径是否已存在comicname/cover.jpg, 存在跳过
path_comic_icon = os.path.join(comicInfo.getDirConfComic(),save_name+icon_prefix) path_comic_icon = os.path.join(comicInfo.getDirConfComic(),save_name+icon_prefix)
if not comicInfo.equIcon() and os.path.exists(path_comic_icon): if not comicInfo.equIcon() and fu.exists(path_comic_icon):
os.remove(path_comic_icon) os.remove(path_comic_icon)
if not os.path.exists(path_comic_icon): if fu.notExists(path_comic_icon):
download(icon_url, path_comic_icon) download(icon_url, path_comic_icon)
#if not os.path.exists(path_cbz_comic): #if not os.path.exists(path_cbz_comic):
# os.makedirs(path_cbz_comic) # os.makedirs(path_cbz_comic)
save_path = os.path.join(comicInfo.getDirCBZComic(),comicInfo.getChapter()+icon_prefix) save_path = os.path.join(comicInfo.getDirCBZComic(),comicInfo.getChapter()+icon_prefix)
#历史版本ICON if is_new:
if os.path.exists(save_path): #历史版本ICON
os.remove(save_path) if os.path.exists(save_path):
#shutil.copy(path_comic_icon, save_path) os.remove(save_path)
#print(f"{path_comic_icon} 已复制至: {save_path}") if os.path.exists(path_comic_icon):
if os.path.exists(path_comic_icon): base_dir = comicInfo.getDirComicChapter()
base_dir = comicInfo.getDirComicChapter() if not os.path.exists(base_dir): os.makedirs(base_dir)
if not os.path.exists(base_dir):
os.makedirs(base_dir)
shutil.copy(path_comic_icon,os.path.join(base_dir,save_name+icon_prefix)) shutil.copy(path_comic_icon,os.path.join(base_dir,save_name+icon_prefix))
else:
if fu.notExists(comicInfo.getDirCBZComicChapter()): os.makedirs(comicInfo.getDirCBZComicChapter())
shutil.copy(path_comic_icon,save_path)
print(f"{path_comic_icon} 已复制至: {save_path}")
#保存icon信息 #保存icon信息
comicInfo.iconDB() comicInfo.iconDB()
comicInfo.nextDownloadToCBZChapter() comicInfo.nextDownloadToCBZChapter()