Przeglądaj źródła

新增报警通知、指定快手视频生成

zhangyong 1 rok temu
rodzic
commit
e06c530813

+ 6 - 0
common/feishu.py

@@ -342,6 +342,12 @@ class Feishu:
                 sheet_url = "https://w42nne6hzg.feishu.cn/sheets/CPDNs06R2hux6SthZ1wcQmkAnYg?sheet=OpE35G"
                 users = "\n<at id=" + str(cls.get_userid(log_type, crawler, "wangxueke")) + "></at> <at id=" + str(
                     cls.get_userid(log_type, crawler, "muxinyi")) + "></at>\n"
+            elif crawler == "拼接视频":
+                content = text
+                sheet_url = ""
+                users = "\n<at id=" + str(cls.get_userid(log_type, crawler, "wangxueke")) + "></at> <at id=" + str(
+                    cls.get_userid(log_type, crawler, "muxinyi")) + "></at> <at id=" + str(
+                    cls.get_userid(log_type, crawler, "zhangyong")) + "></at>\n"
 
             data = json.dumps({
                 "msg_type": "interactive",

+ 14 - 13
common/material.py

@@ -100,7 +100,7 @@ class Material():
 
     # 获取音频类型
     @classmethod
-    def get_audio_type(cls, video_type, count):
+    def get_audio_type(cls, video_type, count, channel_type):
         list = []
         title_list = []
         if video_type == "口播--美文类":
@@ -118,18 +118,19 @@ class Material():
             srt = list['text']
             return audio_id, srt, title_list
         else:
-            if count == 0 or count == 1:
-                audio_type = Feishu.get_values_batch("prod", "succinct", "6VXm7q")
-                for row in audio_type[1:]:
-                    audio_id = row[0]
-                    text = row[1]
-                    title = row[2]
-                    number = {"audio_id": audio_id, "text": text}
-                    list.append(number)
-                    title_list.append(title)
-                audio_id = list[count]['audio_id']
-                srt = list[count]['text']
-                return audio_id, srt, title_list
+            if channel_type == "douyin":
+                if count == 0 or count == 1:
+                    audio_type = Feishu.get_values_batch("prod", "succinct", "6VXm7q")
+                    for row in audio_type[1:]:
+                        audio_id = row[0]
+                        text = row[1]
+                        title = row[2]
+                        number = {"audio_id": audio_id, "text": text}
+                        list.append(number)
+                        title_list.append(title)
+                    audio_id = list[count]['audio_id']
+                    srt = list[count]['text']
+                    return audio_id, srt, title_list
             else:
                 audio_type = [{"audio": "音画美文--美文类", "type": "6VXm7q"}, {"audio": "音画美文--通用类", "type": "aSNFl8"}]
                 audio_type = random.choice(audio_type)

+ 48 - 0
common/sql_help.py

@@ -0,0 +1,48 @@
+import os
+import sys
+import datetime
+
+
+
+sys.path.append(os.getcwd())
+from datetime import datetime
+from common import MysqlHelper
+
+
+class sql():
+
+    #  获取音画美文类数量-抖音
+    @classmethod
+    def get_dy_yinmei_account_id(cls):
+        current_time = datetime.now()
+        formatted_time = current_time.strftime("%Y-%m-%d")
+        count = f"""SELECT COUNT(*) AS total_count FROM ( SELECT audio, account_id FROM video_audio WHERE time = '{formatted_time}' AND video_type = 0 GROUP BY audio, account_id) AS subquery;"""
+        count = MysqlHelper.get_values(count, "prod")
+        if count == None:
+            count = 0
+        count = str(count).replace('(', '').replace(')', '').replace(',', '')
+        return int(count)
+
+    #  获取音画美文类数量-快手
+    @classmethod
+    def get_ks_yinmei_account_id(cls):
+        current_time = datetime.now()
+        formatted_time = current_time.strftime("%Y-%m-%d")
+        count = f"""SELECT COUNT(*) AS total_count FROM ( SELECT audio, account_id FROM video_audio WHERE time = '{formatted_time}' AND video_type = 3 GROUP BY audio, account_id) AS subquery;"""
+        count = MysqlHelper.get_values(count, "prod")
+        if count == None:
+            count = 0
+        count = str(count).replace('(', '').replace(')', '').replace(',', '')
+        return int(count)
+
+    #  获取口播类数量
+    @classmethod
+    def get_koubo_account_id(cls):
+        current_time = datetime.now()
+        formatted_time = current_time.strftime("%Y-%m-%d")
+        count = f"""SELECT COUNT(*) AS total_count FROM ( SELECT audio, account_id FROM video_audio WHERE time = '{formatted_time}' AND video_type = 1 GROUP BY audio, account_id) AS subquery;"""
+        count = MysqlHelper.get_values(count, "prod")
+        if count == None:
+            count = 0
+        count = str(count).replace('(', '').replace(')', '').replace(',', '')
+        return int(count)

+ 37 - 38
main.py

@@ -1,58 +1,54 @@
 import os
 import sys
-import datetime
-
 import schedule
 import time
-
-
 sys.path.append(os.getcwd())
-from datetime import datetime
-from common import MysqlHelper, Common
+from common import Common, Feishu
 from video_capture.kuaishou.kuaishou_author.kuaishou_author import kuaishouAuthor
-
+from common.sql_help import sql
 from video_stitching.video_stitching import VideoStitching
 
 from video_capture.douyin.douyin_author.douyin_author import douyinAuthor
 
 
 
-#  获取音画美文类数量
-def get_yinmei_account_id():
-    current_time = datetime.now()
-    formatted_time = current_time.strftime("%Y-%m-%d")
-    count = f"""SELECT COUNT(*) AS total_count FROM ( SELECT audio, account_id FROM video_audio WHERE time = '{formatted_time}' AND video_type = 0 GROUP BY audio, account_id) AS subquery;"""
-    print(count)
-    count = MysqlHelper.get_values(count, "prod")
-    return count
-
-
-#  获取口播类数量
-def get_koubo_account_id():
-    current_time = datetime.now()
-    formatted_time = current_time.strftime("%Y-%m-%d")
-    count = f"""SELECT COUNT(*) AS total_count FROM ( SELECT audio, account_id FROM video_audio WHERE time = '{formatted_time}' AND video_type = 1 GROUP BY audio, account_id) AS subquery;"""
-    print(count)
-    count = MysqlHelper.get_values(count, "prod")
-    return count
 
+flag = True
 def job_video_stitching():
-    yinmei_count = get_yinmei_account_id()
-    koubo_count = get_koubo_account_id()
-    if koubo_count == None:
-        koubo_count = 0
-    if yinmei_count == None:
-        yinmei_count = 0
-    yinmei_count = str(yinmei_count).replace('(', '').replace(')', '').replace(',', '')
-    koubo_count = str(koubo_count).replace('(', '').replace(')', '').replace(',', '')
-    if int(yinmei_count) < 10:
+    global flag
+    dy_yinmei_count = sql.get_dy_yinmei_account_id()
+    koubo_count = sql.get_koubo_account_id()
+    ks_yinmei_count = sql.get_ks_yinmei_account_id()
+    if int(dy_yinmei_count) < 10:
         Common.logger().info("开始执行")
         video_type = "音画美文"
-        VideoStitching.video_stitching(video_type, yinmei_count)
+        channel_type = "douyin"
+        VideoStitching.video_stitching(video_type, dy_yinmei_count, channel_type)
     elif int(koubo_count) < 10:
         Common.logger().info("开始执行")
         video_type = "口播--美文类"
-        VideoStitching.video_stitching(video_type, koubo_count)
+        channel_type = "koubo"
+        VideoStitching.video_stitching(video_type, koubo_count, channel_type)
+    elif int(ks_yinmei_count) < 10:
+        Common.logger().info("开始执行")
+        video_type = "音画美文"
+        channel_type = "kuaishou"
+        VideoStitching.video_stitching(video_type, ks_yinmei_count, channel_type)
+    count = int(dy_yinmei_count + koubo_count + ks_yinmei_count)
+    if count == 30:
+        if flag:
+            Feishu.bot('recommend', '拼接视频', '自制视频拼接完成啦,共计30条~')
+            flag = False
+    if count == 0:
+        flag = True
+
+def job_feishu_bot():
+    dy_yinmei_count = sql.get_dy_yinmei_account_id()
+    koubo_count = sql.get_koubo_account_id()
+    ks_yinmei_count = sql.get_ks_yinmei_account_id()
+    count = int(dy_yinmei_count + koubo_count + ks_yinmei_count)
+    if count < 30:
+        Feishu.bot('recommend', '拼接视频', f'视频生成异常,不符合预期,请检查\n目前生成数量如下:\n抖音视频拼接:{dy_yinmei_count}条 \n快手视频拼接:{ks_yinmei_count}条\n口播视频拼接:{koubo_count}条')
 
 def job_douyin_data():
     douyinAuthor.get_videoList()
@@ -63,12 +59,15 @@ def job_kuaishou_data():
 # 每5个小时执行一次
 schedule.every(5).hours.do(job_douyin_data)
 
-# 每5个小时执行一次
-schedule.every(6).hours.do(job_kuaishou_data)
+# 每3个小时执行一次
+schedule.every(3).hours.do(job_kuaishou_data)
 
 # 每15分钟执行一次
 schedule.every(15).minutes.do(job_video_stitching)
 
+# 每天下午1:30执行任务
+schedule.every().day.at("13:30").do(job_feishu_bot)
+
 while True:
     schedule.run_pending()
     time.sleep(1)

+ 3 - 5
video_capture/kuaishou/kuaishou_author/kuaishou_author.py

@@ -71,7 +71,7 @@ class kuaishouAuthor():
                 Common.logger().info(f"用户主页ID:{account_id}")
                 pcursor = ""
                 while True:
-                    time.sleep(random.randint(5, 10))
+                    time.sleep(random.randint(10, 50))
                     url = "https://www.kuaishou.com/graphql"
                     payload = json.dumps({
                         "operationName": "visionProfilePhotoList",
@@ -107,17 +107,15 @@ class kuaishouAuthor():
                         Common.logger().info(
                             f"接口请求失败,请更换cookie,{response.status_code}")
                         Feishu.bot('recommend', '快手', '快手cookie失效,请及时更换~')
-                        # 如果返回空信息,则随机睡眠 600, 1200 秒
-                        time.sleep(random.randint(600, 1200))
                         return
                     elif "feeds" not in response.json()["data"]["visionProfilePhotoList"]:
                         Common.logger().info(
                             f'数据为空{response.json()["data"]["visionProfilePhotoList"]}')
-                        return
+                        continue
                     elif len(response.json()["data"]["visionProfilePhotoList"]["feeds"]) == 0:
                         Common.logger().info(
                             f'数据为空{response.json()["data"]["visionProfilePhotoList"]["feeds"]}')
-                        return
+                        continue
                     pcursor = response.json()['data']['visionProfilePhotoList']['pcursor']
                     feeds = response.json()['data']['visionProfilePhotoList']['feeds']
                     count = 0

+ 18 - 11
video_stitching/video_stitching.py

@@ -53,11 +53,15 @@ class VideoStitching():
         return hours * 3600 + minutes * 60 + seconds
 
     @classmethod
-    def insert_videoAudio(cls, audio_url, i):
+    def insert_videoAudio(cls, audio_url, i, channel_type):
         current_time = datetime.now()
         formatted_time = current_time.strftime("%Y-%m-%d")
+        if channel_type == "douyin":
+            video_type = 0
+        else:
+            video_type = 2
         for j in audio_url:
-            insert_sql = f"""INSERT INTO video_audio (audio, video_id, account_id, oss_object_key, time, video_type) values ('{i}', '{j[0]}', '{j[1]}', '{j[2]}', '{formatted_time}', 0)"""
+            insert_sql = f"""INSERT INTO video_audio (audio, video_id, account_id, oss_object_key, time, video_type) values ('{i}', '{j[0]}', '{j[1]}', '{j[2]}', '{formatted_time}', {video_type})"""
             MysqlHelper.update_values(
                 sql=insert_sql,
                 env="prod",
@@ -87,8 +91,8 @@ class VideoStitching():
         return id
 
     @classmethod
-    def get_account_id(cls):
-        account_id = f"""select account_id from video_url group by account_id;"""
+    def get_account_id(cls, channel_type):
+        account_id = f"""select account_id from video_url where oss_object_key LIKE '%{channel_type}%' group by account_id ;"""
         account_id = MysqlHelper.get_values(account_id, "prod")
         return account_id
 
@@ -117,12 +121,15 @@ class VideoStitching():
 
     # 新生成视频上传到对应账号下
     @classmethod
-    def insert_piaoquantv(cls, oss_object_key, title_list, video_type):
+    def insert_piaoquantv(cls, oss_object_key, title_list, video_type, channel_type):
         #list = ["66481136", "66481137", "66481140", "66481141", "66481142"] 老用户id
         if video_type == "口播--美文类":
             list = ["67231152", "67231153", "67231154", "67231155", "67231157"]
         else:
-            list = ["67231113", "67231112", "67231111", "67231110", "67231109"]
+            if channel_type == "douyin":
+                list = ["67231113", "67231112", "67231111", "67231110", "67231109"]
+            else:
+                list = ["67413406", "67413407", "67413408", "67413409", "67413410"]
         code = 1
         for i in range(2):
             item = random.choice(list)
@@ -318,10 +325,10 @@ class VideoStitching():
             return ""
 
     @classmethod
-    def video_stitching(cls, video_type, count):
+    def video_stitching(cls, video_type, count, channel_type):
         cookie = Material.get_houtai_cookie()
         # 获取音频类型+字幕
-        audio_id, srt, title_list = Material.get_audio_type(video_type, count)
+        audio_id, srt, title_list = Material.get_audio_type(video_type, count, channel_type)
         if video_type == "口播--美文类":
             # 获取已入库的口播视频
             audio_list = cls.get_audio_list()
@@ -334,7 +341,7 @@ class VideoStitching():
                 return
         else:
             # 获取已入库的用户id
-            account_id = cls.get_account_id()
+            account_id = cls.get_account_id(channel_type)
             account = random.choice(account_id)
             account = str(account).replace('(', '').replace(')', '').replace(',', '')
             Common.logger().info(f"获取用户ID:{account}")
@@ -371,14 +378,14 @@ class VideoStitching():
                 if video_type == "口播--美文类":
                     cls.insert_video_typeAudio(videos[0], audio_id)
                 else:
-                    cls.insert_videoAudio(audio_url, audio_id)
+                    cls.insert_videoAudio(audio_url, audio_id, channel_type)
                 Common.logger().info(f"发送成功 已使用视频存入数据库完成")
                 if os.path.isfile(output_path):
                     os.remove(output_path)
                     Common.logger().info(f"文件删除成功{output_path}")
                 else:
                     Common.logger().info(f"文件不存在{output_path}")
-                piaoquantv = cls.insert_piaoquantv(oss_object_key, title_list, video_type)
+                piaoquantv = cls.insert_piaoquantv(oss_object_key, title_list, video_type, channel_type)
                 if piaoquantv:
                     Common.logger().info(f"视频添加到对应用户成功")
                     # 关闭视频文件