将store文件夹中后缀名为_video或_image的.py文件统一更名为以_media.py为结尾的命名方式,避免某些平台仅有_video.py文件或_image.py文件的单独实现。之后的所有存储视频或图像的代码均放在此文件中实现

This commit is contained in:
未来可欺
2025-07-30 18:32:08 +08:00
parent 173bc08a9d
commit ecddfbe02c
6 changed files with 39 additions and 67 deletions

View File

@@ -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):

View File

@@ -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):

View File

@@ -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 ...")
utils.logger.info(f"[WeiboImageStoreImplement.save_image] save image {save_file_name} success ...")

View File

@@ -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 *