Browse Source

单点视频过期处理

zhangyong 8 months ago
parent
commit
e706cab98e

+ 2 - 1
common/feishu_utils.py

@@ -299,7 +299,8 @@ class Feishu:
                 "yuzhuoyi": "18624010360",
                 "luojunhui": "18801281360",
                 "fanjun": "15200827642",
-                "zhangyong": "17600025055"
+                "zhangyong": "17600025055",
+                'liukunyu': "18810931977"
             }
             username = name_phone_dict.get(username)
 

+ 1 - 1
common/sql_help.py

@@ -182,7 +182,7 @@ class sqlCollect():
         """
         获取视频号单点内容
         """
-        sql = f"""select video_id,title,author_id,author_name,cover_url,video_url,video_duration,from_user_id,from_user_name,from_group_id,from_group_name,source from dandian_content where from_user_name = %s and has_used = 0 """
+        sql = f"""select video_id,title,author_id,author_name,cover_url,video_url,video_duration,from_user_id,from_user_name,from_group_id,from_group_name,source,wx_msg from dandian_content where from_user_name = %s and has_used = 0 """
         data = AigcMysqlHelper.get_values(sql, (url))
         return data
 

+ 1 - 1
data_channel/douyin.py

@@ -55,7 +55,7 @@ class DY:
             data = obj.get('aweme_list', [])
             if data == [] and len(data) == 0:
                 if name == '抖音品类账号' or name == '抖音品类账号-1':
-                    Feishu.bot("刘坤宇", '机器自动改造消息通知', f'抖音-{name}cookie过期,请及时更换', 'liukunyu')
+                    Feishu.bot("liukunyu", '机器自动改造消息通知', f'抖音-{name}cookie过期,请及时更换', '刘坤宇')
                 else:
                     Feishu.bot(mark, '机器自动改造消息通知', f'抖音-{name}cookie过期,请及时更换', name)
                 return list

+ 49 - 11
data_channel/piaoquan.py

@@ -1,4 +1,5 @@
 import random
+import re
 import time
 import json
 import requests
@@ -263,27 +264,63 @@ class PQ:
         else:
             return ''
 
+    """
+    单点视频重新获取视频链接
+    """
+    @classmethod
+    def get_dd_video_url(cls, wx_msg):
+        try:
+            url = "http://8.217.190.241:8888/api/wei_xin/msg/callback"
+
+            # payload = json.loads(wx_msg)
+            headers = {
+                'Content-Type': 'application/json'
+            }
+            response = requests.request("POST", url, headers=headers, data=wx_msg.encode())
+            response = response.json()
+            url_video = response['video_url']
+            return url_video
+        except Exception as e:
+            print(e)
+            return None
+
 
     """
     票圈站内视频下载
     """
     @classmethod
-    def download_video(cls, video_url, video_path_url, video_id):
-        video = video_path_url + str(video_id) + '.mp4'
-        try:
-            for i in range(3):
+    def download_video(cls, video_url, video_path_url, video_id, video, channel_id):
+        url_video = video_url
+        new_video = video_path_url + str(video_id) + '.mp4'
+        for i in range(3):
+            try:
                 payload = {}
                 headers = {}
-                response = requests.request("GET", video_url, headers=headers, data=payload)
+                response = requests.request("GET", url_video, headers=headers, data=payload, timeout=5)
                 if response.status_code == 200:
-                    with open(f"{video}", "wb") as file:
+                    with open(f"{new_video}", "wb") as file:
                         # 将响应内容写入文件
                         file.write(response.content)
                     time.sleep(5)
