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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
评论管理
"""
# 保存回复视频评论的用户昵称
# {"视频名称+发布日期":{"评论用户的昵称":{"评论内容集合"}}}
import re
 
import comment_util
 
__reply_video_comment_user_name_dict = {}
 
 
def add_reply_record(video_name, video_date, comment_nick_name, comment_content):
    """
    添加评论内容
    :param video_name:
    :param video_date:
    :param comment_nick_name:
    :return:
    """
    k = f"{video_name}{video_date}"
    if k not in __reply_video_comment_user_name_dict:
        __reply_video_comment_user_name_dict[k] = {}
    if comment_nick_name not in __reply_video_comment_user_name_dict[k]:
        __reply_video_comment_user_name_dict[k][comment_nick_name] = set()
    __reply_video_comment_user_name_dict[k][comment_nick_name].add(comment_content)
 
 
def get_replay_content(video_info, comment_nick_name, comment_content):
    """
    获取回复内容
    :param video_info:(视频名称, 日期, 评论次数, 视频标题)
    :param comment_nick_name:评论昵称
    :param comment_content:评论内容
    :return:
    """
    video_name, video_date, video_title = video_info[0], video_info[1], video_info[3]
 
    k = f"{video_name}{video_date}"
    if k not in __reply_video_comment_user_name_dict:
        __reply_video_comment_user_name_dict[k] = {}
    if __reply_video_comment_user_name_dict[k].get(comment_nick_name):
        # 评论过了就不评论了
        return None
    # 获取评论的正则表达式
    comment_templates = comment_util.get_comment_templates()
    if not comment_templates:
        return None
 
    if not comment_content:
        return None
 
    # 替换评论内容中的img
    comment_content = comment_util.replace_img_with_alt(comment_content)
 
    for r in comment_templates:
        is_match = False
        if r[0].find("【视频标题】") >= 0:
            if comment_content.find(video_title)>=0:
                is_match = True
        elif re.match(r[0], comment_content):
            is_match = True
        if is_match:
            # 能够匹配到正则表达式
            result = comment_util.load_content(r[1], comment_nick_name, comment_content)
            if result:
                return result
    return None
 
 
def is_need_click_like(video_name, video_date, comment_nick_name, comment_content):
    """
    是否需要点赞
    :param video_name:
    :param video_date:
    :param comment_nick_name:
    :param comment_content:
    :return:
    """
 
    like_conditions = comment_util.get_like_conditions()
    if not like_conditions:
        return False
    # 替换评论内容中的img
    comment_content = comment_util.replace_img_with_alt(comment_content)
    for r in like_conditions:
        if re.match(r, comment_content):
            # 能够匹配到正则表达式
            return True
    return False