routes.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. """
  2. @author: luojunhui
  3. """
  4. import os
  5. import time
  6. import uuid
  7. import asyncio
  8. from quart import Blueprint, jsonify, request
  9. from applications.functions.log import logging
  10. from applications.schedule import ProcessParams, search_videos
  11. from applications.functions.common import KimiServer, MySQLServer
  12. my_blueprint = Blueprint('kimi', __name__)
  13. @my_blueprint.route('/healthcheck')
  14. def hello():
  15. """
  16. Hello World Test
  17. :return:
  18. """
  19. logging(
  20. code="1001",
  21. info="请求接口成功",
  22. port="healthcheck"
  23. )
  24. return jsonify({'message': 'Hello, World!'})
  25. @my_blueprint.route('/title_to_search', methods=['POST'])
  26. async def search_videos_from_the_web():
  27. """
  28. 从web 搜索视频并且存储到票圈的视频库中
  29. :return:
  30. """
  31. params = await request.get_json()
  32. title = params['title'].replace("【非头次】", "")
  33. gh_id = params['ghId']
  34. trace_id = "search-{}-{}".format(str(uuid.uuid4()), str(int(time.time())))
  35. params['trace_id'] = trace_id
  36. logging(
  37. code="2000",
  38. info="搜索视频内容接口请求成功",
  39. port="title_to_search",
  40. function="search_videos_from_the_web",
  41. trace_id=trace_id
  42. )
  43. # try:
  44. title_p = os.path.join(os.getcwd(), 'applications', 'static', "titles", "{}.json".format(title))
  45. if os.path.exists(title_p):
  46. logging(
  47. code="2001",
  48. info="该标题已经被 kimi 处理过,跳过请求 kimi 操作--- {}".format(title),
  49. function="search_videos_from_the_web",
  50. trace_id=trace_id
  51. )
  52. else:
  53. KimiServer().ask_kimi_and_save_to_local((title, trace_id, title_p))
  54. await asyncio.sleep(1)
  55. kimi_title = KimiServer().kimi_title(title)
  56. search_videos(
  57. title=title,
  58. video_path=title_p,
  59. trace_id=trace_id,
  60. gh_id=gh_id,
  61. )
  62. res = {
  63. "trace_id": trace_id,
  64. "code": 0,
  65. "kimi_title": kimi_title
  66. }
  67. # except Exception as e:
  68. # res = {
  69. # "trace_id": trace_id,
  70. # "code": 1,
  71. # "message": str(e)
  72. # }
  73. return jsonify(res)
  74. @my_blueprint.route('/out_videos', methods=['POST'])
  75. async def find_in_mysql():
  76. """
  77. 搜索是否存在外站视频 video_list, 如果存在,则返回成功
  78. :return:
  79. """
  80. data = await request.get_json()
  81. trace_id = data['traceId']
  82. logging(
  83. code="2000",
  84. info="请求接口成功",
  85. port="title_to_video",
  86. trace_id=trace_id,
  87. function="find_in_mysql"
  88. )
  89. res = MySQLServer().select_download_videos(trace_id=trace_id)
  90. return jsonify(res)
  91. @my_blueprint.route('/title_to_video', methods=['POST'])
  92. async def post_data():
  93. """
  94. 请求接口代码
  95. :return:
  96. """
  97. data = await request.get_json()
  98. trace_id = data['traceId']
  99. logging(
  100. code="1001",
  101. info="请求接口成功",
  102. port="title_to_video",
  103. trace_id=trace_id
  104. )
  105. p = ProcessParams(t_id=trace_id)
  106. processed_data = await p.deal(data)
  107. return jsonify(processed_data)