11package com .acgist .snail .protocol .hls ;
22
3+ import java .nio .file .Files ;
4+ import java .nio .file .Paths ;
5+
36import com .acgist .snail .config .SymbolConfig .Symbol ;
47import com .acgist .snail .context .ITaskSession ;
58import 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