123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- """
- @author: luojunhui
- 调用接口在微信内搜索视频
- """
- import json
- from applications.search import *
- from applications.static.config import gh_id_dict
- from applications.functions.log import logging
- from applications.functions.video_item import video_mq_sender
- def recall_search_video(video_path, title, trace_id):
- """
- search and send msg to ETL
- :param trace_id:
- :param title: 视频标题
- :param video_path: 视频路径
- :return:
- """
- with open(video_path, encoding='utf-8') as f:
- my_obj = json.loads(f.read())
- if my_obj:
- wx_result = wx_search(keys=title)
- if wx_result:
- return {
- "platform": "wx_search",
- "result": wx_result[0]
- }
- else:
- logging(
- code="7001",
- info="通过微信搜索失败---{}".format(title),
- trace_id=trace_id
- )
- # 微信搜不到的话,采用好看视频搜索
- baidu_result = hksp_search(key=title)
- if baidu_result:
- return {
- "platform": "baidu_search",
- "result": baidu_result[0]
- }
- else:
- # 若好看视频未搜到,则采用西瓜搜索
- logging(
- code="7001",
- info="通过baidu搜索失败---{}".format(title),
- trace_id=trace_id
- )
- xigua_result = xigua_search(title)
- if xigua_result:
- return {
- "platform": "xg_search",
- "result": xigua_result[0]
- }
- else:
- logging(
- code="7001",
- info="通过西瓜搜索失败---{}".format(title),
- trace_id=trace_id
- )
- return None
- else:
- logging(
- code="7000",
- info="标题--{}--kimi 挖掘数据失败".format(title),
- trace_id=trace_id
- )
- return None
- def search_videos(video_path, title, trace_id, gh_id):
- """
- search and send msg to ETL
- :param gh_id:
- :param video_path:
- :param title:
- :param trace_id:
- :return:
- """
- recall_obj = recall_search_video(video_path, title, trace_id)
- platform = recall_obj["platform"]
- recall_video = recall_obj["result"]
- if recall_video:
- logging(
- code="7002",
- info="视频搜索成功, 搜索平台为--{}".format(platform),
- trace_id=trace_id,
- data=recall_video
- )
- video_mq_sender(
- video_obj=recall_video,
- user=gh_id_dict.get(gh_id),
- trace_id=trace_id,
- platform=platform
- )
- else:
- logging(
- code="7003",
- info="视频搜索失败",
- trace_id=trace_id
- )
|