video_item.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from common.public import clean_title
  2. from .aliyun_log import AliyunLogger
  3. class VideoItem:
  4. """
  5. function: 当扫描进一条视频的时候,对该视频的基本信息进行处理,保证发送给 pipeline和 etl 的 video_dict 是正确的
  6. __init__: 初始化空json 对象,用来存储视频信息
  7. add_video_info: 把视频信息存储到 item 对象中
  8. check_item: 检查 item 对象中的各个元素以及处理
  9. """
  10. def __init__(self):
  11. self.item = {}
  12. def add_video_info(self, key, value):
  13. self.item[key] = value
  14. # 判断视频格式, 做兼容
  15. def check_item(self):
  16. # video_title
  17. if self.item.get("video_title"):
  18. self.item['video_title'] = clean_title(self.item['video_title'])
  19. else:
  20. self.item['video_title'] = "No title"
  21. # video_id
  22. # video_time, publish_time_str, publish_time_stamp, update_time_stamp
  23. # play_cnt, like_cnt, comment_cnt, share_cnt
  24. # width, height, video_width, video_height
  25. # user_name, user_id, out_user_name, out_user_id
  26. # profile_id, profile_mid
  27. # session
  28. # video_url
  29. # cover_url
  30. def return_item(self):
  31. self.check_item()
  32. return self.item