From ecddfbe02c7604f4cb89b8df6b1ebfde60964ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=AA=E6=9D=A5=E5=8F=AF=E6=AC=BA?= <2513502304@qq.com> Date: Wed, 30 Jul 2025 18:32:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86store=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E4=B8=AD=E5=90=8E=E7=BC=80=E5=90=8D=E4=B8=BA=5Fvideo=E6=88=96?= =?UTF-8?q?=5Fimage=E7=9A=84.py=E6=96=87=E4=BB=B6=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E6=9B=B4=E5=90=8D=E4=B8=BA=E4=BB=A5=5Fmedia.py=E4=B8=BA?= =?UTF-8?q?=E7=BB=93=E5=B0=BE=E7=9A=84=E5=91=BD=E5=90=8D=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E6=9F=90=E4=BA=9B=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E4=BB=85=E6=9C=89=5Fvideo.py=E6=96=87=E4=BB=B6=E6=88=96=5Fimag?= =?UTF-8?q?e.py=E6=96=87=E4=BB=B6=E7=9A=84=E5=8D=95=E7=8B=AC=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E3=80=82=E4=B9=8B=E5=90=8E=E7=9A=84=E6=89=80=E6=9C=89?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E8=A7=86=E9=A2=91=E6=88=96=E5=9B=BE=E5=83=8F?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81=E5=9D=87=E6=94=BE=E5=9C=A8=E6=AD=A4?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=AD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- store/bilibili/__init__.py | 51 ++++++------------- ...tore_video.py => bilibilli_store_media.py} | 0 store/weibo/__init__.py | 32 +++++------- ...bo_store_image.py => weibo_store_media.py} | 21 ++++---- store/xhs/__init__.py | 2 +- ...{xhs_store_image.py => xhs_store_media.py} | 0 6 files changed, 39 insertions(+), 67 deletions(-) rename store/bilibili/{bilibilli_store_video.py => bilibilli_store_media.py} (100%) rename store/weibo/{weibo_store_image.py => weibo_store_media.py} (88%) rename store/xhs/{xhs_store_image.py => xhs_store_media.py} (100%) diff --git a/store/bilibili/__init__.py b/store/bilibili/__init__.py index 5160aa2..30a5050 100644 --- a/store/bilibili/__init__.py +++ b/store/bilibili/__init__.py @@ -8,7 +8,6 @@ # 详细许可条款请参阅项目根目录下的LICENSE文件。 # 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。 - # -*- coding: utf-8 -*- # @Author : relakkes@gmail.com # @Time : 2024/1/14 19:34 @@ -20,7 +19,7 @@ import config from var import source_keyword_var from .bilibili_store_impl import * -from .bilibilli_store_video import * +from .bilibilli_store_media import * class BiliStoreFactory: @@ -35,9 +34,7 @@ class BiliStoreFactory: def create_store() -> AbstractStore: store_class = BiliStoreFactory.STORES.get(config.SAVE_DATA_OPTION) if not store_class: - raise ValueError( - "[BiliStoreFactory.create_store] Invalid save option only supported csv or db or json or sqlite ..." - ) + raise ValueError("[BiliStoreFactory.create_store] Invalid save option only supported csv or db or json or sqlite ...") return store_class() @@ -68,9 +65,7 @@ async def update_bilibili_video(video_item: Dict): "video_cover_url": video_item_view.get("pic", ""), "source_keyword": source_keyword_var.get(), } - utils.logger.info( - f"[store.bilibili.update_bilibili_video] bilibili video id:{video_id}, title:{save_content_item.get('title')}" - ) + utils.logger.info(f"[store.bilibili.update_bilibili_video] bilibili video id:{video_id}, title:{save_content_item.get('title')}") await BiliStoreFactory.create_store().store_content(content_item=save_content_item) @@ -89,9 +84,7 @@ async def update_up_info(video_item: Dict): "user_rank": video_item_card.get("level_info").get("current_level"), "is_official": video_item_card.get("official_verify").get("type"), } - utils.logger.info( - f"[store.bilibili.update_up_info] bilibili user_id:{video_item_card.get('mid')}" - ) + utils.logger.info(f"[store.bilibili.update_up_info] bilibili user_id:{video_item_card.get('mid')}") await BiliStoreFactory.create_store().store_creator(creator=saver_up_info) @@ -123,9 +116,7 @@ async def update_bilibili_video_comment(video_id: str, comment_item: Dict): "like_count": like_count, "last_modify_ts": utils.get_current_timestamp(), } - utils.logger.info( - f"[store.bilibili.update_bilibili_video_comment] Bilibili video comment: {comment_id}, content: {save_comment_item.get('content')}" - ) + utils.logger.info(f"[store.bilibili.update_bilibili_video_comment] Bilibili video comment: {comment_id}, content: {save_comment_item.get('content')}") await BiliStoreFactory.create_store().store_comment(comment_item=save_comment_item) @@ -137,13 +128,11 @@ async def store_video(aid, video_content, extension_file_name): video_content: extension_file_name: """ - await BilibiliVideo().store_video( - { - "aid": aid, - "video_content": video_content, - "extension_file_name": extension_file_name, - } - ) + await BilibiliVideo().store_video({ + "aid": aid, + "video_content": video_content, + "extension_file_name": extension_file_name, + }) async def batch_update_bilibili_creator_fans(creator_info: Dict, fans_list: List[Dict]): @@ -156,14 +145,10 @@ async def batch_update_bilibili_creator_fans(creator_info: Dict, fans_list: List "sign": fan_item.get("sign"), "avatar": fan_item.get("face"), } - await update_bilibili_creator_contact( - creator_info=creator_info, fan_info=fan_info - ) + await update_bilibili_creator_contact(creator_info=creator_info, fan_info=fan_info) -async def batch_update_bilibili_creator_followings( - creator_info: Dict, followings_list: List[Dict] -): +async def batch_update_bilibili_creator_followings(creator_info: Dict, followings_list: List[Dict]): if not followings_list: return for following_item in followings_list: @@ -173,14 +158,10 @@ async def batch_update_bilibili_creator_followings( "sign": following_item.get("sign"), "avatar": following_item.get("face"), } - await update_bilibili_creator_contact( - creator_info=following_info, fan_info=creator_info - ) + await update_bilibili_creator_contact(creator_info=following_info, fan_info=creator_info) -async def batch_update_bilibili_creator_dynamics( - creator_info: Dict, dynamics_list: List[Dict] -): +async def batch_update_bilibili_creator_dynamics(creator_info: Dict, dynamics_list: List[Dict]): if not dynamics_list: return for dynamic_item in dynamics_list: @@ -203,9 +184,7 @@ async def batch_update_bilibili_creator_dynamics( "total_forwards": dynamic_forward, "total_liked": dynamic_like, } - await update_bilibili_creator_dynamic( - creator_info=creator_info, dynamic_info=dynamic_info - ) + await update_bilibili_creator_dynamic(creator_info=creator_info, dynamic_info=dynamic_info) async def update_bilibili_creator_contact(creator_info: Dict, fan_info: Dict): diff --git a/store/bilibili/bilibilli_store_video.py b/store/bilibili/bilibilli_store_media.py similarity index 100% rename from store/bilibili/bilibilli_store_video.py rename to store/bilibili/bilibilli_store_media.py diff --git a/store/weibo/__init__.py b/store/weibo/__init__.py index 449e3dd..41bb317 100644 --- a/store/weibo/__init__.py +++ b/store/weibo/__init__.py @@ -1,13 +1,12 @@ -# 声明:本代码仅供学习和研究目的使用。使用者应遵守以下原则: -# 1. 不得用于任何商业用途。 -# 2. 使用时应遵守目标平台的使用条款和robots.txt规则。 -# 3. 不得进行大规模爬取或对平台造成运营干扰。 -# 4. 应合理控制请求频率,避免给目标平台带来不必要的负担。 +# 声明:本代码仅供学习和研究目的使用。使用者应遵守以下原则: +# 1. 不得用于任何商业用途。 +# 2. 使用时应遵守目标平台的使用条款和robots.txt规则。 +# 3. 不得进行大规模爬取或对平台造成运营干扰。 +# 4. 应合理控制请求频率,避免给目标平台带来不必要的负担。 # 5. 不得用于任何非法或不当的用途。 -# -# 详细许可条款请参阅项目根目录下的LICENSE文件。 -# 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。 - +# +# 详细许可条款请参阅项目根目录下的LICENSE文件。 +# 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。 # -*- coding: utf-8 -*- # @Author : relakkes@gmail.com @@ -19,7 +18,7 @@ from typing import List from var import source_keyword_var -from .weibo_store_image import * +from .weibo_store_media import * from .weibo_store_impl import * @@ -35,8 +34,7 @@ class WeibostoreFactory: def create_store() -> AbstractStore: store_class = WeibostoreFactory.STORES.get(config.SAVE_DATA_OPTION) if not store_class: - raise ValueError( - "[WeibotoreFactory.create_store] Invalid save option only supported csv or db or json or sqlite ...") + raise ValueError("[WeibotoreFactory.create_store] Invalid save option only supported csv or db or json or sqlite ...") return store_class() @@ -91,11 +89,9 @@ async def update_weibo_note(note_item: Dict): "gender": user_info.get("gender", ""), "profile_url": user_info.get("profile_url", ""), "avatar": user_info.get("profile_image_url", ""), - "source_keyword": source_keyword_var.get(), } - utils.logger.info( - f"[store.weibo.update_weibo_note] weibo note id:{note_id}, title:{save_content_item.get('content')[:24]} ...") + utils.logger.info(f"[store.weibo.update_weibo_note] weibo note id:{note_id}, title:{save_content_item.get('content')[:24]} ...") await WeibostoreFactory.create_store().store_content(content_item=save_content_item) @@ -150,8 +146,7 @@ async def update_weibo_note_comment(note_id: str, comment_item: Dict): "profile_url": user_info.get("profile_url", ""), "avatar": user_info.get("profile_image_url", ""), } - utils.logger.info( - f"[store.weibo.update_weibo_note_comment] Weibo note comment: {comment_id}, content: {save_comment_item.get('content', '')[:24]} ...") + utils.logger.info(f"[store.weibo.update_weibo_note_comment] Weibo note comment: {comment_id}, content: {save_comment_item.get('content', '')[:24]} ...") await WeibostoreFactory.create_store().store_comment(comment_item=save_comment_item) @@ -166,8 +161,7 @@ async def update_weibo_note_image(picid: str, pic_content, extension_file_name): Returns: """ - await WeiboStoreImage().store_image( - {"pic_id": picid, "pic_content": pic_content, "extension_file_name": extension_file_name}) + await WeiboStoreImage().store_image({"pic_id": picid, "pic_content": pic_content, "extension_file_name": extension_file_name}) async def save_creator(user_id: str, user_info: Dict): diff --git a/store/weibo/weibo_store_image.py b/store/weibo/weibo_store_media.py similarity index 88% rename from store/weibo/weibo_store_image.py rename to store/weibo/weibo_store_media.py index 65fb160..38fbcdc 100644 --- a/store/weibo/weibo_store_image.py +++ b/store/weibo/weibo_store_media.py @@ -1,13 +1,12 @@ -# 声明:本代码仅供学习和研究目的使用。使用者应遵守以下原则: -# 1. 不得用于任何商业用途。 -# 2. 使用时应遵守目标平台的使用条款和robots.txt规则。 -# 3. 不得进行大规模爬取或对平台造成运营干扰。 -# 4. 应合理控制请求频率,避免给目标平台带来不必要的负担。 +# 声明:本代码仅供学习和研究目的使用。使用者应遵守以下原则: +# 1. 不得用于任何商业用途。 +# 2. 使用时应遵守目标平台的使用条款和robots.txt规则。 +# 3. 不得进行大规模爬取或对平台造成运营干扰。 +# 4. 应合理控制请求频率,避免给目标平台带来不必要的负担。 # 5. 不得用于任何非法或不当的用途。 -# -# 详细许可条款请参阅项目根目录下的LICENSE文件。 -# 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。 - +# +# 详细许可条款请参阅项目根目录下的LICENSE文件。 +# 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。 # -*- coding: utf-8 -*- # @Author : Erm @@ -18,7 +17,7 @@ from typing import Dict import aiofiles -from base.base_crawler import AbstractStoreImage +from base.base_crawler import AbstractStoreImage, AbstractStoreVideo from tools import utils @@ -61,4 +60,4 @@ class WeiboStoreImage(AbstractStoreImage): save_file_name = self.make_save_file_name(picid, extension_file_name) async with aiofiles.open(save_file_name, 'wb') as f: await f.write(pic_content) - utils.logger.info(f"[WeiboImageStoreImplement.save_image] save image {save_file_name} success ...") \ No newline at end of file + utils.logger.info(f"[WeiboImageStoreImplement.save_image] save image {save_file_name} success ...") diff --git a/store/xhs/__init__.py b/store/xhs/__init__.py index 515ed2a..13a50bd 100644 --- a/store/xhs/__init__.py +++ b/store/xhs/__init__.py @@ -18,7 +18,7 @@ import config from var import source_keyword_var from . import xhs_store_impl -from .xhs_store_image import * +from .xhs_store_media import * from .xhs_store_impl import * diff --git a/store/xhs/xhs_store_image.py b/store/xhs/xhs_store_media.py similarity index 100% rename from store/xhs/xhs_store_image.py rename to store/xhs/xhs_store_media.py