vta_routes.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. """
  2. @author: luojunhui
  3. """
  4. from quart import Blueprint, jsonify, request
  5. from deal import RequestDeal
  6. from deal import ArticleMatchAccount
  7. from deal import ArticleGeneral
  8. from deal import PublishDeal
  9. from deal import insert_text_mysql, get_text_by_id
  10. from deal import ShareCard
  11. from deal import SingleVideo
  12. from deal import MatchArticles
  13. from applications.functions import whisper
  14. bp = Blueprint('VideosToArticle', __name__)
  15. def VTARoutes(mysql_client):
  16. """
  17. :param mysql_client:
  18. :return:
  19. """
  20. @bp.route("/healthcheck")
  21. def hello_world():
  22. """
  23. Health Check Port
  24. :return:
  25. """
  26. result = {
  27. "status": "success",
  28. "msg": "Hello Future"
  29. }
  30. return jsonify(result)
  31. @bp.route('/videos', methods=["POST"])
  32. async def find_videos():
  33. """
  34. 更具接口获取视频信息
  35. :return:
  36. """
  37. params = await request.get_json()
  38. RD = RequestDeal(params, mysql_client)
  39. result = await RD.deal()
  40. return jsonify(result)
  41. @bp.route('/whisper', methods=["POST"])
  42. async def video_extracting():
  43. """
  44. whisper 处理文本
  45. :return:
  46. """
  47. params = await request.get_json()
  48. video_id = params['vid']
  49. video_title = params['title']
  50. try:
  51. response = whisper(video_id)
  52. result = await insert_text_mysql(mysql_client, video_id, response['text'], video_title)
  53. except Exception as e:
  54. result = {"error": str(e), "vid": video_id}
  55. return jsonify(result)
  56. @bp.route('/get_text', methods=["POST"])
  57. async def get_video_text():
  58. """
  59. 获取视频文本
  60. :return:
  61. """
  62. params = await request.get_json()
  63. video_id = params['vid']
  64. text = await get_text_by_id(mysql_client, video_id)
  65. if text:
  66. result = {"text": text}
  67. else:
  68. result = {"text": None}
  69. return jsonify(result)
  70. @bp.route('/publish', methods=["POST"])
  71. async def auto_publish():
  72. """
  73. auto publish article info to aigc system
  74. :return:
  75. """
  76. params = await request.get_json()
  77. P = PublishDeal(params=params)
  78. res = P.deal()
  79. return jsonify(res)
  80. @bp.route('/article', methods=["POST"])
  81. async def generate_text():
  82. """
  83. 生成文本
  84. :return:
  85. """
  86. params = await request.get_json()
  87. A = ArticleGeneral(params=params)
  88. res = A.deal()
  89. return jsonify(res)
  90. @bp.route("/match", methods=["POST"])
  91. async def match_account():
  92. """
  93. 匹配小程序
  94. :return:
  95. """
  96. params = await request.get_json()
  97. MA = ArticleMatchAccount(params=params)
  98. res = MA.deal()
  99. return jsonify(res)
  100. @bp.route("/getShareCard", methods=["POST"])
  101. async def get_share_cards():
  102. """
  103. 获取分享卡片
  104. :return:
  105. """
  106. params = await request.get_json()
  107. SC = ShareCard(params=params)
  108. response = SC.deal()
  109. return jsonify(response)
  110. @bp.route("/singleVideo", methods=["POST"])
  111. async def find_video_info():
  112. """
  113. 获取单个视频的信息
  114. :return:
  115. """
  116. params = await request.get_json()
  117. SV = SingleVideo(params=params)
  118. response = SV.deal()
  119. return jsonify(response)
  120. @bp.route("/matchArticle", methods=["POST"])
  121. async def match_article():
  122. """
  123. 匹配视频
  124. :return:
  125. """
  126. params = await request.get_json()
  127. MA = MatchArticles(params=params)
  128. result = MA.deal()
  129. response = {
  130. "status": "success",
  131. "article": result
  132. }
  133. return jsonify(response)
  134. return bp