use of com.acgist.snail.pojo.bean.M3u8 in project snail by acgist.
the class HlsContextTest method testHlsContext.
@Test
void testHlsContext() throws DownloadException {
final String id = UUID.randomUUID().toString();
final TaskEntity task = new TaskEntity();
task.setId(id);
task.setName("acgist");
final ITaskSession session = TaskSession.newInstance(task);
assertDoesNotThrow(() -> {
HlsContext.getInstance().m3u8(id, new M3u8(Type.FILE, null, List.of()));
HlsContext.getInstance().hlsSession(session);
HlsContext.getInstance().remove(session);
});
}
use of com.acgist.snail.pojo.bean.M3u8 in project snail by acgist.
the class M3u8Builder method buildCipher.
/**
* <p>新建加密套件</p>
*
* @return 加密套件
*
* @throws NetException 网络异常
*/
private Cipher buildCipher() throws NetException {
final var optional = this.labels.stream().filter(label -> LABEL_EXT_X_KEY.equalsIgnoreCase(label.getName())).findFirst();
if (optional.isEmpty()) {
// 没有加密标签:不用解密
return null;
}
final KeyValueWrapper wrapper = optional.get().attrs();
final String method = wrapper.getIgnoreCase(ATTR_METHOD);
final M3u8.Protocol protocol = M3u8.Protocol.of(method);
LOGGER.debug("HLS加密算法:{}", method);
if (protocol == null || protocol == M3u8.Protocol.NONE) {
throw new NetException("不支持的HLS加密算法:" + method);
}
if (protocol == M3u8.Protocol.AES_128) {
return this.buildCipherAes128(wrapper.getIgnoreCase(ATTR_IV), wrapper.getIgnoreCase(ATTR_URI));
} else {
throw new NetException("不支持的HLS加密算法:" + method);
}
}
use of com.acgist.snail.pojo.bean.M3u8 in project snail by acgist.
the class HlsContext method hlsSession.
/**
* <p>获取HLS任务信息</p>
*
* @param taskSession 任务信息
*
* @return HLS任务信息
*/
public HlsSession hlsSession(ITaskSession taskSession) {
final String id = taskSession.getId();
final M3u8 m3u8 = this.m3u8s.get(id);
return this.sessions.computeIfAbsent(id, key -> HlsSession.newInstance(m3u8, taskSession));
}
use of com.acgist.snail.pojo.bean.M3u8 in project snail by acgist.
the class M3u8Builder method buildM3u8.
/**
* <p>新建M3U8信息</p>
*
* @return {@link M3u8}
*
* @throws NetException 网络异常
*/
private M3u8 buildM3u8() throws NetException {
final M3u8.Type type = this.buildType();
final Cipher cipher = this.buildCipher();
List<String> links;
if (type == Type.M3U8) {
links = this.buildM3u8Links();
} else {
// 获取LABEL_EXTINF标签数据
links = this.buildFileLinks(LABEL_EXTINF);
// 没有LABEL_EXTINF标签数据:获取LABEL_EXT_X_BITRATE标签数据
if (CollectionUtils.isEmpty(links)) {
links = this.buildFileLinks(LABEL_EXT_X_BITRATE);
}
if (CollectionUtils.isEmpty(links)) {
throw new NetException("没有下载文件");
}
}
return new M3u8(type, cipher, links);
}
Aggregations