video_processing.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import re
  2. import requests
  3. import json
  4. from common.aliyun_log import AliyunLogger
  5. from common.redis import get_video_data, install_video_data
  6. class VideoProcessing:
  7. def get_ai_data(self, video_path):
  8. url = "http://8.219.186.16:8080/process_video/"
  9. payload = json.dumps( {
  10. "video_path": video_path
  11. } )
  12. headers = {
  13. 'Content-Type': 'application/json'
  14. }
  15. response = requests.request( "POST", url, headers=headers, data=payload )
  16. try:
  17. response = response.json()
  18. print(response)
  19. result = response['result']
  20. print(result)
  21. cleaned_string = result.replace( "```json", "" ).replace( "```", "" ).strip()
  22. cleaned_string = re.sub( r'[\x00-\x1F]+', '', cleaned_string )
  23. json_data = json.loads( cleaned_string )
  24. print(json_data)
  25. return json_data
  26. except Exception as e:
  27. print(f"视频请求异常:{e}")
  28. return None
  29. def get_video(self):
  30. video_data = get_video_data()
  31. if not video_data:
  32. print("没有获取到视频内容")
  33. return
  34. # 解码为字符串
  35. data_str = video_data.decode( 'utf-8' )
  36. # 解析为 JSON 对象
  37. data_json = json.loads( data_str )
  38. video_id = data_json['video_id']
  39. title = data_json['title']
  40. video_path = data_json['video_path']
  41. data = self.get_ai_data(video_path)
  42. AliyunLogger.logging(str(video_id), title, video_path, data)
  43. print("写入日志成功")
  44. if __name__ == '__main__':
  45. video_processor = VideoProcessing()
  46. video_processor.get_video()