将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文件。
# 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。 # 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# @Author : relakkes@gmail.com # @Author : relakkes@gmail.com
# @Time : 2024/1/14 19:34 # @Time : 2024/1/14 19:34
@@ -20,7 +19,7 @@ import config
from var import source_keyword_var from var import source_keyword_var
from .bilibili_store_impl import * from .bilibili_store_impl import *
from .bilibilli_store_video import * from .bilibilli_store_media import *
class BiliStoreFactory: class BiliStoreFactory:
@@ -35,9 +34,7 @@ class BiliStoreFactory:
def create_store() -> AbstractStore: def create_store() -> AbstractStore:
store_class = BiliStoreFactory.STORES.get(config.SAVE_DATA_OPTION) store_class = BiliStoreFactory.STORES.get(config.SAVE_DATA_OPTION)
if not store_class: if not store_class:
raise ValueError( raise ValueError("[BiliStoreFactory.create_store] Invalid save option only supported csv or db or json or sqlite ...")
"[BiliStoreFactory.create_store] Invalid save option only supported csv or db or json or sqlite ..."
)
return store_class() return store_class()
@@ -68,9 +65,7 @@ async def update_bilibili_video(video_item: Dict):
"video_cover_url": video_item_view.get("pic", ""), "video_cover_url": video_item_view.get("pic", ""),
"source_keyword": source_keyword_var.get(), "source_keyword": source_keyword_var.get(),
} }
utils.logger.info( utils.logger.info(f"[store.bilibili.update_bilibili_video] bilibili video id:{video_id}, title:{save_content_item.get('title')}")
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) 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"), "user_rank": video_item_card.get("level_info").get("current_level"),
"is_official": video_item_card.get("official_verify").get("type"), "is_official": video_item_card.get("official_verify").get("type"),
} }
utils.logger.info( utils.logger.info(f"[store.bilibili.update_up_info] bilibili user_id:{video_item_card.get('mid')}")
f"[store.bilibili.update_up_info] bilibili user_id:{video_item_card.get('mid')}"
)
await BiliStoreFactory.create_store().store_creator(creator=saver_up_info) 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, "like_count": like_count,
"last_modify_ts": utils.get_current_timestamp(), "last_modify_ts": utils.get_current_timestamp(),
} }
utils.logger.info( utils.logger.info(f"[store.bilibili.update_bilibili_video_comment] Bilibili video comment: {comment_id}, content: {save_comment_item.get('content')}")
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) 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: video_content:
extension_file_name: extension_file_name:
""" """
await BilibiliVideo().store_video( await BilibiliVideo().store_video({
{ "aid": aid,
"aid": aid, "video_content": video_content,
"video_content": video_content, "extension_file_name": extension_file_name,
"extension_file_name": extension_file_name, })
}
)
async def batch_update_bilibili_creator_fans(creator_info: Dict, fans_list: List[Dict]): 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"), "sign": fan_item.get("sign"),
"avatar": fan_item.get("face"), "avatar": fan_item.get("face"),
} }
await update_bilibili_creator_contact( await update_bilibili_creator_contact(creator_info=creator_info, fan_info=fan_info)
creator_info=creator_info, fan_info=fan_info
)
async def batch_update_bilibili_creator_followings( async def batch_update_bilibili_creator_followings(creator_info: Dict, followings_list: List[Dict]):
creator_info: Dict, followings_list: List[Dict]
):
if not followings_list: if not followings_list:
return return
for following_item in followings_list: for following_item in followings_list:
@@ -173,14 +158,10 @@ async def batch_update_bilibili_creator_followings(
"sign": following_item.get("sign"), "sign": following_item.get("sign"),
"avatar": following_item.get("face"), "avatar": following_item.get("face"),
} }
await update_bilibili_creator_contact( await update_bilibili_creator_contact(creator_info=following_info, fan_info=creator_info)
creator_info=following_info, fan_info=creator_info
)
async def batch_update_bilibili_creator_dynamics( async def batch_update_bilibili_creator_dynamics(creator_info: Dict, dynamics_list: List[Dict]):
creator_info: Dict, dynamics_list: List[Dict]
):
if not dynamics_list: if not dynamics_list:
return return
for dynamic_item in dynamics_list: for dynamic_item in dynamics_list:
@@ -203,9 +184,7 @@ async def batch_update_bilibili_creator_dynamics(
"total_forwards": dynamic_forward, "total_forwards": dynamic_forward,
"total_liked": dynamic_like, "total_liked": dynamic_like,
} }
await update_bilibili_creator_dynamic( await update_bilibili_creator_dynamic(creator_info=creator_info, dynamic_info=dynamic_info)
creator_info=creator_info, dynamic_info=dynamic_info
)
async def update_bilibili_creator_contact(creator_info: Dict, fan_info: Dict): async def update_bilibili_creator_contact(creator_info: Dict, fan_info: Dict):

View File

