|
@@ -29,8 +29,10 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -206,13 +208,18 @@ public class CdnDoaminServiceImpl extends ServiceImpl<CdnDomainMapper, CdnDomain
|
|
|
m3u8 = videoM3u8s.get(0);
|
|
|
}
|
|
|
if (!StringUtils.isBlank(type)) {
|
|
|
- String downLoadFileUrl = "http://192.168.1.134:8088/api?cdn=" + cdnDomain.getDomain() + "&id=" + m3u8.getId();
|
|
|
+ String downLoadFileUrl = "http://127.0.0.1:8088/api/cdnDomain/downLoadM3u8File?cdn=" + cdnDomain.getDomain() + "&id=" + m3u8.getId();
|
|
|
throw new ResultException(888, downLoadFileUrl);
|
|
|
}
|
|
|
String tsListStr = m3u8.getTsListStr();
|
|
|
+ String tsName = m3u8.getTS_NAME();
|
|
|
+
|
|
|
if (!StringUtils.isBlank(tsListStr)) {
|
|
|
- List<VideoTs> tsList = JSON.parseArray(tsListStr, VideoTs.class);
|
|
|
- m3u8.setTS_LIST(tsList);
|
|
|
+ if (StringUtils.isBlank(tsName)) {
|
|
|
+ List<VideoTs> tsList = JSON.parseArray(tsListStr, VideoTs.class);
|
|
|
+ //说明是有序的视频,则不需要返回tsList
|
|
|
+ m3u8.setTS_LIST(tsList);
|
|
|
+ }
|
|
|
String prefixPath = m3u8.getPREFIX_PATH();
|
|
|
if (StringUtils.isNotBlank(prefixPath)) {
|
|
|
m3u8.setPREFIX_PATH(cdnDomain.getDomain() + m3u8.getPREFIX_PATH());
|
|
@@ -233,6 +240,50 @@ public class CdnDoaminServiceImpl extends ServiceImpl<CdnDomainMapper, CdnDomain
|
|
|
|
|
|
@Override
|
|
|
public Result downLoadM3u8File(String cdn, Integer id, HttpServletResponse response) {
|
|
|
+ VideoM3u8 m3u8 = m3u8Mapper.selectById(id);
|
|
|
+ if (m3u8 == null) {
|
|
|
+ throw new ResultException(500, "当前视频不存在");
|
|
|
+ }
|
|
|
+ response.setContentType("text/plain");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + id + ".m3u8");
|
|
|
+ ServletOutputStream out = null;
|
|
|
+ try {
|
|
|
+ out = response.getOutputStream();
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ String last = "\n";
|
|
|
+ builder.append("#EXTM3U").append(last);
|
|
|
+ builder.append("#EXT-X-VERSION:").append(m3u8.getVERSION()).append(last);
|
|
|
+ builder.append("#EXT-X-TARGETDURATION:").append(m3u8.getTARGETDURATION()).append(last);
|
|
|
+ builder.append("#EXT-X-MEDIA-SEQUENCE:").append(m3u8.getSEQUENCE()).append(last);
|
|
|
+ builder.append("#EXT-X-PLAYLIST-TYPE:").append(m3u8.getTYPE()).append(last);
|
|
|
+ if (StringUtils.isNotBlank(m3u8.getKEY())) {
|
|
|
+ builder.append("#EXT-X-KEY:METHOD=AES-128,URI=\"data:application/octet-stream;base64,").append(m3u8.getKEY()).append("\"").
|
|
|
+ append(",IV=").append(m3u8.getIV()).append(last);
|
|
|
+ }
|
|
|
+ String tsListStr = m3u8.getTsListStr();
|
|
|
+ if (StringUtils.isNotBlank(tsListStr)) {
|
|
|
+ List<VideoTs> tsList = JSON.parseArray(tsListStr, VideoTs.class);
|
|
|
+ String prefixPath = m3u8.getPREFIX_PATH();
|
|
|
+ boolean notBlank = StringUtils.isNotBlank(prefixPath);
|
|
|
+
|
|
|
+ for (VideoTs videoTs : tsList) {
|
|
|
+ String name = videoTs.getName();
|
|
|
+ builder.append("#EXTINF:").append(videoTs.getTime()).append(",").append(last);
|
|
|
+ if (notBlank) {
|
|
|
+ //为true表示不为空,说明ts地址是相对路径,这里拼接cdn地址
|
|
|
+ builder.append(cdn).append(prefixPath).append(name).append(last);
|
|
|
+ } else {
|
|
|
+ builder.append(name).append(last);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ builder.append("#EXT-X-ENDLIST").append(last);
|
|
|
+ out.write(builder.toString().getBytes());
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|