Просмотр исходного кода

ai片尾使用原标题,快手获取分享数增加重试次数

zhangyong 9 месяцев назад
Родитель
Сommit
1af300d087
3 измененных файлов с 17 добавлено и 17 удалено
  1. 2 2
      common/gpt4o_help.py
  2. 12 13
      data_channel/kuaishou.py
  3. 3 2
      video_rewriting/video_prep.py

+ 2 - 2
common/gpt4o_help.py

@@ -29,7 +29,7 @@ class GPT4o():
                     第二:生成过程有如下的规范、约束和建议:
                             1.标题开头包含醒目emoji🔴,整体字符长度控制在10-25;
                             2.不能包含#话题和@人;
-                            3.如果原标题无法按照规则生成新标题则重新尝试5次,失败后返回原标题
+                            3.如果原标题无法按照规则生成新标题则重新尝试5次,5次都失败后返回None
                             4.不能编造:不能加入原标题没有的实体信息,如原标题没有养老金,不能在生成的标题中出现养老金;
                             5.必须用引导群里好友和朋友们点击的短句结尾,示例:“群友们,都看看吧!”,“太棒了,请朋友们收好!”,“找了很久,终于找到了”,“好友们都来听听吧”;
                             6.不能使用无实质信息和强烈诱导点击、紧急、夸张、震惊的描述:在提高标题吸引力的同时,严格落实不使用“必看”、“错过悔恨终生”类描述,错误危险标题示例:
@@ -160,4 +160,4 @@ class GPT4o():
 
 if __name__ == '__main__':
     title = '#夏日萌友季 #快分享计划 @快手粉条(O40300047) @快手宠物(O40300091)'
-    GPT4o.get_ai_title(title)
+    GPT4o.get_ai_pw(title)

+ 12 - 13
data_channel/kuaishou.py

@@ -22,19 +22,18 @@ class KS:
         headers = {
             'Content-Type': 'application/json'
         }
-
-        response = requests.request("POST", url, headers=headers, data=payload)
-        response = response.json()
-        try:
-            if response["code"] == 0:
-                data = response["data"]["data"]
-                share_count = data.get("share_count")
-                return int(share_count)
-            else:
-                return 0
-        except KeyError as e:
-            Common.logger("ks").info(f"获取分享数据失败:{e}\n")
-            return 0
+        for i in range(5):
+            try:
+                time.sleep(2)
+                response = requests.request("POST", url, headers=headers, data=payload)
+                response = response.json()
+                if response["code"] == 0:
+                    data = response["data"]["data"]
+                    share_count = data.get("share_count")
+                    return int(share_count)
+            except KeyError as e:
+                Common.logger("ks").info(f"获取分享数据失败:{e}\n")
+        return 0
 
     @classmethod
     def get_ks_url(cls, task_mark, url_id, number, mark, feishu_id, cookie_sheet, channel_id, name):

+ 3 - 2
video_rewriting/video_prep.py

@@ -156,7 +156,8 @@ class getVideo:
                         video_url = video["video_url"]
                         rule = video['rule']
                         old_title = video['old_title']
-
+                        if old_title == "" or len(old_title) == 0 or old_title == None:
+                            old_title = '⭕分享给大家一个视频!值得细品!'
                         time.sleep(1)
                         pw_random_id = cls.random_id()
                         if channel_id == "票圈":
@@ -175,7 +176,7 @@ class getVideo:
                             new_video_path = FFmpeg.video_ggduration(new_video_path, video_path_url, pw_random_id, gg_duration_total)
                         if video_ending and video_ending != 'None':
                             if video_ending == "AI片尾引导":
-                                pw_srt_text = GPT4o.get_ai_pw(new_title)
+                                pw_srt_text = GPT4o.get_ai_pw(old_title)
                                 if pw_srt_text:
                                     pw_url = TTS.get_pw_zm(pw_srt_text)
                                     Common.logger("log").info(f"{task_mark}下的视频{url},获取AI片尾音频成功")