routes.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import time
  6. import uuid
  7. from quart import Blueprint, jsonify, request
  8. from applications.functions.log import logging
  9. from applications.schedule import ProcessParams, search_videos
  10. from applications.functions.common import MySQLServer
  11. from applications.functions.kimi import KimiServer
  12. from applications.schedule.main_schedule import AskForInfo
  13. my_blueprint = Blueprint('kimi', __name__)
  14. @my_blueprint.route('/healthcheck')
  15. def hello():
  16. """
  17. Hello World Test
  18. :return:
  19. """
  20. logging(
  21. code="1001",
  22. info="请求接口成功",
  23. port="healthcheck"
  24. )
  25. return jsonify({'message': 'Hello, World!'})
  26. @my_blueprint.route('/title_to_search', methods=['POST'])
  27. async def search_videos_from_the_web():
  28. """
  29. 从web 搜索视频并且存储到票圈的视频库中
  30. :return:
  31. """
  32. params = await request.get_json()
  33. K = KimiServer()
  34. gh_id = params['ghId']
  35. trace_id = "search-{}-{}".format(str(uuid.uuid4()), str(int(time.time())))
  36. params['trace_id'] = trace_id
  37. logging(
  38. code="2000",
  39. info="搜索视频内容接口请求成功",
  40. port="title_to_search",
  41. function="search_videos_from_the_web",
  42. trace_id=trace_id
  43. )
  44. try:
  45. kimi_info = await K.search_kimi_schedule(params=params)
  46. video_id, video_url = await search_videos(
  47. kimi_info=kimi_info,
  48. trace_id=trace_id,
  49. gh_id=gh_id
  50. )
  51. print(json.dumps(kimi_info, ensure_ascii=False, indent=4))
  52. res = {
  53. "trace_id": trace_id,
  54. "code": 0,
  55. "kimi_title": kimi_info['k_title'],
  56. "search_video_id": video_id,
  57. "video_url": video_url
  58. }
  59. except Exception as e:
  60. res = {
  61. "trace_id": trace_id,
  62. "code": 1,
  63. "message": str(e)
  64. }
  65. return jsonify(res)
  66. @my_blueprint.route('/out_videos', methods=['POST'])
  67. async def find_in_mysql():
  68. """
  69. 搜索是否存在外站视频 video_list, 如果存在,则返回成功
  70. :return:
  71. """
  72. data = await request.get_json()
  73. trace_id = data['traceId']
  74. logging(
  75. code="2000",
  76. info="请求接口成功",
  77. port="title_to_video",
  78. trace_id=trace_id,
  79. function="find_in_mysql"
  80. )
  81. res = MySQLServer().select_download_videos(trace_id=trace_id)
  82. return jsonify(res)
  83. @my_blueprint.route('/find_video', methods=['POST'])
  84. async def post_data():
  85. """
  86. 请求接口代码
  87. :return:
  88. """
  89. data = await request.get_json()
  90. trace_id = data['traceId']
  91. logging(
  92. code="1001",
  93. info="请求接口成功",
  94. port="title_to_video",
  95. trace_id=trace_id
  96. )
  97. p = ProcessParams(t_id=trace_id)
  98. processed_data = await p.deal(data)
  99. return jsonify(processed_data)
  100. @my_blueprint.route('/title_to_video', methods=['POST'])
  101. async def delay_response():
  102. """
  103. main
  104. :return:
  105. """
  106. # 从请求体中解析 JSON 数据
  107. data = await request.get_json()
  108. A = AskForInfo(data)
  109. res = await A.schedule()
  110. return jsonify(res)