admin
2025-04-02 91b7ec2b67d74e4d2e41c857232414feb3cb7bfd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import time
 
import tool
 
 
@tool.singleton
class VideoManger:
    __video_cache_path = "datas/videos.json"
    # {"视频内容+视频时间":(评论数量,更新时间)}
    __video_data_cache_dict = {}
 
    def __init__(self):
 
        if os.path.exists(self.__video_cache_path):
            with open(self.__video_cache_path, encoding="utf-8", mode='r') as f:
                lines = f.readlines()
                if lines:
                    self.__video_data_cache_dict = eval(lines[0])
 
    def is_need_click(self, video_info):
        """
        是否需要点击
        :param video_info:
        :return:
        """
        video_name, video_time, comment_count = video_info[0], video_info[1], video_info[2]
        k = f"{video_name}{video_time}"
        if k not in self.__video_data_cache_dict:
            return True
        if int(comment_count) - int(self.__video_data_cache_dict[k][0]) > 0:
            return True
        return False
 
    def add_video_infos(self, video_infos):
        """
        添加视频信息
        :param video_infos:
        :return:
        """
        print("保存所有视频内容")
        self.__video_data_cache_dict = {f"{x[0]}{x[1]}": (x[2], time.time()) for x in video_infos}
        # 保存到文件
        with open(self.__video_cache_path, encoding="utf-8", mode='w') as f:
            f.write(f"{self.__video_data_cache_dict}")