瀏覽代碼

增加新规则

zhangyong 1 年之前
父節點
當前提交
e5ae3e2d2e
共有 3 個文件被更改,包括 52 次插入32 次删除
  1. 9 11
      common/material.py
  2. 26 9
      main.py
  3. 17 12
      video_stitching/video_stitching.py

+ 9 - 11
common/material.py

@@ -72,17 +72,11 @@ class Material():
 
 
     # 获取音频类型
     # 获取音频类型
     @classmethod
     @classmethod
-    def get_audio_type(cls):
-        audio_type = [{"audio": "音画美文--美文类", "type": "6VXm7q"}, {"audio": "音画美文--通用类", "type": "aSNFl8"},
-                      {"audio": "口播--美文类", "type": "Sed8gy"}]
-        audio_type = random.choice(audio_type)
-
-        type_audio = audio_type['audio']
-        type = audio_type['type']
-        audio_type = Feishu.get_values_batch("prod", "succinct", type)
+    def get_audio_type(cls, video_type):
         list = []
         list = []
         title_list = []
         title_list = []
-        if type_audio == "口播--美文类":
+        if video_type == "口播--美文类":
+            audio_type = Feishu.get_values_batch("prod", "succinct", "Sed8gy")
             for row in audio_type[1:]:
             for row in audio_type[1:]:
                 audio_id = row[2]
                 audio_id = row[2]
                 text = row[3]
                 text = row[3]
@@ -94,8 +88,12 @@ class Material():
             list = random.choice(list)
             list = random.choice(list)
             audio_id = list['audio_id']
             audio_id = list['audio_id']
             srt = list['text']
             srt = list['text']
-            return audio_id, srt, title_list, type_audio
+            return audio_id, srt, title_list
         else:
         else:
+            audio_type = [{"audio": "音画美文--美文类", "type": "6VXm7q"}, {"audio": "音画美文--通用类", "type": "aSNFl8"}]
+            audio_type = random.choice(audio_type)
+            type = audio_type['type']
+            audio_type = Feishu.get_values_batch("prod", "succinct", type)
             for row in audio_type[1:]:
             for row in audio_type[1:]:
                 audio_id = row[0]
                 audio_id = row[0]
                 text = row[1]
                 text = row[1]
@@ -106,7 +104,7 @@ class Material():
             list = random.choice(list)
             list = random.choice(list)
             audio_id = list['audio_id']
             audio_id = list['audio_id']
             srt = list['text']
             srt = list['text']
-            return audio_id, srt, title_list, type_audio
+            return audio_id, srt, title_list
 
 
 
 
 
 

+ 26 - 9
main.py

@@ -14,25 +14,42 @@ 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_account_id():
+#  获取口播类数量
+def get_koubo_account_id():
     current_time = datetime.now()
     current_time = datetime.now()
     formatted_time = current_time.strftime("%Y-%m-%d")
     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}' GROUP BY audio, account_id) AS subquery;"""
+    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)
     print(count)
     count = MysqlHelper.get_values(count, "prod")
     count = MysqlHelper.get_values(count, "prod")
     return count
     return count
 
 
 def job_video_stitching():
 def job_video_stitching():
-    # 在这里编写需要执行的任务代码
-    count = get_account_id()
-    if count == None:
-        count = 0
-    count = str(count).replace('(', '').replace(')', '').replace(',', '')
-    if int(count) < 20:
+    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:
+        Common.logger().info("开始执行")
+        video_type = "音画美文"
+        VideoStitching.video_stitching(video_type)
+    elif int(koubo_count) < 10:
         Common.logger().info("开始执行")
         Common.logger().info("开始执行")
-        VideoStitching.video_stitching()
+        video_type = "口播--美文类"
+        VideoStitching.video_stitching(video_type)
 
 
 def job_douyin_data():
 def job_douyin_data():
     douyinAuthor.get_videoList()
     douyinAuthor.get_videoList()

+ 17 - 12
video_stitching/video_stitching.py

@@ -57,7 +57,7 @@ class VideoStitching():
         current_time = datetime.now()
         current_time = datetime.now()
         formatted_time = current_time.strftime("%Y-%m-%d")
         formatted_time = current_time.strftime("%Y-%m-%d")
         for j in audio_url:
         for j in audio_url:
