zhangyong 3 ヶ月 前
コミット
4e42258c92

+ 0 - 0
application/common/ffmpeg/__init__.py


+ 76 - 0
application/common/ffmpeg/ffmpeg_utils.py

@@ -0,0 +1,76 @@
+import requests
+import json
+
+class Ffmpeg:
+
+    def get_oss_link(self, oss_key):
+        url = "http://61.48.133.26:5555/api/v1/oss/get_object_link"
+
+        payload = json.dumps({
+            "oss_object_key": oss_key
+        })
+        headers = {
+            'Authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNGNhMTI4ZGYtYWMzMy00NWQ2LTg3MmEtMDAzOTk4MGVhM2ViIiwibmFtZSI6Inp5IiwiZXhwIjoyMDUwOTI3MjExfQ.k_rvuESjA62RgPDiLniVgJyLJn3Q8C1Y_AGq3CPRuKI',
+            'Content-Type': 'application/json'
+        }
+
+        response = requests.request("POST", url, headers=headers, data=payload)
+        response = response.json()
+        data = response['data']
+        return data
+
+    def merge_m3u8(self,url_link):
+        url = "http://61.48.133.26:5555/api/v1/ffmpeg/merge_m3u8"
+
+        data = {
+            "url": url_link,
+            "referer": ""
+        }
+        headers = {
+            'Authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNGNhMTI4ZGYtYWMzMy00NWQ2LTg3MmEtMDAzOTk4MGVhM2ViIiwibmFtZSI6Inp5IiwiZXhwIjoyMDUwOTI3MjExfQ.k_rvuESjA62RgPDiLniVgJyLJn3Q8C1Y_AGq3CPRuKI',
+            'Content-Type': 'application/json'
+        }
+
+        response = requests.request("POST", url, headers=headers, json=data, stream=True)
+        for item in response.content.split(b'\r\n\r\n'):
+            try:
+                item = json.loads(item[6:].decode())
+                if item['event'] == 'message':
+                    continue
+                elif item['event'] == 'ffmpeg code':
+                    code = int(item['data'])
+                    if code != 0:  # ffmpeg处理异常
+                        return
+                elif item['event'] == 'result':
+                    oss_object_key = item['data']['oss_object_key']
+                    if oss_object_key:
+                        oss_url = self.get_oss_link(oss_object_key)
+                        return oss_url
+            except json.decoder.JSONDecodeError:
+                continue
+
+    def webp2_jpg(self,webp2_url):
+        url = "http://61.48.133.26:5555/api/v1/ffmpeg/webp2jpg"
+
+        payload = json.dumps({
+            "url": webp2_url,
+            "referer": ""
+        })
+        headers = {
+            'Authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNGNhMTI4ZGYtYWMzMy00NWQ2LTg3MmEtMDAzOTk4MGVhM2ViIiwibmFtZSI6Inp5IiwiZXhwIjoyMDUwOTI3MjExfQ.k_rvuESjA62RgPDiLniVgJyLJn3Q8C1Y_AGq3CPRuKI',
+            'Content-Type': 'application/json'
+        }
+
+        response = requests.request("POST", url, headers=headers, data=payload)
+        response = response.json()
+        oss_object_key = response['data']['oss_object_key']
+        if oss_object_key:
+            oss_url = self.get_oss_link(oss_object_key)
+            return oss_url
+        else:
+            return None
+
+
+if __name__ == '__main__':
+    ffmpeg = Ffmpeg()
+    print(ffmpeg.get_oss_link("jq_oss/video/20250103135417425230.mp4"))

+ 10 - 0
spider/crawler_online/haoyunzhufuduo.py

@@ -11,6 +11,7 @@ import requests
 
 from application.common.feishu import FsData
 from application.common.feishu.feishu_utils import FeishuUtils
+from application.common.ffmpeg.ffmpeg_utils import Ffmpeg
 from application.common.gpt import GPT4oMini
 from application.common.mysql.sql import Sql
 from application.common.redis.xng_redis import xng_in_video_data
@@ -124,6 +125,15 @@ class HYZFDfRecommend(object):
             trace_id=trace_id,
         )
         if pipeline.process_item():
+            video_url = video_obj["videoPath"]
+            cover_url = video_obj["coverImagePath"]
+            ffmpeg = Ffmpeg()
+            new_video_url = ffmpeg.merge_m3u8(video_url)
+            new_cover_url = ffmpeg.webp2_jpg(cover_url)
+            if not new_video_url or not  new_cover_url:
+                return
+            item.add_video_info("video_url", new_video_url)
+            item.add_video_info("cover_url", new_cover_url)
             title_list = title_rule.split(",")
             title = video_obj["title"]
             contains_keyword = any(keyword in title for keyword in title_list)