zhangyong 9 months ago
parent
commit
4978283232
4 changed files with 16 additions and 23 deletions
  1. 6 12
      common/aliyun_oss.py
  2. 3 5
      common/sql_help.py
  3. 1 1
      config.ini
  4. 6 5
      video_rewriting/video_prep.py

+ 6 - 12
common/aliyun_oss.py

@@ -67,18 +67,12 @@ class Oss():
 
     # 获取视频链接 将视频链接有效时间设置为1天
     @classmethod
-    def get_oss_url(cls, videos, video_path):
+    def get_oss_url(cls, video_path_url, v_id, before_path):
+        video = video_path_url + str(v_id) + '.mp4'
         auth = oss2.Auth(OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET)
-        bucket = oss2.Bucket(auth, OSS_BUCKET_ENDPOINT, OSS_BUCKET_NAME)
-        list = []
-        for i in videos:
-            try:
-                # 获取指定路径下的对象列表
-                filename = i[2].split("/")[-1]
-                bucket.get_object_to_file(i[2], f'{video_path}{filename}.mp4')
-                list.append([i[0], i[1], i[2], f'{video_path}{filename}.mp4'])
-            except Exception:
-                continue
-        return list
+        bucket = oss2.Bucket(auth, OSS_BUCKET_ENDPOINT, "art-pubbucket")
+        # 获取指定路径下的对象列表
+        bucket.get_object_to_file(before_path, video)
+        return video
 
 

+ 3 - 5
common/sql_help.py

@@ -12,10 +12,8 @@ class sqlCollect():
     """
     @classmethod
     def update_task_tencent_material(cls, video_id, oss_object_key):
-        current_time = datetime.now()
-        formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
-        insert_sql = f"""UPDATE ad_put_tencent_material_upload_handle SET video_after_path = '{oss_object_key}', processe_node = 1, update_time = '{formatted_time}' WHERE video_id = {video_id};"""
-        data = MysqlHelper.update_values(
+        insert_sql = f"""UPDATE ad_put_tencent_material_upload_handle SET video_after_path = '{oss_object_key}', processe_node = 1 WHERE video_id = {video_id};"""
+        MysqlHelper.update_values(
             sql=insert_sql
         )
 
@@ -27,7 +25,7 @@ class sqlCollect():
     def is_video_id(cls):
         current_time = datetime.now()
         formatted_time = current_time.strftime("%Y-%m-%d")
-        sql = f"""SELECT video_id FROM ad_put_tencent_material_upload_handle WHERE processe_node = '0' AND update_time LIKE '{formatted_time}%' AND is_delete = 0;"""
+        sql = f"""SELECT video_id, video_before_path FROM ad_put_tencent_material_upload_handle WHERE processe_node = '0' AND update_time LIKE '{formatted_time}%' AND is_delete = 0;"""
         data = MysqlHelper.get_values(sql)
         return data
 

+ 1 - 1
config.ini

@@ -1,5 +1,5 @@
 [PATHS]
-;VIDEO_PATH = /Users/tzld/Desktop/guanggao_video/path/
+;VIDEO_PATH = /Users/tzld/Desktop/ad_material_video/path/
 VIDEO_PATH = /root/ad_material_video/path/
 
 

+ 6 - 5
video_rewriting/video_prep.py

@@ -53,14 +53,15 @@ class getVideo:
     def video_task(cls):
         video_list = sqlCollect.is_video_id()
         if video_list:
-            videos = [item[0] for item in video_list]
+            videos = {int(key): value for key, value in video_list}
             video_path_url = cls.create_folders()  # 创建目录
-            for v_id in videos:
+            for v_id, before_path in videos.items():
+                time.sleep(2)
                 try:
-                    video_url, new_title = PQ.get_pw_url(v_id)
-                    new_video_path = PQ.download_video(video_url, video_path_url, v_id)  # 下载视频地址
+                    new_video_path = Oss.get_oss_url(video_path_url, v_id, before_path)  # 下载视频地址
+                    time.sleep(2)
                     if new_video_path == '':
-                        Common.logger("log").info(f"{video_url}视频下载失败")
+                        Common.logger("log").info(f"{v_id}视频下载失败")
                         cls.remove_files(video_path_url)
                         continue
                     url = FFmpeg.video_duration(new_video_path, video_path_url, v_id)