video_processing.py 1.8 KB

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