|
@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
@@ -69,6 +70,7 @@ public class VideoApiService {
|
|
|
|
|
|
public Long publishVideo(Long uid, String videoUrl, String coverUrl, String title) {
|
|
|
String url = videoApiHost + "/longvideoapi/crawler/video/send";
|
|
|
+ JSONObject res = null;
|
|
|
try {
|
|
|
String param = "videoPath=" + videoUrl +
|
|
|
"&crawlerSrcCode=CONTENT" +
|
|
@@ -81,24 +83,26 @@ public class VideoApiService {
|
|
|
"&viewStatus=1" +
|
|
|
"&versionCode=1";
|
|
|
String post = httpPoolClient.post(url, param, "application/x-www-form-urlencoded;charset=UTF-8");
|
|
|
- JSONObject res = JSONObject.parseObject(post);
|
|
|
- if (res.getInteger("code") != 0) {
|
|
|
- log.error("publishVideo error, uid:{} videoUrl={} coverUrl={} title={} res={}", uid, videoUrl, coverUrl, title, res);
|
|
|
- throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
|
|
|
- }
|
|
|
- JSONObject data = res.getJSONObject("data");
|
|
|
- Long videoId = data.getLong("id");
|
|
|
- log.info("publishVideo success, uid:{} videoId={}", uid, videoId);
|
|
|
- return videoId;
|
|
|
+ res = JSONObject.parseObject(post);
|
|
|
} catch (Exception e) {
|
|
|
log.error("publishVideo error", e);
|
|
|
}
|
|
|
- return null;
|
|
|
+ if (Objects.isNull(res)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (res.getInteger("code") != 0) {
|
|
|
+ log.error("publishVideo error, uid:{} videoUrl={} coverUrl={} title={} res={}", uid, videoUrl, coverUrl, title, res);
|
|
|
+ throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
|
|
|
+ }
|
|
|
+ JSONObject data = res.getJSONObject("data");
|
|
|
+ Long videoId = data.getLong("id");
|
|
|
+ log.info("publishVideo success, uid:{} videoId={}", uid, videoId);
|
|
|
+ return videoId;
|
|
|
}
|
|
|
|
|
|
- public String updateVideo(Long uid, Long videoId, String coverUrl, String title) {
|
|
|
+ public void updateVideo(Long uid, Long videoId, String coverUrl, String title) {
|
|
|
String url = videoApiHost + "/longvideoapi/openapi/video/update";
|
|
|
- String result = null;
|
|
|
+ JSONObject res = null;
|
|
|
try {
|
|
|
JSONObject videoDetail = getVideoInfo(videoId);
|
|
|
JSONObject chargeDetail = videoDetail.getJSONObject("chargeDetail");
|
|
@@ -117,16 +121,17 @@ public class VideoApiService {
|
|
|
param.put("allowIosPlay", chargeDetail.getLong("allowIosPlay"));
|
|
|
param.put("allowDownload", 0);
|
|
|
String post = httpPoolClient.post(url, param.toJSONString());
|
|
|
- JSONObject res = JSONObject.parseObject(post);
|
|
|
- if (res.getInteger("code") != 0) {
|
|
|
- log.error("updateVideo error, uid:{} videoId={} coverUrl={} title={} res={}", uid, videoId, coverUrl, title, res);
|
|
|
- result = res.getString("msg");
|
|
|
- throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
|
|
|
- }
|
|
|
+ res = JSONObject.parseObject(post);
|
|
|
} catch (Exception e) {
|
|
|
log.error("updateVideo error", e);
|
|
|
}
|
|
|
- return result;
|
|
|
+ if (Objects.isNull(res)) {
|
|
|
+ throw new CommonException(ExceptionEnum.VIDEO_UPDATE_FAILED);
|
|
|
+ }
|
|
|
+ if (res.getInteger("code") != 0) {
|
|
|
+ log.error("updateVideo error, uid:{} videoId={} coverUrl={} title={} res={}", uid, videoId, coverUrl, title, res);
|
|
|
+ throw new CommonException(ExceptionEnum.VIDEO_UPDATE_FAILED.getCode(), res.getString("msg"));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public JSONObject getVideoInfo(Long videoId) {
|