|
@@ -1,6 +1,5 @@
|
|
|
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;
|
|
@@ -27,7 +26,6 @@ import java.util.concurrent.Executors;
|
|
|
/**
|
|
|
* @Description: 快手-获取视频接口
|
|
|
* @Author: jeecg-boot
|
|
|
- *
|
|
|
* @Date: 2019-07-25
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
@@ -51,82 +49,77 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
|
|
|
/**
|
|
|
* 获取关键帧
|
|
|
*
|
|
|
- *
|
|
|
* @param
|
|
|
*/
|
|
|
@Override
|
|
|
- public void getKeyFrame(CtopOauthToken token) {
|
|
|
+ public void getKeyFrame(String token, Long accountId, String md5, String photoId) {
|
|
|
try {
|
|
|
- QueryWrapper<KuaiShouVideoGet> videoGetQueryWrapper = new QueryWrapper<>();
|
|
|
+ /* 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) {
|
|
|
- synchronized (this) {
|
|
|
- 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;
|
|
|
- }
|
|
|
- Map<String, Object> deleteMap = new HashMap<>();
|
|
|
- deleteMap.put("video_signature", videoGet.getSignature());
|
|
|
- deleteMap.put("signature", md5);
|
|
|
- materialCutFrameService.removeByMap(deleteMap);
|
|
|
-
|
|
|
- MaterialCutFrame materialCutFrame = new MaterialCutFrame();
|
|
|
- materialCutFrame.setImageIndex(i);
|
|
|
- materialCutFrame.setVideoSignature(videoGet.getSignature());
|
|
|
- materialCutFrame.setUrl(imageUrl);
|
|
|
- materialCutFrame.setSignature(md5);
|
|
|
- materialCutFrameService.save(materialCutFrame);
|
|
|
- LoadFileUtil.delFile(localPath);
|
|
|
+ }*/
|
|
|
+ // for (KuaiShouVideoGet videoGet : kuaiShouVideoGets) {
|
|
|
+ synchronized (this) {
|
|
|
+ QueryWrapper<MaterialCutFrame> cutFrameQueryWrapper = new QueryWrapper<>();
|
|
|
+ cutFrameQueryWrapper.eq("video_signature", md5);
|
|
|
+ cutFrameQueryWrapper.last("limit 1");
|
|
|
+ MaterialCutFrame one = materialCutFrameService.getOne(cutFrameQueryWrapper);
|
|
|
+ if (!Check.isNull(one)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ 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(photoId);
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", token);
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ JSONObject requestJson = new JSONObject();
|
|
|
+ requestJson.put("advertiser_id", accountId);
|
|
|
+ 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;
|
|
|
}
|
|
|
+ Map<String, Object> deleteMap = new HashMap<>();
|
|
|
+ deleteMap.put("video_signature", md5);
|
|
|
+ deleteMap.put("signature", md5);
|
|
|
+ materialCutFrameService.removeByMap(deleteMap);
|
|
|
+ MaterialCutFrame materialCutFrame = new MaterialCutFrame();
|
|
|
+ materialCutFrame.setImageIndex(i);
|
|
|
+ materialCutFrame.setVideoSignature(md5);
|
|
|
+ materialCutFrame.setUrl(imageUrl);
|
|
|
+ materialCutFrame.setSignature(md5);
|
|
|
+ materialCutFrameService.save(materialCutFrame);
|
|
|
+ LoadFileUtil.delFile(localPath);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
+ // }
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|