diff --git a/downloader/src/main/java/com/jeffmony/downloader/VideoDownloadManager.java b/downloader/src/main/java/com/jeffmony/downloader/VideoDownloadManager.java index 7064783..8a5de0c 100644 --- a/downloader/src/main/java/com/jeffmony/downloader/VideoDownloadManager.java +++ b/downloader/src/main/java/com/jeffmony/downloader/VideoDownloadManager.java @@ -152,7 +152,7 @@ private void parseExistVideoDownloadInfo(final VideoTaskItem taskItem, final Has startBaseVideoDownloadTask(taskItem, headers); } else if (taskItem.isHlsType()) { VideoInfoParserManager.getInstance() - .parseM3U8File(taskItem, new IVideoInfoParseListener() { + .parseM3U8File(taskItem, headers, new IVideoInfoParseListener() { @Override public void onM3U8FileParseSuccess(VideoTaskItem info, M3U8 m3u8) { diff --git a/downloader/src/main/java/com/jeffmony/downloader/VideoInfoParserManager.java b/downloader/src/main/java/com/jeffmony/downloader/VideoInfoParserManager.java index 00035da..80bcf31 100644 --- a/downloader/src/main/java/com/jeffmony/downloader/VideoInfoParserManager.java +++ b/downloader/src/main/java/com/jeffmony/downloader/VideoInfoParserManager.java @@ -153,7 +153,7 @@ private void parseM3U8Info(VideoTaskItem taskItem, IVideoInfoListener listener, HashMap headers) { try { M3U8 m3u8 = - M3U8Utils.parseM3U8Info(mConfig, taskItem.getUrl(), false, null); + M3U8Utils.parseM3U8Info(mConfig, taskItem.getUrl(), false, null, headers); // HLS LIVE video cannot be proxy cached. if (m3u8.hasEndList()) { String saveName = VideoDownloadUtils.computeMD5(taskItem.getUrl()); @@ -176,7 +176,7 @@ private void parseM3U8Info(VideoTaskItem taskItem, IVideoInfoListener listener, } } - public void parseM3U8File(VideoTaskItem taskItem, + public void parseM3U8File(VideoTaskItem taskItem, final HashMap headers, IVideoInfoParseListener callback) { File remoteM3U8File = new File(taskItem.getSaveDir(), VideoDownloadUtils.REMOTE_M3U8); if (!remoteM3U8File.exists()) { @@ -186,7 +186,7 @@ public void parseM3U8File(VideoTaskItem taskItem, } try { M3U8 m3u8 = M3U8Utils.parseM3U8Info(mConfig, taskItem.getUrl(), true, - remoteM3U8File); + remoteM3U8File, headers); callback.onM3U8FileParseSuccess(taskItem, m3u8); } catch (Exception e) { e.printStackTrace(); diff --git a/downloader/src/main/java/com/jeffmony/downloader/m3u8/M3U8Utils.java b/downloader/src/main/java/com/jeffmony/downloader/m3u8/M3U8Utils.java index 27a5fb5..c602fde 100644 --- a/downloader/src/main/java/com/jeffmony/downloader/m3u8/M3U8Utils.java +++ b/downloader/src/main/java/com/jeffmony/downloader/m3u8/M3U8Utils.java @@ -17,6 +17,8 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.HashMap; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -35,7 +37,7 @@ public class M3U8Utils { */ public static M3U8 parseM3U8Info(VideoDownloadConfig config, String videoUrl, boolean isLocalFile, - File m3u8File) throws IOException { + File m3u8File, final HashMap headers) throws IOException { URL url = new URL(videoUrl); InputStreamReader inputStreamReader = null; BufferedReader bufferedReader; @@ -44,6 +46,11 @@ public static M3U8 parseM3U8Info(VideoDownloadConfig config, bufferedReader = new BufferedReader(inputStreamReader); } else { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + if (headers != null) { + for (Map.Entry item : headers.entrySet()) { + connection.setRequestProperty(item.getKey(), item.getValue()); + } + } if (config.shouldIgnoreCertErrors() && connection instanceof HttpsURLConnection) { HttpUtils.trustAllCert((HttpsURLConnection) connection); @@ -126,7 +133,7 @@ public static M3U8 parseM3U8Info(VideoDownloadConfig config, } // It has '#EXT-X-STREAM-INF' tag; if (hasStreamInfo) { - return parseM3U8Info(config, getFinalUrl(videoUrl, line), isLocalFile, m3u8File); + return parseM3U8Info(config, getFinalUrl(videoUrl, line), isLocalFile, m3u8File, headers); } M3U8Ts ts = new M3U8Ts(); if (isLocalFile) {