Skip to content

Commit d5c0962

Browse files
committed
Merge branch 'master' into dev
2 parents 41fd72a + 8ddac59 commit d5c0962

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

snail/src/main/java/com/acgist/snail/protocol/Protocol.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public enum Type {
7676
*/
7777
HLS(
7878
new String[] {
79+
".+\\.m3u8",
7980
"http://.+\\.m3u8", "https://.+\\.m3u8",
8081
"http://.+\\.m3u8#.+", "https://.+\\.m3u8#.+",
8182
"http://.+\\.m3u8\\?.+", "https://.+\\.m3u8\\?.+"

snail/src/main/java/com/acgist/snail/protocol/hls/HlsProtocol.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.acgist.snail.protocol.hls;
22

3+
import java.nio.file.Files;
4+
import java.nio.file.Paths;
5+
36
import com.acgist.snail.config.SymbolConfig.Symbol;
47
import com.acgist.snail.context.ITaskSession;
58
import com.acgist.snail.context.wrapper.DescriptionWrapper;
@@ -64,15 +67,16 @@ protected void prep() throws DownloadException {
6467

6568
@Override
6669
protected String buildFileName() throws DownloadException {
67-
final String path = URIWrapper.newInstance(this.url).decode().getPath();
68-
if(StringUtils.endsWithIgnoreCase(path, INDEX_M3U8)) {
69-
// 去掉斜杠和结尾
70-
return path.substring(1, path.length() - INDEX_M3U8.length())
71-
.replace(Symbol.SLASH.toChar(), Symbol.MINUS.toChar()) +
72-
Protocol.Type.HLS.defaultSuffix();
73-
} else {
74-
return super.buildFileName();
70+
if(Protocol.Type.HTTP.verify(this.url)) {
71+
final String path = URIWrapper.newInstance(this.url).decode().getPath();
72+
if(StringUtils.endsWithIgnoreCase(path, INDEX_M3U8)) {
73+
// 去掉斜杠和结尾
74+
return path.substring(1, path.length() - INDEX_M3U8.length())
75+
.replace(Symbol.SLASH.toChar(), Symbol.MINUS.toChar()) +
76+
Protocol.Type.HLS.defaultSuffix();
77+
}
7578
}
79+
return super.buildFileName();
7680
}
7781

7882
@Override
@@ -93,10 +97,19 @@ protected void done() throws DownloadException {
9397
* @throws DownloadException 下载异常
9498
*/
9599
private void buildM3u8() throws NetException, DownloadException {
96-
final var response = HttpClient
97-
.newInstance(this.url)
98-
.get()
99-
.responseToString();
100+
final String response;
101+
if(Protocol.Type.HTTP.verify(this.url)) {
102+
response = HttpClient
103+
.newInstance(this.url)
104+
.get()
105+
.responseToString();
106+
} else {
107+
try {
108+
response = Files.readString(Paths.get(this.url));
109+
} catch (Exception e) {
110+
throw new DownloadException("无效文件:" + this.url, e);
111+
}
112+
}
100113
final var m3u8Check = M3u8Builder.newInstance(response, this.url).build();
101114
if(m3u8Check.getType() == M3u8.Type.M3U8) {
102115
this.url = m3u8Check.getMaxRateLink();

0 commit comments

Comments
 (0)