zhangyong 1 year ago
parent
commit
fa839c3731
3 changed files with 91 additions and 89 deletions
  1. 17 10
      common/aliyun_oss_uploading.py
  2. 59 73
      main.py
  3. 15 6
      video_stitching/video_stitching.py

+ 17 - 10
common/aliyun_oss_uploading.py

@@ -63,13 +63,20 @@ class Oss():
 
     # 获取视频链接 将视频链接有效时间设置为1天
     @classmethod
-    def get_oss_url(cls, path):
-        list = []
-        for i in path:
-            # 创建 OSS 客户端
-            auth = oss2.Auth(OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET)
-            bucket = oss2.Bucket(auth, OSS_BUCKET_ENDPOINT, OSS_BUCKET_NAME)
-            # 获取指定路径下的对象列表
-            url = bucket.sign_url('GET', i[2], 60 * 60 * 24)  # 设置链接有效期为1天(86400秒)
-            list.append([i[0], i[1], i[2], url])
-        return list
+    def get_oss_url(cls, video_type, videos):
+        auth = oss2.Auth(OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET)
+        bucket = oss2.Bucket(auth, OSS_BUCKET_ENDPOINT, OSS_BUCKET_NAME)
+        if video_type == "口播--美文类":
+            bucket.get_object_to_file(videos[0], f'./video_stitching/video_material/koubo.mp4')
+            return ""
+        else:
+            list = []
+            for i in videos:
+                try:
+                    # 获取指定路径下的对象列表
+                    filename = i[2].split("/")[-1]
+                    bucket.get_object_to_file(i[2], f'./video_stitching/video_material/{filename}.mp4')
+                    list.append([i[0], i[1], i[2], filename])
+                except Exception:
+                    continue
+            return list

+ 59 - 73
main.py

@@ -1,7 +1,6 @@
 import os
 import sys
 
-import oss2
 import schedule
 import time
 sys.path.append(os.getcwd())
@@ -14,76 +13,63 @@ from video_capture.douyin.douyin_author.douyin_author import douyinAuthor
 
 
 
-#
-# flag = True
-# def job_video_stitching():
-#     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 = "音画美文"
-#         channel_type = "douyin"
-#         VideoStitching.video_stitching(video_type, dy_yinmei_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)
-#     elif int(koubo_count) < 10:
-#         Common.logger().info("开始执行")
-#         video_type = "口播--美文类"
-#         channel_type = "koubo"
-#         VideoStitching.video_stitching(video_type, koubo_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()
-#
-# def job_kuaishou_data():
-#     kuaishouAuthor.get_kuaishou_videoList()
-#
-# # 每5个小时执行一次
-# schedule.every(5).hours.do(job_douyin_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)
 
-OSS_ACCESS_KEY_ID = "LTAIP6x1l3DXfSxm"
-OSS_ACCESS_KEY_SECRET = "KbTaM9ars4OX3PMS6Xm7rtxGr1FLon"
-OSS_BUCKET_ENDPOINT = "oss-cn-hangzhou-internal.aliyuncs.com"# 内网地址
-OSS_BUCKET_NAME = "art-crawler"
-koubo_count = 1
-video_type = "口播--美文类"
-channel_type = "koubo"
-auth = oss2.Auth(OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET)
-bucket = oss2.Bucket(auth, OSS_BUCKET_ENDPOINT, OSS_BUCKET_NAME)
-if video_type == "口播--美文类":
-    bucket.get_object_to_file("koubo/fo1", f'./video_stitching/video_material/koubo.mp4')
-    print("完成")
-# VideoStitching.video_stitching(video_type, koubo_count, channel_type)
+flag = True
+def job_video_stitching():
+    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 = "音画美文"
+        channel_type = "douyin"
+        VideoStitching.video_stitching(video_type, dy_yinmei_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)
+    elif int(koubo_count) < 10:
+        Common.logger().info("开始执行")
+        video_type = "口播--美文类"
+        channel_type = "koubo"
+        VideoStitching.video_stitching(video_type, koubo_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()
+
+def job_kuaishou_data():
+    kuaishouAuthor.get_kuaishou_videoList()
+
+# 每5个小时执行一次
+schedule.every(5).hours.do(job_douyin_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)
+

+ 15 - 6
video_stitching/video_stitching.py

@@ -98,7 +98,7 @@ class VideoStitching():
 
     @classmethod
     def get_audio_list(cls):
-        audio_list = f"""select oss_object_key from video_koubo_url;"""
+        audio_list = f"""select oss_object_key from video_koubo_url ;"""
         audio_list = MysqlHelper.get_values(audio_list, "prod")
         return audio_list
 
@@ -188,7 +188,7 @@ class VideoStitching():
         duration_limit = mp3.duration
         if type_audio == "口播--美文类":
             # 读取视频文件,获取视频时长
-            clip = f"https://art-crawler.oss-cn-hangzhou.aliyuncs.com/{videos[0]}"
+            clip = f"./video_stitching/video_material/koubo.mp4"
             clip = VideoFileClip(clip)
             video_duration = clip.duration
             # 计算需要循环播放的视频个数
@@ -202,7 +202,8 @@ class VideoStitching():
         else:
             # 遍历每个视频并计算总时长
             for i, video in enumerate(videos):
-                clip = VideoFileClip(f"https://art-crawler.oss-cn-hangzhou.aliyuncs.com/{video[2]}")
+                filename = video[2].split("/")[-1]
+                clip = VideoFileClip(f'./video_stitching/video_material/{filename}.mp4')
                 clips.append(clip)
                 total_duration += clip.duration
                 if total_duration >= duration_limit:
@@ -356,7 +357,7 @@ class VideoStitching():
             # 获取 未使用的视频链接
             url_list = cls.get_url_list(audio_id, account)
             videos = [list(item) for item in url_list]
-        # videos = Oss.get_oss_url(videos)
+        videos = Oss.get_oss_url(video_type, videos)
         # 视频截取
         try:
             audio_url, video_with_subtitles, clips = cls.concatenate_videos(videos, str(audio), srt, video_type)
@@ -384,6 +385,12 @@ class VideoStitching():
                     Common.logger().info(f"文件删除成功{output_path}")
                 else:
                     Common.logger().info(f"文件不存在{output_path}")
+                if video_type == "口播--美文类":
+                    os.remove("./video_stitching/video_material/koubo.mp4")
+                else:
+                    for video in videos:
+                        filename = video[2].split("/")[-1]
+                        os.remove(f'./video_stitching/video_material/{filename}.mp4')
                 piaoquantv = cls.insert_piaoquantv(oss_object_key, title_list, video_type, channel_type)
                 if piaoquantv:
                     Common.logger().info(f"视频添加到对应用户成功")
@@ -401,7 +408,9 @@ class VideoStitching():
 
 
 if __name__ == '__main__':
-    video_type = "口播--美文类"
-    VideoStitching.video_stitching(video_type)
+    koubo_count = 1
+    video_type = "口播"
+    channel_type = "douyin"
+    VideoStitching.video_stitching(video_type, koubo_count, channel_type)