_mapper.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from app.core.database import DatabaseManager
  2. class VideoDecodeMapper:
  3. def __init__(self, pool: DatabaseManager):
  4. self.pool = pool
  5. async def fetch_video_source_content(self, root_source_id: str):
  6. query = """
  7. SELECT content_id, gh_id, video_id, trace_id
  8. FROM long_articles_root_source_id
  9. WHERE root_source_id = %s;
  10. """
  11. return await self.pool.async_fetch(query=query, params=(root_source_id,))
  12. async def fetch_video_match_result_v1(self, gh_id: str, content_id: str):
  13. query = """
  14. SELECT response FROM long_articles_match_videos WHERE gh_id = %s AND content_id = %s;
  15. """
  16. return await self.pool.async_fetch(
  17. query=query,
  18. params=(
  19. gh_id,
  20. content_id,
  21. ),
  22. )
  23. async def fetch_video_match_result_v2(self, trace_id: str):
  24. query = """
  25. SELECT response FROM long_articles_match_videos WHERE trace_id = %s
  26. """
  27. return await self.pool.async_fetch(query=query, params=(trace_id,))
  28. async def save_video_to_decode_data(self, data: tuple):
  29. """
  30. 存储数据到 video_decode_data
  31. """
  32. query = """
  33. INSERT IGNORE INTO video_decode_data
  34. (video_id, channel, hot_scene_type, video_path, title, root_source_id, dt)
  35. VALUES
  36. (%s, %s, %s, %s, %s, %s, %s);
  37. """
  38. return await self.pool.async_save(
  39. query=query,
  40. params=data,
  41. )
  42. async def update_video_decode_data_status(self, video_id, ori_status, new_status):
  43. query = """
  44. UPDATE video_decode_data
  45. SET status = %s
  46. WHERE video_id = %s AND status = %s;
  47. """
  48. affected_rows = await self.pool.async_save(
  49. query=query,
  50. params=(new_status, video_id, ori_status),
  51. )
  52. return bool(affected_rows)
  53. async def insert_into_decode_task_queue(self, data: tuple):
  54. query = """
  55. INSERT IGNORE INTO video_decode_queue
  56. (video_path, sample_video_id, dt)
  57. VALUES
  58. (%s, %s, %s);
  59. """
  60. return await self.pool.async_save(
  61. query=query,
  62. params=data,
  63. )