-            insert_sql = f"""INSERT INTO video_audio (audio, video_id, account_id, oss_object_key, time) values ('{i}', '{j[0]}', '{j[1]}', '{j[2]}', '{formatted_time}')"""
+            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)"""
             MysqlHelper.update_values(
             MysqlHelper.update_values(
                 sql=insert_sql,
                 sql=insert_sql,
                 env="prod",
                 env="prod",
@@ -70,7 +70,7 @@ class VideoStitching():
     def insert_video_typeAudio(cls, video, audio_id):
     def insert_video_typeAudio(cls, video, audio_id):
         current_time = datetime.now()
         current_time = datetime.now()
         formatted_time = current_time.strftime("%Y-%m-%d")
         formatted_time = current_time.strftime("%Y-%m-%d")
-        insert_sql = f"""INSERT INTO video_audio (audio, account_id, oss_object_key, time) values ('{audio_id}', '{video}', '{video}', '{formatted_time}')"""
+        insert_sql = f"""INSERT INTO video_audio (audio, account_id, oss_object_key, time, video_type) values ('{audio_id}', '{video}', '{video}', '{formatted_time}', 1)"""
         MysqlHelper.update_values(
         MysqlHelper.update_values(
             sql=insert_sql,
             sql=insert_sql,
             env="prod",
             env="prod",
@@ -117,9 +117,13 @@ class VideoStitching():
 
 
     # 新生成视频上传到对应账号下
     # 新生成视频上传到对应账号下
     @classmethod
     @classmethod
-    def insert_piaoquantv(cls, oss_object_key, title_list):
+    def insert_piaoquantv(cls, oss_object_key, title_list, video_type):
+        #list = ["66481136", "66481137", "66481140", "66481141", "66481142"] 老用户id
+        if video_type == "口播--美文类":
+            list = ["67231152", "67231153", "67231154", "67231155", "67231157"]
+        else:
+            list = ["67231113", "67231112", "67231111", "67231110", "67231109"]
         code = 1
         code = 1
-        list = ["66481136", "66481137", "66481140", "66481141", "66481142"]
         for i in range(2):
         for i in range(2):
             item = random.choice(list)
             item = random.choice(list)
             title_list = [item for item in title_list if item is not None]
             title_list = [item for item in title_list if item is not None]
@@ -314,11 +318,11 @@ class VideoStitching():
             return ""
             return ""
 
 
     @classmethod
     @classmethod
-    def video_stitching(cls):
+    def video_stitching(cls, video_type):
         cookie = Material.get_houtai_cookie()
         cookie = Material.get_houtai_cookie()
         # 获取音频类型+字幕
         # 获取音频类型+字幕
-        audio_id, srt, title_list, type_audio = Material.get_audio_type()
-        if type_audio == "口播--美文类":
+        audio_id, srt, title_list = Material.get_audio_type(video_type)
+        if video_type == "口播--美文类":
             # 获取已入库的口播视频
             # 获取已入库的口播视频
             audio_list = cls.get_audio_list()
             audio_list = cls.get_audio_list()
             videos = [list(item) for item in audio_list]
             videos = [list(item) for item in audio_list]
@@ -326,7 +330,7 @@ class VideoStitching():
             # 判断该视频+音频是否生成过视频
             # 判断该视频+音频是否生成过视频
             video = VideoStitching.get_audio_url_list(videos, audio_id)
             video = VideoStitching.get_audio_url_list(videos, audio_id)
             if video:
             if video:
-                Common.logger().info(f"该视频+音频已经生成过视频,不做视频拼接")
+                Common.logger().info(f"该视频+音频已经生成过视频,不做视频拼接")
                 return
                 return
         else:
         else:
             # 获取已入库的用户id
             # 获取已入库的用户id
@@ -349,7 +353,7 @@ class VideoStitching():
         # videos = Oss.get_oss_url(videos)
         # videos = Oss.get_oss_url(videos)
         # 视频截取
         # 视频截取
         try:
         try:
-            audio_url, video_with_subtitles, clips = cls.concatenate_videos(videos, str(audio), srt, type_audio)
+            audio_url, video_with_subtitles, clips = cls.concatenate_videos(videos, str(audio), srt, video_type)
             if len(audio_url) == 0:
             if len(audio_url) == 0:
                 Common.logger().info(f"视频生成失败")
                 Common.logger().info(f"视频生成失败")
             # 随机生成视频id
             # 随机生成视频id
@@ -364,7 +368,7 @@ class VideoStitching():
             if status == 200:
             if status == 200:
                 time.sleep(10)
                 time.sleep(10)
                 # 发送成功 已使用视频存入数据库
                 # 发送成功 已使用视频存入数据库
-                if type_audio == "口播--美文类":
+                if video_type == "口播--美文类":
                     cls.insert_video_typeAudio(videos[0], audio_id)
                     cls.insert_video_typeAudio(videos[0], audio_id)
                 else:
                 else:
                     cls.insert_videoAudio(audio_url, audio_id)
                     cls.insert_videoAudio(audio_url, audio_id)
@@ -374,7 +378,7 @@ class VideoStitching():
                     Common.logger().info(f"文件删除成功{output_path}")
                     Common.logger().info(f"文件删除成功{output_path}")
                 else:
                 else:
                     Common.logger().info(f"文件不存在{output_path}")
                     Common.logger().info(f"文件不存在{output_path}")
-                piaoquantv = cls.insert_piaoquantv(oss_object_key, title_list)
+                piaoquantv = cls.insert_piaoquantv(oss_object_key, title_list, video_type)
                 if piaoquantv:
                 if piaoquantv:
                     Common.logger().info(f"视频添加到对应用户成功")
                     Common.logger().info(f"视频添加到对应用户成功")
                     # 关闭视频文件
                     # 关闭视频文件
@@ -391,6 +395,7 @@ class VideoStitching():
 
 
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
-    VideoStitching.video_stitching()
+    video_type = "口播--美文类"
+    VideoStitching.video_stitching(video_type)