search.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. """
  2. 搜索API
  3. """
  4. from flask import Blueprint
  5. from flask import request
  6. import api
  7. from tiktok import TikTokBrowser
  8. search_opt = Blueprint('search', __name__)
  9. @search_opt.route('/image-text-by-keyword', methods=["POST"])
  10. def search_keyword():
  11. """
  12. 根据关键字搜索抖音图文
  13. :return:
  14. """
  15. request_body = request.json
  16. keyword = request_body.get('keyword')
  17. api.assert_not_none(keyword, '关键字不能为空')
  18. phone = api.get_idle_account()
  19. browser = TikTokBrowser(phone)
  20. result = browser.search_image_text(keyword)
  21. return api.success(result)
  22. @search_opt.route('/image-text-by-author', methods=["POST"])
  23. def image_text_by_author():
  24. """
  25. 根据作者链接搜索抖音图文
  26. :return:
  27. """
  28. request_body = request.json
  29. author_url = request_body.get('authorUrl')
  30. size = request_body.get('size')
  31. api.assert_not_none(author_url, '作者链接不能为空')
  32. phone = api.get_idle_account()
  33. browser = TikTokBrowser(phone)
  34. result = browser.search_image_text_by_author(author_url, size)
  35. return api.success(result)
  36. @search_opt.route('/user', methods=["POST"])
  37. def search_user():
  38. """
  39. 搜索抖音用户信息
  40. :return:
  41. """
  42. request_body = request.json
  43. user_url = request_body.get('url')
  44. api.assert_not_none(user_url, '用户链接不能为空')
  45. browser = TikTokBrowser(api.get_idle_account())
  46. result = browser.search_user(user_url)
  47. return api.success(result)
  48. @search_opt.route('/batch-users', methods=["POST"])
  49. def batch_users():
  50. """
  51. 批量搜索抖音用户信息
  52. :return:
  53. """
  54. request_body = request.json
  55. user_urls = request_body.get('urls')
  56. api.assert_not_none(user_urls, '用户链接不能为空')
  57. browser = TikTokBrowser(api.get_idle_phone())
  58. result = browser.batch_users(user_urls)
  59. return api.success(result)
  60. @search_opt.route('/batch-user-polish', methods=["POST"])
  61. def batch_user_unique_id():
  62. """
  63. 批量搜索抖音用户抖音号
  64. :return:
  65. """
  66. request_body = request.json
  67. sec_uids = request_body.get('secUids')
  68. api.assert_not_none(sec_uids, '用户id不能为空')
  69. browser = TikTokBrowser(api.get_idle_account())
  70. result = browser.batch_user_polish(sec_uids)
  71. return api.success(result)
  72. @search_opt.route('/item', methods=["POST"])
  73. def search_item():
  74. """
  75. 根据关键字搜索抖音笔记、视频
  76. :return:
  77. """
  78. request_body = request.json
  79. note_url = request_body.get('url')
  80. api.assert_not_none(note_url, '作品链接不能为空')
  81. browser = TikTokBrowser(api.get_idle_account())
  82. result = browser.invoke(func=browser.search_item, url=note_url)
  83. return api.success(result)
  84. @search_opt.route('/batch-notes', methods=["POST"])
  85. def batch_notes():
  86. """
  87. 根据关键字搜索抖音笔记、视频
  88. :return:
  89. """
  90. request_body = request.json
  91. note_urls = request_body.get('urls')
  92. api.assert_not_none(note_urls, '作品链接不能为空')
  93. browser = TikTokBrowser(api.get_idle_account())
  94. result = browser.batch_notes(note_urls)
  95. return api.success(result)