-                    return video
-            return video
-        except Exception:
-            return video
+                    return new_video
+                else:
+                    if channel_id == '单点视频':
+                        wx_msg = video['wx_msg']
+                        if wx_msg:
+                            url_videos = cls.get_dd_video_url(wx_msg)
+                            if url_videos:
+                                url_video = url_videos
+            except Exception:
+                if channel_id == '单点视频':
+                    wx_msg = video['wx_msg']
+                    if wx_msg:
+                        url_videos = cls.get_dd_video_url(wx_msg)
+                        if url_videos:
+                            url_video = url_videos
+                if i == 3:
+                    return new_video
+            return new_video
+
 
     """
     票圈站内视频下载
@@ -308,5 +345,6 @@ class PQ:
 
 if __name__ == '__main__':
     url= 'http://111.51.148.73/ksc1/55LDHcm2DuGHbBbzIDfqMh-vfVhaCuIXZG0szwmCZj9pXLmq7otQhUyGXtBtc13Rb0C49a4FzRU5xfUaRQb6De46IO6hQBVqzjOkFArRDfTC7u9BThi0Bsa2w6PP_6dg7WQYKxU6ZIbYI2tnLfOXU5Ira-DEZuGDQbgpZstADnGtvLMkOiB6DImlhfgdxWIZ.mp4?tag=1-1724839019-sp-0-lgl7lhkrnt-8937a5c247b0f313&provider=self&ocid=341&clientCacheKey=3x3br4x5z5hew32_bF.mp4&tt=bF&di=6f31a709&bp=10001'
-    a = PQ.download_video(url,'/Users/tzld/Desktop/video_rewriting/path','70100016')
+    video = {"wx_msg": '{"TypeName":"AddMsg","Appid":"wx_GtAew_wmLbsHMbpDe7Hwk","Data":{"MsgId":1176686077,"FromUserName":{"string":"51757111911@chatroom"},"ToUserName":{"string":"wxid_mr9pdsanc99422"},"MsgType":1,"Content":{"string":"wxid_3379403802612:\n6.41 复制打开抖音,看看【Zooey的作品】被一只青蛙问候了?!  https://v.douyin.com/ihHknvbV/ w@f.bA YZm:/ 06/05 "},"Status":3,"ImgStatus":1,"ImgBuf":{"iLen":0},"CreateTime":1725343506,"MsgSource":"<msgsource>\n\t<bizflag>0</bizflag>\n\t<pua>1</pua>\n\t<alnode>\n\t\t<cf>3</cf>\n\t\t<inlenlist>86</inlenlist>\n\t</alnode>\n\t<silence>1</silence>\n\t<membercount>4</membercount>\n\t<signature>V1_pVkC6xlw|v1_pVkC6xlw</signature>\n\t<tmp_node>\n\t\t<publisher-id></publisher-id>\n\t</tmp_node>\n</msgsource>\n","NewMsgId":6473116084228305363,"MsgSeq":776685968},"Wxid":"wxid_mr9pdsanc99422"}'}
+    a = PQ.download_video(url,'/Users/tzld/Desktop/video_rewriting/path','70100016',video,'单点视频')
     print(a)

+ 2 - 1
data_channel/shipinhaodandian.py

@@ -23,11 +23,12 @@ class SPHDD:
                     from_group_id = data[9]
                     from_group_name = data[10]
                     source = data[11]
+                    wx_msg = data[12]
                     log_data = f"user:{url},video_id:{video_id},video_url:{video_url},original_title:{old_title}"
                     AliyunLogger.logging(f"{channel_id}-{source}", name, url, video_id, "扫描到一条视频", "2001", log_data)
                     AliyunLogger.logging(f"{channel_id}-{source}", name, url, video_id, "符合规则等待改造", "2004", log_data)
                     all_data = {"video_id": video_id, "cover": cover_url, "video_url": video_url, "rule": author_name,
-                                "old_title": old_title, "from_user_name": from_user_name, "from_group_name": from_group_name, "source": source}
+                                "old_title": old_title, "from_user_name": from_user_name, "from_group_name": from_group_name, "source": source, "wx_msg": wx_msg}
                     list.append(all_data)
             return list
         return list

+ 3 - 3
video_rewriting/video_processor.py

@@ -140,7 +140,7 @@ class VideoProcessor:
                 time.sleep(1)
                 pw_random_id = cls.random_id()
                 new_video_path = cls.download_and_process_video(channel_id, video_url, video_path_url, v_id,
-                                                                crop_total, gg_duration_total, pw_random_id, new_title, mark)
+                                                                crop_total, gg_duration_total, pw_random_id, new_title, mark, video)
                 if not os.path.isfile(new_video_path):
                     AliyunLogger.logging(channel_id, name, url, v_id, "视频下载失败", "3002", f"video_url:{video_url}")
                     text = (
@@ -334,12 +334,12 @@ class VideoProcessor:
 
     @classmethod
     def download_and_process_video(cls, channel_id, video_url, video_path_url, v_id, crop_total, gg_duration_total,
-                                   pw_random_id, new_title, mark):
+                                   pw_random_id, new_title, mark, video):
         """
         下载并处理视频
         """
         if channel_id in ["票圈", "快手创作者版", "单点视频"]:
-            new_video_path = PQ.download_video(video_url, video_path_url, v_id)
+            new_video_path = PQ.download_video(video_url, video_path_url, v_id, video, channel_id)
             Common.logger(mark).info(f"{channel_id}视频下载成功: {new_video_path}")
         elif channel_id == "视频号历史":
             new_video_path = Oss.download_sph_ls(video_url, video_path_url, v_id)