Browse Source

增加时长限制功能

zhangyong 10 tháng trước cách đây
mục cha
commit
e624c62ae6

+ 16 - 0
data_channel/data_help.py

@@ -0,0 +1,16 @@
+import cv2
+
+
+class dataHelp():
+    """
+    获取视频时长
+    """
+    @classmethod
+    def video_duration(cls, filename):
+        cap = cv2.VideoCapture(filename)
+        if cap.isOpened():
+            rate = cap.get(5)
+            frame_num = cap.get(7)
+            duration = frame_num / rate
+            return duration
+        return 0

+ 10 - 7
data_channel/douyin.py

@@ -7,6 +7,7 @@ import urllib3
 from requests.adapters import HTTPAdapter
 from requests.adapters import HTTPAdapter
 from common import Material, Common, Feishu
 from common import Material, Common, Feishu
 from common.sql_help import sqlCollect
 from common.sql_help import sqlCollect
+from data_channel.data_help import dataHelp
 from data_channel.douyin_help import DouYinHelper
 from data_channel.douyin_help import DouYinHelper
 
 
 
 
@@ -55,7 +56,7 @@ class DY:
             if data == [] and len(data) == 0:
             if data == [] and len(data) == 0:
                 return list
                 return list
             if not data[0].get('search_impr').get('entity_type'):
             if not data[0].get('search_impr').get('entity_type'):
-                Feishu.bot(mark, '机器自动改造消息通知', f'今日任务为空,请关注', name)
+                Feishu.bot(mark, '机器自动改造消息通知', f'抖音cookie过期,请及时更换', name)
                 time.sleep(900)
                 time.sleep(900)
                 continue
                 continue
             response.close()
             response.close()
@@ -69,10 +70,12 @@ class DY:
                         video_uri = data[i].get('video', {}).get('play_addr', {}).get('uri')
                         video_uri = data[i].get('video', {}).get('play_addr', {}).get('uri')
                         ratio = f'{data[i].get("video", {}).get("height")}p'
                         ratio = f'{data[i].get("video", {}).get("height")}p'
                         video_url = f'https://www.iesdouyin.com/aweme/v1/play/?video_id={video_uri}&ratio={ratio}&line=0'  # 视频链接
                         video_url = f'https://www.iesdouyin.com/aweme/v1/play/?video_id={video_uri}&ratio={ratio}&line=0'  # 视频链接
-                        cover_url = data[i].get('video').get('cover').get('url_list')[0]  # 视频封面
-                        all_data = {"video_id": video_id, "cover": cover_url, "video_url": video_url}
-                        list.append(all_data)
-                        if len(list) == int(number):
-                            Common.logger("log").info(f"获取抖音视频总数:{len(list)}\n")
-                            return list
+                        duration = dataHelp.video_duration(video_url)
+                        if int(duration) >= 45:
+                            cover_url = data[i].get('video').get('cover').get('url_list')[0]  # 视频封面
+                            all_data = {"video_id": video_id, "cover": cover_url, "video_url": video_url}
+                            list.append(all_data)
+                            if len(list) == int(number):
+                                Common.logger("log").info(f"获取抖音视频总数:{len(list)}\n")
+                                return list
         return list
         return list

+ 9 - 6
data_channel/shipinhao.py

@@ -6,6 +6,7 @@ import requests
 
 
 from common import Common
 from common import Common
 from common.sql_help import sqlCollect
 from common.sql_help import sqlCollect
+from data_channel.data_help import dataHelp
 
 
 
 
 class SPH:
 class SPH:
@@ -95,12 +96,14 @@ class SPH:
                             time.sleep(random.randint(0, 1))
                             time.sleep(random.randint(0, 1))
                             video_obj = response.json()
                             video_obj = response.json()
                             video_url = video_obj.get('DownloadAddress')
                             video_url = video_obj.get('DownloadAddress')
-                            cover = video_obj.get('thumb_url')
-                            all_data = {"video_id": objectId, "cover": cover, "video_url": video_url}
-                            list.append(all_data)
-                            if len(list) == int(number):
-                                Common.logger("log").info(f"获取视频号视频总数:{len(list)}\n")
-                                return list
+                            duration = dataHelp.video_duration(video_url)
+                            if int(duration) >= 45:
+                                cover = video_obj.get('thumb_url')
+                                all_data = {"video_id": objectId, "cover": cover, "video_url": video_url}
+                                list.append(all_data)
+                                if len(list) == int(number):
+                                    Common.logger("log").info(f"获取视频号视频总数:{len(list)}\n")
+                                    return list
             return list
             return list
         return []
         return []
 
 

+ 4 - 10
video_rewriting/video_prep.py

@@ -3,6 +3,7 @@ import os
 import random
 import random
 import threading
 import threading
 import time
 import time
+
 from datetime import datetime
 from datetime import datetime
 import concurrent.futures
 import concurrent.futures
 from common import Material, Feishu, Common, Oss
 from common import Material, Feishu, Common, Oss
@@ -18,13 +19,6 @@ config.read('./config.ini')
 
 
 class getVideo:
 class getVideo:
 
 
-    """
-    数据处理
-    """
-    @classmethod
-    def get_video(cls):
-        pass
-
     """
     """
     根据标示+任务标示创建目录
     根据标示+任务标示创建目录
     """
     """
@@ -116,11 +110,11 @@ class getVideo:
                 # elif channel_id == "快手":
                 # elif channel_id == "快手":
                 #     pass
                 #     pass
                 if len(data_list) == 0:
                 if len(data_list) == 0:
-                    Common.logger("log").info(f"{task_mark}下的视频ID{id} 已经改造过了")
-                    Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务下的用户ID{id},没有已经改造的视频了', name)
+                    Common.logger("log").info(f"{task_mark}下的视频ID{url} 已经改造过了")
+                    Feishu.bot(mark, '机器自动改造消息通知', f'{task_mark}任务下的用户ID{url},没有已经改造的视频了', name)
                     cls.remove_files(video_path_url)
                     cls.remove_files(video_path_url)
                     continue
                     continue
-                Common.logger("log").info(f"{task_mark}下的ID{id} 获取视频完成,共{len(data_list)}条")
+                Common.logger("log").info(f"{task_mark}下的ID{url} 获取视频完成,共{len(data_list)}条")
 
 
                 try:
                 try:
                     for video in data_list:
                     for video in data_list: