video_processing.py 1.6 KB

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