Quellcode durchsuchen

视频号修复

zhangyong vor 9 Monaten
Ursprung
Commit
82bca25472

+ 6 - 6
common/redis.py

@@ -50,22 +50,22 @@ def get_data(name, data):
     return ret
 
 """抖音搜索计数插入"""
-def increment_key():
+def increment_key(mark_count):
     helper = SyncRedisHelper()
     client = helper.get_client()
-    client.incrby('dyss-count', 1)
+    client.incrby(mark_count, 1)
 
 """抖音搜索计数获取"""
-def get_first_value_with_prefix():
+def get_first_value_with_prefix(mark_count):
     helper = SyncRedisHelper()
     client = helper.get_client()
-    value = client.get("dyss-count")
+    value = client.get(mark_count)
     return int(value) if value is not None else 1
 
-def del_dyss_redis_key():
+def del_dyss_redis_key(mark_count):
     helper = SyncRedisHelper()
     client = helper.get_client()
-    client.delete("dyss-count")
+    client.delete(mark_count)
 
 
 def get_redis_video_data(video_id):

+ 0 - 0
data_channel/ks_keyword.py


+ 34 - 2
data_channel/piaoquan.py

@@ -304,10 +304,10 @@ class PQ:
             return data
 
     """
-    视频号视频下载
+    单点视频号视频下载
     """
     @classmethod
-    def sph_download_video(cls, video_url, video_path_url, video_id, video, channel_id):
+    def dd_sph_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'])
@@ -378,6 +378,38 @@ class PQ:
                     return None
         return None
 
+    """
+    视频号视频下载
+    """
+    @classmethod
+    def sph_download_video(cls, video_url, video_path_url, video_id, video):
+        decode_key = int(video['decode_key'])
+        data, enc_length = None, 0
+        for i in range(3):
+            try:
+                response = requests.get(url=video_url, timeout=10)
+                data = response.content
+                data_length = int(response.headers.get("Content-Range", '0').split('/')[-1])
+                enc_length = int(response.headers.get('X-enclen', 131072))
+                if len(data) == data_length:
+                    break
+            except TimeoutError:
+                continue
+        if not data:
+            return None
+        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:
+                if video['source'] == "视频号" and int(video['is_encrypted']) == 1:
+                    with open(f"{new_video}", 'wb') as f:
+                        f.write(url_video)
+                        return new_video
+            except Exception:
+                if i == 2:
+                    return None
+
     """票圈/快手创作者"""
     @classmethod
     def download_video(cls, video_url, video_path_url, video_id):

+ 14 - 15
data_channel/shipinhao.py

@@ -64,20 +64,20 @@ class SPH:
             url = "http://8.217.190.241:8888/crawler/wei_xin/shi_pin_hao/blogger"
             next_cursor = ""
             list = []
-            for i in range(10):
-                headers = {
-                    'Content-Type': 'application/json'
-                }
-                payload = json.dumps({
-                    "account_id": account_id,
-                    "cursor": next_cursor
-                })
-
+            # for i in range(10):
+            headers = {
+                'Content-Type': 'application/json'
+            }
+            payload = json.dumps({
+                "account_id": account_id,
+                "cursor": next_cursor
+            })
+            try:
                 response = requests.request("POST", url, headers=headers, data=payload)
                 time.sleep(random.randint(1, 5))
                 res_json = response.json()
                 if res_json['code'] == 0:
-                    next_cursor = res_json['data']['next_cursor']
+                    # next_cursor = res_json['data']['next_cursor']
                     data_lsit = res_json['data']['data']
                     for obj in data_lsit:
                         objectId = obj['id']
@@ -113,7 +113,7 @@ class SPH:
 
                                 continue
                             AliyunLogger.logging(channel_id, name, url_id, objectId, "符合规则等待改造", "2004", log_data)
-                            all_data = {"video_id": objectId, "cover": cover, "video_url": video_url, "rule": video_percent, "old_title": old_title, "decode_key":decode_key}
+                            all_data = {"video_id": objectId, "cover": cover, "video_url": video_url, "rule": video_percent, "old_title": old_title, "decode_key": decode_key}
                             list.append(all_data)
                             if len(list) == int(number):
                                 Common.logger(mark).info(f"获取视频号视频总数:{len(list)}\n")
@@ -124,10 +124,9 @@ class SPH:
                             Common.logger("sph").info(
                                      f"不符合规则:{task_mark},用户主页id:{url_id},视频id{objectId} ,分享:{share_cnt},点赞:{like_cnt}")
                             continue
-                                
-
-            return list
-        return []
+                return list
+            except Exception:
+                return list
 
 
 if __name__ == '__main__':

+ 4 - 3
redis_clear_mark.py

@@ -4,11 +4,12 @@ from common.redis import del_dyss_redis_key
 
 
 def redis_bot():
+    lists = ['dyss-count', 'sph-count']
     print("开始执行")
-    del_dyss_redis_key()
+    for mark_count in lists:
+        print(mark_count)
+        del_dyss_redis_key(mark_count)
     print("执行结束")
-
-
 # 每天零点10分
 schedule.every().day.at("00:10").do(redis_bot)
 while True:

+ 17 - 4
video_rewriting/video_processor.py

@@ -380,11 +380,16 @@ class VideoProcessor:
         下载并处理视频
         """
         if channel_id == "单点视频":
-            new_video_path = PQ.sph_download_video(video_url, video_path_url, v_id, video, channel_id)
+            new_video_path = PQ.dd_sph_download_video(video_url, video_path_url, v_id, video, channel_id)
             if new_video_path == None:
                 return None
             Common.logger(mark).info(f"{channel_id}视频下载成功: {new_video_path}")
-        elif channel_id == "票圈" or  channel_id == "快手创作者版":
+        elif channel_id == "视频号":
+            new_video_path = PQ.sph_download_video(video_url, video_path_url, v_id, video)
+            if new_video_path == None:
+                return None
+            Common.logger(mark).info(f"{channel_id}视频下载成功: {new_video_path}")
+        elif channel_id == "票圈" or channel_id == "快手创作者版":
             new_video_path = PQ.download_video(video_url, video_path_url, v_id)
             if new_video_path == None:
                 return None
@@ -550,11 +555,19 @@ class VideoProcessor:
                 return
             task = json.loads(data)
             if mark == 'pl-gjc' and task['channel_id'] == '抖音搜索':
-                count = get_first_value_with_prefix()
-                increment_key()
+                mark_count = 'dyss-count'
+                count = get_first_value_with_prefix(mark_count)
+                increment_key(mark_count)
                 if int(count) == 300:
                     Common.logger(mark).log(f"抖音搜索接口今日已经上限")
                     return "抖音搜索上限"
+            if mark == 'sph-plzh'and task['channel_id'] == '视频号':
+                mark_count = 'sph-count'
+                count = get_first_value_with_prefix(mark_count)
+                increment_key(mark_count)
+                if int(count) == 400:
+                    Common.logger(mark).log(f"视频号获取用户主页今日已经上限")
+                    return "视频号获取用户主页视频上限"
             VideoProcessor.process_task(task, mark, name, feishu_id, cookie_sheet)
             return mark
         except Exception as e: