浏览代码

增加快手小程序

zhangyong 5 月之前
父节点
当前提交
d3baf8c76d
共有 4 个文件被更改,包括 125 次插入0 次删除
  1. 11 0
      common/sql_help.py
  2. 89 0
      data_channel/ks_xcx.py
  3. 20 0
      job_ks_xcx.py
  4. 5 0
      video_rewriting/video_processor.py

+ 11 - 0
common/sql_help.py

@@ -39,6 +39,17 @@ class sqlCollect():
             return False
         return True
 
+    """
+   快手小程序判断该任务id是否用过
+   """
+    @classmethod
+    def ks_is_used_xcx(cls, video_id, channel):
+        sql = """SELECT used_video_id FROM pj_video_data WHERE used_video_id = %s AND channel = %s  AND data_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) ORDER BY data_time DESC LIMIT 1;"""
+        data = MysqlHelper.get_values(sql, (str(video_id),  channel))
+        if len(data) == 0 or data == ():
+            return False
+        return True
+
     @classmethod
     def get_history_id(cls, channel, url):
         """

+ 89 - 0
data_channel/ks_xcx.py

@@ -0,0 +1,89 @@
+import json
+import time
+
+import requests
+
+from common import Feishu, AliyunLogger
+from common.sql_help import sqlCollect
+
+
+class KSXCX:
+    @classmethod
+    def get_xcx_date(cls):
+        list = []
+        try:
+            url = "http://8.217.192.46:8889/crawler/kuai_shou_mp/recommend"
+
+            payload = json.dumps({
+                "cursor": ""
+            })
+            headers = {
+                'Content-Type': 'application/json'
+            }
+
+            response = requests.request("POST", url, headers=headers, data=payload)
+            response = response.json()
+            code = response['code']
+            if code == 0:
+
+                data_list = response['data']['data']
+                for data in data_list:
+                    type = int(data['type'])
+                    if type != 1:
+                        continue
+                    photo_type = data['photoType']
+                    if photo_type != "VIDEO":
+                        continue
+                    duration = int(int(data["duration"])/1000)
+
+                    cover_url = data['webpCoverUrls'][0]['url']
+                    video_url = data['mainMvUrls'][0]['url']
+                    like_count = data.get('likeCount', 0)
+                    timestamp = data['timestamp']
+                    share_count = data.get('shareCount', 0)
+                    comment_count = data.get('commentCount', 0)
+                    view_count = data.get('viewCount', 0)
+                    title = data['caption']
+                    photo_id = data['photoId']
+                    user_name = data['userName']
+                    log_data = f"user:快手小程序,,video_id:{photo_id},,video_url:{video_url},original_title:{title},,share_count:{share_count},,view_count:{view_count},,duration:{duration}"
+                    AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id, "扫描到一条视频", "2001", log_data)
+                    status = sqlCollect.ks_is_used_xcx(photo_id,"快手小程序")
+                    if status:
+                        AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id, "该视频已改造过", "2002", log_data)
+                        continue
+                    if duration <= 30:
+                        AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id,
+                                             f"不符合规则:时长不符合规则小于30秒,视频时长{duration}", "2003",
+                                             log_data)
+                        continue
+                    if int(share_count) < 1000:
+                        AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id,
+                                             f"分享小于1000,实际点赞{share_count}", "2003",
+                                             log_data)
+                        continue
+                    video_percent = '%.4f' % (int(share_count) / int(like_count))
+                    if float(video_percent) < 0.15:
+                        AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id,
+                                             f"分享/点赞 < 15%,实际占比{video_percent}", "2003",
+                                             log_data)
+                        continue
+                    all_data = {"video_id": photo_id, "cover": cover_url, "video_url": video_url,
+                                "rule": video_percent,
+                                "old_title": title}
+                    if not list and  any(item["video_id"] == all_data["video_id"] for item in list):
+                        AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id, "重复视频", "2002",
+                                             log_data)
+
+                        continue
+                    list.append(all_data)
+
+                    AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id, "符合规则等待改造", "2004", log_data)
+                return list
+        except Exception as e:
+            return list
+
+
+
+if __name__ == '__main__':
+    KSXCX.get_xcx_date()

+ 20 - 0
job_ks_xcx.py

@@ -0,0 +1,20 @@
+
+import time
+from common import Material
+
+from video_rewriting.video_processor import VideoProcessor
+def video_task_start():
+    """处理视频任务,返回用户名并根据结果决定延迟时间"""
+    data = Material.feishu_list()[19]
+    while True:
+        try:
+            print("开始执行任务")
+            mark = VideoProcessor.main(data)
+            print(f"返回用户名: {mark}")
+            time.sleep(120 if mark else 120)  # 根据 mark 是否为空设置延迟
+        except Exception as e:
+            print("处理任务时出现异常:", e)
+            time.sleep(10)
+            continue
+if __name__ == '__main__':
+    video_task_start()

+ 5 - 0
video_rewriting/video_processor.py

@@ -21,6 +21,7 @@ from data_channel.ks_feed import KSFeed
 from data_channel.ks_keyword import KsKeyword
 from data_channel.ks_ls import KSLS
 from data_channel.ks_pc_keyword import KsPcKeyword
+from data_channel.ks_xcx import KSXCX
 from data_channel.kuaishou import KS
 from data_channel.kuaishouchuangzuozhe import KsFeedVideo
 from data_channel.piaoquan import PQ
@@ -421,6 +422,8 @@ class VideoProcessor:
                                 sheet = "9Ii8lw"
                             elif name == "视频号推荐流":
                                 sheet = "hMBv7T"
+                            elif name == "快手小程序":
+                                sheet = "GeDT6Q"
                             Feishu.insert_columns("ILb4sa0LahddRktnRipcu2vQnLb", sheet, "ROWS", 1, 2)
                             time.sleep(0.5)
                             Feishu.update_values("ILb4sa0LahddRktnRipcu2vQnLb", sheet, "A2:Z2", values)
@@ -465,6 +468,8 @@ class VideoProcessor:
             return KSFeed.get_feed_date()
         elif channel_id == '视频号推荐流':
             return SPHFeed.get_feed_date()
+        elif channel_id == '快手小程序':
+            return KSXCX.get_xcx_date()
 
 
     @classmethod