package com.yeshi.buwan.controller.admin.api;
|
|
import com.yeshi.buwan.domain.VideoType;
|
import com.yeshi.buwan.service.imp.VideoTypeService;
|
import com.yeshi.buwan.service.inter.juhe.BilibiliVideoService;
|
import com.yeshi.buwan.util.JsonUtil;
|
import com.yeshi.buwan.videos.bilibili.BilibiliApiUtil;
|
import com.yeshi.buwan.videos.bilibili.entity.BilibiliMediaInfo;
|
import com.yeshi.buwan.videos.bilibili.entity.BilibiliVideo;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import javax.annotation.Resource;
|
import java.io.PrintWriter;
|
|
@Controller
|
@RequestMapping("admin/new/api/bilibili")
|
public class BilibiliAdminController {
|
|
@Resource
|
private VideoTypeService videoTypeService;
|
|
@Resource
|
private BilibiliVideoService bilibiliVideoService;
|
|
@RequestMapping(value = "/addVideo", method = RequestMethod.POST)
|
public void addVideo(String url, int type, PrintWriter out) {
|
VideoType videoType = videoTypeService.getVideoType(type);
|
if (videoType == null) {
|
out.print(JsonUtil.loadFalseAdmin("视频分类不存在"));
|
return;
|
}
|
|
try {
|
BilibiliVideo bilibiliVideo = BilibiliApiUtil.parseShortVideo(url);
|
if (bilibiliVideo == null) {
|
out.print(JsonUtil.loadFalseAdmin("链接解析失败"));
|
return;
|
}
|
bilibiliVideoService.addToInternetSearch(bilibiliVideo, type);
|
out.print(JsonUtil.loadTrueAdmin(""));
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseAdmin(e.getMessage()));
|
return;
|
}
|
}
|
|
|
@RequestMapping(value = "/addMedia", method = RequestMethod.POST)
|
public void addMedia(String url, PrintWriter out) {
|
try {
|
BilibiliMediaInfo mediaInfo = BilibiliApiUtil.parseMediaInfo(url);
|
if (mediaInfo == null) {
|
out.print(JsonUtil.loadFalseAdmin("链接解析失败"));
|
return;
|
}
|
bilibiliVideoService.addToInternetSearch(mediaInfo);
|
out.print(JsonUtil.loadTrueAdmin(""));
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseAdmin(e.getMessage()));
|
return;
|
}
|
}
|
|
}
|