|
@@ -1,13 +1,28 @@
|
|
|
package cn.com.ctop.kuaishou.modules.batch.service.impl;
|
|
|
|
|
|
+import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
+import cn.com.ctop.common.module.entity.MaterialCutFrame;
|
|
|
+import cn.com.ctop.common.module.service.IMaterialCutFrameService;
|
|
|
+import cn.com.ctop.common.module.utils.Check;
|
|
|
+import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
+import cn.com.ctop.common.module.utils.LoadFileUtil;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouVideoGetMapper;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
/**
|
|
|
* @Description: 快手-获取视频接口
|
|
@@ -19,9 +34,92 @@ import java.util.List;
|
|
|
public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMapper, KuaiShouVideoGet> implements IKuaiShouVideoGetService {
|
|
|
@Autowired
|
|
|
private KuaiShouVideoGetMapper videoGetMapper;
|
|
|
+ @Autowired
|
|
|
+ private IMaterialCutFrameService materialCutFrameService;
|
|
|
+ static ExecutorService executorService = Executors.newFixedThreadPool(15);
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${oss.replace.download}")
|
|
|
+ private String downloadUrl;
|
|
|
|
|
|
@Override
|
|
|
public void replaceBatch(List<KuaiShouVideoGet> videoGets) {
|
|
|
videoGetMapper.replaceBatch(videoGets);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取关键帧
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getKeyFrame(CtopOauthToken token) {
|
|
|
+ try {
|
|
|
+ QueryWrapper<KuaiShouVideoGet> videoGetQueryWrapper = new QueryWrapper<>();
|
|
|
+ videoGetQueryWrapper.eq("account_id", token.getAccountId());
|
|
|
+ videoGetQueryWrapper.eq("channel_type", 1);
|
|
|
+ List<KuaiShouVideoGet> kuaiShouVideoGets = videoGetMapper.selectList(videoGetQueryWrapper);
|
|
|
+ if (Check.isNull(kuaiShouVideoGets)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (KuaiShouVideoGet videoGet : kuaiShouVideoGets) {
|
|
|
+ if (!Check.isNull(videoGet.getSignature())) {
|
|
|
+ QueryWrapper<MaterialCutFrame> cutFrameQueryWrapper = new QueryWrapper<>();
|
|
|
+ cutFrameQueryWrapper.eq("video_signature", videoGet.getSignature());
|
|
|
+ cutFrameQueryWrapper.last("limit 1");
|
|
|
+ MaterialCutFrame one = materialCutFrameService.getOne(cutFrameQueryWrapper);
|
|
|
+ if (!Check.isNull(one)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ String url = "https://ad.e.kuaishou.com/rest/openapi/v1/tool/key_frame";
|
|
|
+ JSONArray photoArr = new JSONArray();
|
|
|
+ photoArr.add(videoGet.getPhotoId());
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ JSONObject requestJson = new JSONObject();
|
|
|
+ requestJson.put("advertiser_id", token.getAccountId());
|
|
|
+ requestJson.put("photo_ids", photoArr);
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONArray dataArr = resultJson.getJSONArray("data");
|
|
|
+ if (!Check.isNull(dataArr)) {
|
|
|
+ for (int i = 0; i < dataArr.size(); i++) {
|
|
|
+ String imageUrl = dataArr.getString(i);
|
|
|
+ String localPath = LoadFileUtil.downLoadFromUrl(imageUrl, downloadUrl);
|
|
|
+ String md5 = null;
|
|
|
+ try {
|
|
|
+ md5 = LoadFileUtil.getMD5(localPath);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ MaterialCutFrame materialCutFrame = new MaterialCutFrame();
|
|
|
+ materialCutFrame.setImageIndex(i);
|
|
|
+ materialCutFrame.setVideoSignature(videoGet.getSignature());
|
|
|
+ materialCutFrame.setUrl(imageUrl);
|
|
|
+ materialCutFrame.setSignature(md5);
|
|
|
+ materialCutFrameService.save(materialCutFrame);
|
|
|
+ LoadFileUtil.delFile(localPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|