video_processing.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. sample_data = {
  12. "一、基础信息": {
  13. "视觉/音乐/文字": "",
  14. "内容选题": "",
  15. "视频主题": ""
  16. },
  17. "二、主体和场景": {
  18. "视频主体": "",
  19. "视频场景": []
  20. },
  21. "三、情感与风格": {},
  22. "四、视频传播性与观众": {
  23. "片尾引导": {},
  24. "传播性判断": "",
  25. "观众画像": {}
  26. },
  27. "五、音画细节": {
  28. "音频细节": {},
  29. "视频水印": {},
  30. "视频字幕": {},
  31. "视频口播": ""
  32. },
  33. "六、人物与场景": {
  34. "知名人物": {},
  35. "人物年龄段": "",
  36. "场景描述": []
  37. },
  38. "七、时效性与分类": {
  39. "时效性": {},
  40. "视频一级分类": "",
  41. "二级分类": ["品类- 、分数-", "品类- 、分数-", "品类- 、分数-"]
  42. }
  43. }
  44. url = "http://8.219.186.16:8080/process_video/"
  45. payload = json.dumps( {
  46. "video_path": video_path,
  47. "prompt": prompt,
  48. "mark": str(mark),
  49. "sample_data": str(sample_data)
  50. } )
  51. headers = {
  52. 'Content-Type': 'application/json'
  53. }
  54. try:
  55. response = requests.request( "POST", url, headers=headers, data=payload )
  56. response = response.json()
  57. result = response['result']
  58. mark = response['mark']
  59. cleaned_string = result.replace( "```json", '' ).replace( "```", '' ).strip()
  60. return cleaned_string, str(mark)
  61. except Exception as e:
  62. print(f"视频请求异常:{e}")
  63. return None
  64. def get_video(self, redis_task):
  65. video_data = get_video_data(redis_task)
  66. if not video_data:
  67. print("没有获取到视频内容")
  68. time.sleep(5)
  69. return
  70. # 解码为字符串
  71. data_str = video_data.decode( 'utf-8' )
  72. # 解析为 JSON 对象
  73. data_json = json.loads( data_str )
  74. video_id = data_json['video_id']
  75. title = data_json['title']
  76. video_path = data_json['video_path']
  77. type = data_json['type']
  78. partition = data_json['partition']
  79. print(video_path)
  80. data, mark = self.get_ai_data(video_path)
  81. AliyunLogger.logging(str(video_id), title, video_path, mark, type, partition, data)
  82. print("写入日志成功")
  83. if __name__ == '__main__':
  84. video_processor = VideoProcessing()
  85. video_processor.get_video()