@@ -1,13 +1,12 @@
# 声明:本代码仅供学习和研究目的使用。使用者应遵守以下原则: # 声明:本代码仅供学习和研究目的使用。使用者应遵守以下原则:
# 1. 不得用于任何商业用途。 # 1. 不得用于任何商业用途。
# 2. 使用时应遵守目标平台的使用条款和robots.txt规则。 # 2. 使用时应遵守目标平台的使用条款和robots.txt规则。
# 3. 不得进行大规模爬取或对平台造成运营干扰。 # 3. 不得进行大规模爬取或对平台造成运营干扰。
# 4. 应合理控制请求频率,避免给目标平台带来不必要的负担。 # 4. 应合理控制请求频率,避免给目标平台带来不必要的负担。
# 5. 不得用于任何非法或不当的用途。 # 5. 不得用于任何非法或不当的用途。
# #
# 详细许可条款请参阅项目根目录下的LICENSE文件。 # 详细许可条款请参阅项目根目录下的LICENSE文件。
# 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。 # 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# @Author : relakkes@gmail.com # @Author : relakkes@gmail.com
@@ -19,7 +18,7 @@ from typing import List
from var import source_keyword_var from var import source_keyword_var
from .weibo_store_image import * from .weibo_store_media import *
from .weibo_store_impl import * from .weibo_store_impl import *
@@ -35,8 +34,7 @@ class WeibostoreFactory:
def create_store() -> AbstractStore: def create_store() -> AbstractStore:
store_class = WeibostoreFactory.STORES.get(config.SAVE_DATA_OPTION) store_class = WeibostoreFactory.STORES.get(config.SAVE_DATA_OPTION)
if not store_class: if not store_class:
raise ValueError( raise ValueError("[WeibotoreFactory.create_store] Invalid save option only supported csv or db or json or sqlite ...")
"[WeibotoreFactory.create_store] Invalid save option only supported csv or db or json or sqlite ...")
return store_class() return store_class()
@@ -91,11 +89,9 @@ async def update_weibo_note(note_item: Dict):
"gender": user_info.get("gender", ""), "gender": user_info.get("gender", ""),
"profile_url": user_info.get("profile_url", ""), "profile_url": user_info.get("profile_url", ""),
"avatar": user_info.get("profile_image_url", ""), "avatar": user_info.get("profile_image_url", ""),
"source_keyword": source_keyword_var.get(), "source_keyword": source_keyword_var.get(),
} }
utils.logger.info( utils.logger.info(f"[store.weibo.update_weibo_note] weibo note id:{note_id}, title:{save_content_item.get('content')[:24]} ...")
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) 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", ""), "profile_url": user_info.get("profile_url", ""),
"avatar": user_info.get("profile_image_url", ""), "avatar": user_info.get("profile_image_url", ""),
} }
utils.logger.info( utils.logger.info(f"[store.weibo.update_weibo_note_comment] Weibo note comment: {comment_id}, content: {save_comment_item.get('content', '')[:24]} ...")
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) 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: Returns:
""" """
await WeiboStoreImage().store_image( await WeiboStoreImage().store_image({"pic_id": picid, "pic_content": pic_content, "extension_file_name": extension_file_name})
{"pic_id": picid, "pic_content": pic_content, "extension_file_name": extension_file_name})
async def save_creator(user_id: str, user_info: Dict): async def save_creator(user_id: str, user_info: Dict):

View File

@@ -1,13 +1,12 @@
# 声明:本代码仅供学习和研究目的使用。使用者应遵守以下原则: # 声明:本代码仅供学习和研究目的使用。使用者应遵守以下原则:
# 1. 不得用于任何商业用途。 # 1. 不得用于任何商业用途。
# 2. 使用时应遵守目标平台的使用条款和robots.txt规则。 # 2. 使用时应遵守目标平台的使用条款和robots.txt规则。
# 3. 不得进行大规模爬取或对平台造成运营干扰。 # 3. 不得进行大规模爬取或对平台造成运营干扰。
# 4. 应合理控制请求频率,避免给目标平台带来不必要的负担。 # 4. 应合理控制请求频率,避免给目标平台带来不必要的负担。
# 5. 不得用于任何非法或不当的用途。 # 5. 不得用于任何非法或不当的用途。
# #
# 详细许可条款请参阅项目根目录下的LICENSE文件。 # 详细许可条款请参阅项目根目录下的LICENSE文件。
# 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。 # 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# @Author : Erm # @Author : Erm
@@ -18,7 +17,7 @@ from typing import Dict
import aiofiles import aiofiles
from base.base_crawler import AbstractStoreImage from base.base_crawler import AbstractStoreImage, AbstractStoreVideo
from tools import utils from tools import utils
@@ -61,4 +60,4 @@ class WeiboStoreImage(AbstractStoreImage):
save_file_name = self.make_save_file_name(picid, extension_file_name) save_file_name = self.make_save_file_name(picid, extension_file_name)
async with aiofiles.open(save_file_name, 'wb') as f: async with aiofiles.open(save_file_name, 'wb') as f:
await f.write(pic_content) 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 var import source_keyword_var
from . import xhs_store_impl from . import xhs_store_impl
from .xhs_store_image import * from .xhs_store_media import *
from .xhs_store_impl import * from .xhs_store_impl import *