vta_routes.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 applications.functions import whisper
  11. bp = Blueprint('VideosToArticle', __name__)
  12. def VTARoutes(mysql_client):
  13. """
  14. :param mysql_client:
  15. :return:
  16. """
  17. @bp.route('/videos', methods=["POST"])
  18. async def find_videos():
  19. """
  20. 更具接口获取视频信息
  21. :return:
  22. """
  23. params = await request.get_json()
  24. RD = RequestDeal(params, mysql_client)
  25. result = await RD.deal()
  26. return jsonify(result)
  27. @bp.route('/whisper', methods=["POST"])
  28. async def video_extracting():
  29. """
  30. whisper 处理文本
  31. :return:
  32. """
  33. params = await request.get_json()
  34. video_id = params['vid']
  35. video_title = params['title']
  36. try:
  37. response = whisper(video_id)
  38. await insert_text_mysql(mysql_client, video_id, response['text'], video_title)
  39. result = {"info": "success insert text into mysql", "vid": video_id}
  40. except Exception as e:
  41. result = {"error": str(e), "vid": video_id}
  42. return jsonify(result)
  43. @bp.route('/get_text', methods=["POST"])
  44. async def get_video_text():
  45. """
  46. 获取视频文本
  47. :return:
  48. """
  49. params = await request.get_json()
  50. video_id = params['vid']
  51. text = await get_text_by_id(mysql_client, video_id)
  52. if text:
  53. result = {"text": text}
  54. else:
  55. result = {"text": None}
  56. return jsonify(result)
  57. @bp.route('/publish', methods=["POST"])
  58. async def auto_publish():
  59. """
  60. auto publish article info to aigc system
  61. :return:
  62. """
  63. params = await request.get_json()
  64. P = PublishDeal(params=params)
  65. res = P.deal()
  66. return jsonify(res)
  67. @bp.route('/article', methods=["POST"])
  68. async def generate_text():
  69. """
  70. 生成文本
  71. :return:
  72. """
  73. params = await request.get_json()
  74. A = ArticleGeneral(params=params)
  75. res = A.deal()
  76. return jsonify(res)
  77. @bp.route("/match", methods=["POST"])
  78. async def match_account():
  79. """
  80. 匹配小程序
  81. :return:
  82. """
  83. params = await request.get_json()
  84. MA = ArticleMatchAccount(params=params)
  85. res = MA.deal()
  86. return jsonify(res)
  87. return bp