admin
2025-03-31 4603536999de113969dd7164f3a04dcde9083480
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
"""
评论管理
"""
# 保存回复视频评论的用户昵称
# {"视频名称+发布日期":{"评论用户的昵称":{"评论内容集合"}}}
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_name, video_date, comment_nick_name, comment_content):
    """
    获取回复内容
    :param video_name:视频名称
    :param video_date:视频日期
    :param comment_nick_name:评论昵称
    :param comment_content:评论内容
    :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 __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:
        if r.match(r[0], comment_content):
            # 能够匹配到正则表达式
            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 r.match(r, comment_content):
            # 能够匹配到正则表达式
            return True
    return False