From 6effbacb28f80b5c5d9f1b6751d76e9b6faa77b8 Mon Sep 17 00:00:00 2001 From: yajiwa <839790708@qq.com> Date: Mon, 13 Jun 2022 10:08:09 +0800 Subject: [PATCH 1/5] add change_img_md5 --- utils/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/utils/utils.py b/utils/utils.py index 581c7df5..1a7a041e 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -398,3 +398,19 @@ def change_pixiv_image_links( .replace("_webp", "") ) return url + + +def change_img_md5(path_file) -> bool: + """ + 说明: + 改变图片MD5 + 参数: + :param path_file: 图片路径 + """ + try: + with open(path_file, "a") as f: + f.write(str(int(time.time() * 1000))) + f.close() + return True + except: + return False \ No newline at end of file From 6e18379597137cf73340d95a0466d116b844f438 Mon Sep 17 00:00:00 2001 From: yajiwa <839790708@qq.com> Date: Mon, 13 Jun 2022 10:08:51 +0800 Subject: [PATCH 2/5] update setu_img --- plugins/pix_gallery/_data_source.py | 3 ++- plugins/pixiv_rank_search/data_source.py | 2 ++ plugins/send_setu_/send_setu/data_source.py | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/pix_gallery/_data_source.py b/plugins/pix_gallery/_data_source.py index f991c66e..28fd52e8 100644 --- a/plugins/pix_gallery/_data_source.py +++ b/plugins/pix_gallery/_data_source.py @@ -4,7 +4,7 @@ from asyncio.locks import Semaphore from asyncio.exceptions import TimeoutError from ._model.pixiv import Pixiv from typing import List, Optional -from utils.utils import change_pixiv_image_links +from utils.utils import change_pixiv_image_links, change_img_md5 from utils.image_utils import BuildImage from utils.http_utils import AsyncHttpx from services.log import logger @@ -238,6 +238,7 @@ async def get_image(img_url: str, user_id: int) -> Optional[str]: TEMP_PATH / f"pix_{user_id}_{img_url.split('/')[-1][:-4]}.jpg", "wb" ) as f: await f.write(response.content) + change_img_md5(TEMP_PATH / f"pix_{user_id}_{img_url.split('/')[-1][:-4]}.jpg") return TEMP_PATH / f"pix_{user_id}_{img_url.split('/')[-1][:-4]}.jpg" except TimeoutError: logger.warning(f"PIX:{img_url} 图片下载超时...") diff --git a/plugins/pixiv_rank_search/data_source.py b/plugins/pixiv_rank_search/data_source.py index 83792a49..b4eb3f2e 100755 --- a/plugins/pixiv_rank_search/data_source.py +++ b/plugins/pixiv_rank_search/data_source.py @@ -1,5 +1,6 @@ from configs.path_config import IMAGE_PATH from utils.message_builder import image +from utils.utils import change_img_md5 from asyncio.exceptions import TimeoutError from configs.config import Config from utils.http_utils import AsyncHttpx @@ -143,6 +144,7 @@ async def download_pixiv_imgs( file, timeout=Config.get_config("pixiv_rank_search", "TIMEOUT"), ): + change_img_md5(file) if forward_msg_index is not None: result += image( f"{user_id}_{forward_msg_index}_{index}_pixiv.jpg", diff --git a/plugins/send_setu_/send_setu/data_source.py b/plugins/send_setu_/send_setu/data_source.py index 6cb3414b..48d688ec 100755 --- a/plugins/send_setu_/send_setu/data_source.py +++ b/plugins/send_setu_/send_setu/data_source.py @@ -2,6 +2,7 @@ from configs.path_config import IMAGE_PATH, TEMP_PATH from utils.message_builder import image from services.log import logger from utils.image_utils import get_img_hash, compressed_image +from utils.utils import change_img_md5 from asyncpg.exceptions import UniqueViolationError from asyncio.exceptions import TimeoutError from typing import List, Optional @@ -111,6 +112,7 @@ async def search_online_setu( path_ / f"{index}.jpg", ) logger.info(f"下载 lolicon 图片 {url_} 成功, id:{index}") + change_img_md5(path_ / file_name) return image(path_ / file_name), index except TimeoutError: pass @@ -128,6 +130,7 @@ async def check_local_exists_or_download(setu_image: Setu) -> "MessageSegment, i path_ = r18_path if setu_image.is_r18 else path file = IMAGE_PATH / path_ / f"{setu_image.local_id}.jpg" if file.exists(): + change_img_md5(file) return image(f"{setu_image.local_id}.jpg", path_), 200 return await search_online_setu(setu_image.img_url, id_, path_) From 830103b9d53d87150c950ea0df0560fdf604994d Mon Sep 17 00:00:00 2001 From: yajiwa <839790708@qq.com> Date: Mon, 13 Jun 2022 10:59:29 +0800 Subject: [PATCH 3/5] update change_img_md5 --- utils/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/utils.py b/utils/utils.py index 1a7a041e..8c280933 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -400,7 +400,7 @@ def change_pixiv_image_links( return url -def change_img_md5(path_file) -> bool: +def change_img_md5(path_file: str) -> bool: """ 说明: 改变图片MD5 @@ -410,7 +410,6 @@ def change_img_md5(path_file) -> bool: try: with open(path_file, "a") as f: f.write(str(int(time.time() * 1000))) - f.close() return True except: return False \ No newline at end of file From caa404d58d05a372b99a5a15a61c4265c2491397 Mon Sep 17 00:00:00 2001 From: HibiKier <45528451+HibiKier@users.noreply.github.com> Date: Mon, 13 Jun 2022 11:03:21 +0800 Subject: [PATCH 4/5] Update utils.py --- utils/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/utils.py b/utils/utils.py index 8c280933..ac151b84 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -5,6 +5,7 @@ from configs.config import SYSTEM_PROXY, Config from typing import List, Union, Optional, Type, Any from nonebot.adapters.onebot.v11 import Bot, Message from nonebot.matcher import matchers, Matcher +from pathlib import Path import httpx import nonebot import pytz @@ -400,7 +401,7 @@ def change_pixiv_image_links( return url -def change_img_md5(path_file: str) -> bool: +def change_img_md5(path_file: Union[str, Path]) -> bool: """ 说明: 改变图片MD5 @@ -412,4 +413,4 @@ def change_img_md5(path_file: str) -> bool: f.write(str(int(time.time() * 1000))) return True except: - return False \ No newline at end of file + return False From 35c038efa2f432e7bad8f9bcc54c7da550fdb9e7 Mon Sep 17 00:00:00 2001 From: HibiKier <45528451+HibiKier@users.noreply.github.com> Date: Mon, 13 Jun 2022 11:05:16 +0800 Subject: [PATCH 5/5] Update utils.py --- utils/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/utils.py b/utils/utils.py index ac151b84..7ce3044f 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -5,6 +5,7 @@ from configs.config import SYSTEM_PROXY, Config from typing import List, Union, Optional, Type, Any from nonebot.adapters.onebot.v11 import Bot, Message from nonebot.matcher import matchers, Matcher +from services.log import logger from pathlib import Path import httpx import nonebot @@ -412,5 +413,6 @@ def change_img_md5(path_file: Union[str, Path]) -> bool: with open(path_file, "a") as f: f.write(str(int(time.time() * 1000))) return True - except: + except Exception as e: + logger.warning(f"改变图片MD5发生错误 {type(e)}:{e} Path:{path_file}") return False