|
@@ -12,6 +12,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -29,6 +30,7 @@ import java.util.concurrent.Executors;
|
|
* @Date: 2019-07-25
|
|
* @Date: 2019-07-25
|
|
* @Version: V1.0
|
|
* @Version: V1.0
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMapper, KuaiShouVideoGet> implements IKuaiShouVideoGetService {
|
|
public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMapper, KuaiShouVideoGet> implements IKuaiShouVideoGetService {
|
|
@Autowired
|
|
@Autowired
|
|
@@ -54,62 +56,55 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
|
|
@Override
|
|
@Override
|
|
public void getKeyFrame(String token, Long accountId, String videoMd5, String photoId) {
|
|
public void getKeyFrame(String token, Long accountId, String videoMd5, String photoId) {
|
|
try {
|
|
try {
|
|
-
|
|
|
|
-
|
|
|
|
- executorService.submit(new Runnable() {
|
|
|
|
- @Override
|
|
|
|
- public void run() {
|
|
|
|
- QueryWrapper<MaterialCutFrame> cutFrameQueryWrapper = new QueryWrapper<>();
|
|
|
|
- cutFrameQueryWrapper.eq("video_signature", videoMd5);
|
|
|
|
- cutFrameQueryWrapper.last("limit 1");
|
|
|
|
- MaterialCutFrame one = materialCutFrameService.getOne(cutFrameQueryWrapper);
|
|
|
|
- if (!Check.isNull(one)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- 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", videoMd5);
|
|
|
|
- deleteMap.put("signature", md5);
|
|
|
|
- materialCutFrameService.removeByMap(deleteMap);
|
|
|
|
- MaterialCutFrame materialCutFrame = new MaterialCutFrame();
|
|
|
|
- materialCutFrame.setImageIndex(i);
|
|
|
|
- materialCutFrame.setVideoSignature(videoMd5);
|
|
|
|
- materialCutFrame.setUrl(imageUrl);
|
|
|
|
- materialCutFrame.setSignature(md5);
|
|
|
|
- materialCutFrameService.save(materialCutFrame);
|
|
|
|
- LoadFileUtil.delFile(localPath);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ log.info("开始素造抽帧,md5:{}", videoMd5);
|
|
|
|
+ QueryWrapper<MaterialCutFrame> cutFrameQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ cutFrameQueryWrapper.eq("video_signature", videoMd5);
|
|
|
|
+ cutFrameQueryWrapper.last("limit 1");
|
|
|
|
+ MaterialCutFrame one = materialCutFrameService.getOne(cutFrameQueryWrapper);
|
|
|
|
+ if (!Check.isNull(one)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ 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", videoMd5);
|
|
|
|
+ deleteMap.put("signature", md5);
|
|
|
|
+ materialCutFrameService.removeByMap(deleteMap);
|
|
|
|
+ MaterialCutFrame materialCutFrame = new MaterialCutFrame();
|
|
|
|
+ materialCutFrame.setImageIndex(i);
|
|
|
|
+ materialCutFrame.setVideoSignature(videoMd5);
|
|
|
|
+ materialCutFrame.setUrl(imageUrl);
|
|
|
|
+ materialCutFrame.setSignature(md5);
|
|
|
|
+ materialCutFrameService.save(materialCutFrame);
|
|
|
|
+ LoadFileUtil.delFile(localPath);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- });
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
// }
|
|
// }
|