This commit is contained in:
caiwx86 2023-03-31 01:37:41 +08:00
parent 29db14b827
commit 5cc8b385cc
2 changed files with 15 additions and 5 deletions

View File

@ -206,26 +206,35 @@ class fileUtils:
@classmethod
def notExists(cls,path):
return not cls.exists(path)
@classmethod
def size(cls,file_path,unit=None):
size = 0
if cls.exists(file_path): size = os.path.getsize(file_path)
if unit == "kb" or unit == "KB":
return str(size/1000)+"KB"
if unit == None:
return size
@classmethod
def ver_file(cls,file_path,type):
time.sleep(0.1)
file_size = os.path.getsize(file_path)
if type == "image" and int(file_size) > 100:
file_size_unit = cls.size(file_path,unit="kb")
if type == "image" and int(cls.size(file_path)) > 100:
#验证是否是图像
try:
img = Image.open(file_path)
img.verify()
img.close()
print(f"{file_path} 类型为type:{type} size: {file_size}")
print(f"{file_path} 类型为type:{type} size: {file_size_unit}")
return True
except:
if os.path.exists(file_path):
os.remove(file_path)
print(f"{file_path}已损坏 type:{type} size: {file_size},删除重试中")
print(f"{file_path}已损坏 type:{type} size: {file_size_unit},删除重试中")
return False
else:
print(f"文件小于100b删除中,{file_path} size: {file_size}")
print(f"文件小于100b删除中,{file_path} size: {file_size_unit}")
try:
os.remove(file_path)
except Exception as e:

View File

@ -120,6 +120,7 @@ def download_comic_icon(is_new=comicInfo.IS_NEW_ICON):
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))
else:
if fu.notExists(comicInfo.getDirCBZComic()): os.makedirs(comicInfo.getDirCBZComic())
shutil.copy(path_comic_icon,save_path)
print(f"{path_comic_icon} 已复制至: {save_path}")
#保存icon信息