Browse Source

兼容 单点视频号

zhangyong 7 months ago
parent
commit
dbb9da7388

+ 4 - 1
common/aliyun_log.py

@@ -46,7 +46,10 @@ class AliyunLogger:
         logstore = "rewriting-log"
         endpoint = "cn-hangzhou.log.aliyuncs.com"
         if data:
-            data = dict(item.split(":", 1) for item in data.split(","))
+            try:
+                data = dict(item.split(":", 1) for item in data.split(",,"))
+            except ValueError as e:
+                print(f"Error processing item: {e}")
         contents = [
             ("principal", principal),
             ("channel", channel),

+ 1 - 1
common/redis.py

@@ -50,7 +50,7 @@ def get_redis_video_data(video_id):
     lock = f"video_lock:{video_id}"
     helper = SyncRedisHelper()
     client = helper.get_client()
-    acquire_lock = client.set(lock, 1, ex=1200, nx=True)
+    acquire_lock = client.set(lock, 1, ex=600, nx=True)
     if not acquire_lock:
         return True
     return False

+ 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,wx_msg 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, is_encrypted, decode_key  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

@@ -83,7 +83,7 @@ class DY:
                     duration = dataHelp.video_duration(video_url)
                     Common.logger("dy").info(
                         f"扫描:{task_mark},用户主页id:{url_id},视频id{video_id} ,分享:{share_count},点赞{digg_count}")
-                    log_data = f"user:{url_id},video_id:{video_id},video_url:{video_url},original_title:{old_title},share_count:{share_count},digg_count:{digg_count},duration:{duration}"
+                    log_data = f"user:{url_id},,video_id:{video_id},,video_url:{video_url},,original_title:{old_title},,share_count:{share_count},,digg_count:{digg_count},,duration:{duration}"
                     AliyunLogger.logging(channel_id, name, url_id, video_id, "扫描到一条视频", "2001", log_data)
                     if status:
                         AliyunLogger.logging(channel_id, name, url_id, video_id, "该视频已改造过", "2001", log_data)

+ 1 - 1
data_channel/dy_ls.py

@@ -56,7 +56,7 @@ class DYLS:
                         .replace(">", "").replace("|", "").replace(" ", "") \
                         .replace("&NBSP", "").replace(".", "。").replace(" ", "") \
                         .replace("'", "").replace("#", "").replace("Merge", "")
-                    log_data = f"user:{url_id},video_id:{video_id},video_url:{video_url},original_title:{old_title},share_count:{share_count},digg_count:{digg_count},duration:{duration}"
+                    log_data = f"user:{url_id},,video_id:{video_id},,video_url:{video_url},,original_title:{old_title},,share_count:{share_count},,digg_count:{digg_count},,duration:{duration}"
                     AliyunLogger.logging(channel_id, name, url_id, video_id, "扫描到一条视频", "2001", log_data)
                     Common.logger("dy-ls").info(
                         f"扫描:{task_mark},用户主页id:{url_id},视频id{video_id} ,分享:{share_count},点赞{digg_count}")

+ 2 - 2
data_channel/ks_ls.py

@@ -50,7 +50,7 @@ class KSLS:
                     duration = data["duration"]
                     duration = int(duration)/1000
                     special = float(0.0005)
-                    log_data = f"user:{url_id},video_id:{photo_id},video_url:'',original_title:{old_title},share_count:{share_count},view_count:{view_count},duration:{duration}"
+                    log_data = f"user:{url_id},,video_id:{photo_id},,video_url:'',original_title:{old_title},,share_count:{share_count},,view_count:{view_count},,duration:{duration}"
 
                     AliyunLogger.logging(channel_id, name, url_id, photo_id, "扫描到一条视频", "2001", log_data)
                     if status:
@@ -76,7 +76,7 @@ class KSLS:
                         continue
                     video_url, image_url = cls.get_video(photo_id)
                     if video_url:
-                        log_data = f"user:{url_id},video_id:{photo_id},video_url:{video_url},original_title:{old_title},share_count:{share_count},view_count:{view_count},duration:{duration}"
+                        log_data = f"user:{url_id},,video_id:{photo_id},,video_url:{video_url},,original_title:{old_title},,share_count:{share_count},,view_count:{view_count},,duration:{duration}"
                         AliyunLogger.logging(channel_id, name, url_id, photo_id, "符合规则等待改造", "2004", log_data)
                         all_data = {"video_id": photo_id, "cover": image_url, "video_url": video_url,
                                     "rule": video_percent,

+ 1 - 1
data_channel/kuaishou.py

@@ -117,7 +117,7 @@ class KS:
                     realLikeCount = int(feeds[i].get('photo', {}).get('realLikeCount', 0))
                     video_percent = '%.4f' % (share_count / view_count)
                     duration = dataHelp.video_duration(video_url)
-                    log_data = f"user:{url_id},video_id:{video_id},video_url:{video_url},original_title:{old_title},share_count:{share_count},view_count:{view_count},duration:{duration}"
+                    log_data = f"user:{url_id},,video_id:{video_id},,video_url:{video_url},,original_title:{old_title},,share_count:{share_count},,view_count:{view_count},,duration:{duration}"
                     AliyunLogger.logging(channel_id, name, url_id, video_id, "扫描到一条视频", "2001", log_data)
                     Common.logger("ks").info(
                         f"扫描:{task_mark},用户主页id:{url_id},视频id{video_id} ,播放数:{view_count} ,分享数:{share_count},时长:{duration} ")

+ 1 - 1
data_channel/kuaishouchuangzuozhe.py

@@ -259,7 +259,7 @@ class KsFeedVideo:
                     main_mv_url = feed["main_mv_url"]  # 视频链接
                     thumbnail_url = feed["thumbnail_url"]  # 视频封面
                     user_id = feed["user_id"]  # 用户id非用户主页id
-                    log_data = f"user:{user_name},video_id:{photo_id},video_url:{main_mv_url},original_title:{caption},share_count:{share_count},view_count:{view_count},duration:{duration}"
+                    log_data = f"user:{user_name},,video_id:{photo_id},,video_url:{main_mv_url},,original_title:{caption},,share_count:{share_count},,view_count:{view_count},,duration:{duration}"
                     AliyunLogger.logging(channel_id, name, user_name, photo_id, "扫描到一条视频", "2001", log_data)
                     value, age = cls.analyze_photo(photo_id)
                     if status:

+ 43 - 17
data_channel/piaoquan.py

@@ -2,6 +2,8 @@ import random
 import re
 import time
 import json
+
+import cffi
 import requests
 from urllib.parse import urlencode
 
@@ -122,7 +124,7 @@ class PQ:
                 cover = url["coverImgPath"]
                 video_url = url["transedVideoPath"]
                 old_title = url["title"]
-                log_data = f"user:{user_id},video_id:{video_id},video_url:{video_url},original_title:{old_title}"
+                log_data = f"user:{user_id},,video_id:{video_id},,video_url:{video_url},,original_title:{old_title}"
                 AliyunLogger.logging(channel_id, name, user_id, video_id, "扫描到一条视频", "2001", log_data)
 
                 if status:
@@ -284,32 +286,56 @@ class PQ:
             print(e)
             return None
 
+    "视频号加密视频解密"
+    @classmethod
+    def decrypt_video(cls, data: bytes, decode_key: int, enc_length: int = 131072) -> bytes:
+        ffi = cffi.FFI()
+        # lib = ffi.dlopen(r'/Users/tzld/Desktop/video_rewriting/libsph_decrypt.dylib')
+        lib = ffi.dlopen(r'/root/video_rewriting/libsph_decrypt.so')
+        ffi.cdef('void decrypt(unsigned char *data, const size_t data_length, const uint32_t key);')
+
+        c_data = ffi.new('unsigned char[]', list(data))
+        lib.decrypt(c_data, enc_length, decode_key)
+        data = bytes(ffi.buffer(c_data, len(data))[:])
+        return data
 
     """
-    票圈站内视频下载
+    视频下载
     """
     @classmethod
     def download_video(cls, video_url, video_path_url, video_id, video, channel_id):
+        if channel_id == '单点视频':
+            if video['source'] == "视频号" and int(video['is_encrypted']) == 1:
+                decode_key = int(video['decode_key'])
+                response = requests.get(url=video_url)
+                data = response.content
+                enc_length = int(response.headers.get('X-enclen', 131072))
+                video_url = cls.decrypt_video(data=data, decode_key=decode_key, enc_length=enc_length)
         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", url_video, headers=headers, data=payload)
-                if response.status_code == 200:
-                    with open(f"{new_video}", "wb") as file:
-                        # 将响应内容写入文件
-                        file.write(response.content)
-                    time.sleep(5)
-                    return new_video
+                if video['source'] == "视频号" and int(video['is_encrypted']) == 1:
+                    with open(f"{new_video}", 'wb') as f:
+                        f.write(url_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
+                    payload = {}
+                    headers = {}
+                    response = requests.request("GET", url_video, headers=headers, data=payload)
+                    if response.status_code == 200:
+                        with open(f"{new_video}", "wb") as file:
+                            # 将响应内容写入文件
+                            file.write(response.content)
+                        time.sleep(5)
+                        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']

+ 1 - 1
data_channel/shipinhao.py

@@ -104,7 +104,7 @@ class SPH:
                         like_cnt = int(obj['like_count'])  # 点赞
                         old_title = video_obj.get('title').split("\n")[0].split("#")[0]
                         duration = dataHelp.video_duration(video_url)
-                        log_data = f"user:{url_id},video_id:{objectId},video_url:{video_url},original_title:{old_title},share_count:{share_cnt},like_count:{like_cnt},duration:{duration}"
+                        log_data = f"user:{url_id},,video_id:{objectId},,video_url:{video_url},,original_title:{old_title},,share_count:{share_cnt},,like_count:{like_cnt},,duration:{duration}"
                         AliyunLogger.logging(channel_id, name, url_id, objectId, "扫描到一条视频", "2001", log_data)
 
                         Common.logger("sph").info(

+ 8 - 6
data_channel/shipinhaodandian.py

@@ -26,18 +26,20 @@ class SPHDD:
                             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}"
+                            is_encrypted = data[13]
+                            decode_key = data[14]
+                            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, "wx_msg": wx_msg}
+                                        "old_title": old_title, "from_user_name": from_user_name, "from_group_name": from_group_name, "source": source, "wx_msg": wx_msg, "is_encrypted": is_encrypted, "decode_key": decode_key}
                             list.append(all_data)
-                    except:
+                    except Exception as e:
+                        print(e)
                         continue
-                    return list
+                return list
             except Exception:
                 return list
-            return list
         return list
 
 
@@ -45,4 +47,4 @@ class SPHDD:
 
 if __name__ == '__main__':
 
-    SPHDD.get_sphdd_data("杨昊")
+    SPHDD.get_sphdd_data("刘坤宇", '', '')

+ 1 - 1
data_channel/sph_ls.py

@@ -21,7 +21,7 @@ class SPHLS:
                 duration = int(float(data[6]))
                 Common.logger("sph-ls").info(
                     f"扫描:{task_mark},用户主页id:{url},视频id{video_id} ,分享:{share_cnt},点赞:{like_cnt},时长:{duration}")
-                log_data = f"user:{url},video_id:{video_id},video_url:{oss_url},original_title:{old_title},share_count:{share_cnt},like_count:{like_cnt},duration:{duration}"
+                log_data = f"user:{url},,video_id:{video_id},,video_url:{oss_url},,original_title:{old_title},,share_count:{share_cnt},,like_count:{like_cnt},,duration:{duration}"
                 AliyunLogger.logging(channel_id, name, url, video_id, "扫描到一条视频", "2001", log_data)
 
                 if status:

+ 1 - 1
job_dd_sph.py

@@ -11,7 +11,7 @@ def video_task_start():
             print("开始执行任务")
             mark = VideoProcessor.main(data)
             print(f"返回用户名: {mark}")
-            time.sleep(360 if mark else 600)  # 根据 mark 是否为空设置延迟
+            time.sleep(360 if mark else 360)  # 根据 mark 是否为空设置延迟
         except Exception as e:
             print("处理任务时出现异常:", e)
             time.sleep(10)

BIN
libsph_decrypt.so


+ 7 - 7
video_rewriting/video_processor.py

@@ -120,10 +120,10 @@ class VideoProcessor:
                 video_url = video["video_url"]
                 old_title = video['old_title']
                 rule = video['rule']
-                if channel_id == "单点视频":
-                    redis_video = get_redis_video_data(v_id)
-                    if redis_video:
-                        continue
+                # if channel_id == "单点视频":
+                #     redis_video = get_redis_video_data(v_id)
+                #     if redis_video:
+                #         continue
                 if not old_title:
                     old_title = '这个视频,分享给我的老友,祝愿您能幸福安康'
                     text = (
@@ -167,7 +167,7 @@ class VideoProcessor:
                             # new_video_path = FFmpeg.single_video(new_video_path, video_path_url, zm)
 
                     if not os.path.isfile(new_video_path):
-                        log_data = f"user:{url},video_id:{v_id},video_url:{video_url},ai_title:{new_title}"
+                        log_data = f"user:{url},,video_id:{v_id},,video_url:{video_url},,ai_title:{new_title}"
                         AliyunLogger.logging(channel_id, name, url, v_id, "视频改造失败", "3001", log_data)
                         text = (
                             f"**通知类型**: 视频改造失败\n"
@@ -218,7 +218,7 @@ class VideoProcessor:
                     Feishu.finish_bot(text,
                                       "https://open.feishu.cn/open-apis/bot/v2/hook/e7697dc6-5254-4411-8b59-3cd0742bf703",
                                       "【 机器改造通知 】")
-                    log_data = f"user:{url},video_id:{v_id},video_url:{video_url},ai_title:{new_title},voice:{voice}"
+                    log_data = f"user:{url},,video_id:{v_id},,video_url:{video_url},,ai_title:{new_title},,voice:{voice}"
                     AliyunLogger.logging(channel_id, name, url, v_id, "视频改造成功", "1000", log_data, str(code))
                     if channel_id == "快手历史" or channel_id == "抖音历史" or channel_id == "视频号历史":
                         explain = "历史爆款"
@@ -280,7 +280,7 @@ class VideoProcessor:
             except Exception as e:
                 Common.logger(mark).warning(f"{name}的{task_mark}任务处理失败:{e}")
                 cls.remove_files(video_path_url)
-                return
+                continue
 
     @classmethod
     def get_data_list(cls, channel_id, task_mark, url, number, mark, feishu_id, cookie_sheet, name):