| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package com.tzld.piaoquan.longarticle.utils;
- import cn.hutool.http.HttpRequest;
- import cn.hutool.http.HttpResponse;
- import cn.hutool.json.JSONObject;
- import cn.hutool.json.JSONUtil;
- import com.tzld.piaoquan.longarticle.model.bo.VideoDetail;
- import lombok.extern.slf4j.Slf4j;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- @Slf4j
- public class VideoUtils {
- private static final String VIDEO_DETAIL_URL = "https://longvideoapi.piaoquantv.com/longvideoapi/openapi/video/batchSelectVideoInfo";
- public static VideoDetail getVideoDetail(Long videoId) {
- try {
- Map<String, Object> data = new HashMap<>();
- data.put("videoIdList", new String[]{String.valueOf(videoId)});
- HttpResponse response = HttpRequest.post(VIDEO_DETAIL_URL)
- .header("Content-Type", "application/json")
- .body(JSONUtil.toJsonStr(data))
- .execute();
- JSONObject jsonObject = JSONUtil.parseObj(response.body());
- List<JSONObject> list = jsonObject.get("data", List.class);
- if (list == null || list.isEmpty()) {
- return null;
- }
- JSONObject item = list.get(0);
- VideoDetail videoDetail = new VideoDetail();
- videoDetail.setVideoId(item.getStr("id"));
- videoDetail.setUid(item.getStr("uid"));
- videoDetail.setTitle(item.getStr("title"));
- videoDetail.setOssVideoPath(item.getStr("ossVideoPath"));
- videoDetail.setVideoPath(item.getStr("videoPath"));
- String shareImgPath = item.getStr("shareImgPath");
- videoDetail.setShareImgPath(shareImgPath);
- if (shareImgPath != null && !shareImgPath.isEmpty()) {
- String coverImgPath = getCoverImgPath(shareImgPath);
- videoDetail.setCoverImgPath(coverImgPath);
- videoDetail.setSmallPlayImgPath(getSmallPlayImgPath(coverImgPath));
- }
- return videoDetail;
- } catch (Exception e) {
- log.error("VideoUtils getVideoDetail error:{}", e.getMessage());
- }
- return null;
- }
- private static String getCoverImgPath(String shareImgPath) {
- String[] split = shareImgPath.split("/");
- StringBuilder stringBuilder = new StringBuilder();
- for (String s : split) {
- if (!s.startsWith("watermark")) {
- stringBuilder.append(s).append("/");
- }
- }
- if (stringBuilder.length() > 0) {
- stringBuilder.deleteCharAt(stringBuilder.length() - 1);
- }
- return stringBuilder.toString();
- }
- private static String getSmallPlayImgPath(String coverImgPath) {
- return coverImgPath + "/watermark,image_eXNoL3BpYy93YXRlcm1hcmtlci9pY29uX3BsYXlfd2hpdGUucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLHdfNzI=,g_center";
- }
- public static void main(String[] args) {
- System.out.println(getVideoDetail(11466300L).getOssVideoPath());
- }
- }
|