Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding header when getting file info #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void parseM3U8Info(VideoTaskItem taskItem, IVideoInfoListener listener,
HashMap<String, String> 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());
Expand All @@ -176,7 +176,7 @@ private void parseM3U8Info(VideoTaskItem taskItem, IVideoInfoListener listener,
}
}

public void parseM3U8File(VideoTaskItem taskItem,
public void parseM3U8File(VideoTaskItem taskItem, final HashMap<String, String> headers,
IVideoInfoParseListener callback) {
File remoteM3U8File = new File(taskItem.getSaveDir(), VideoDownloadUtils.REMOTE_M3U8);
if (!remoteM3U8File.exists()) {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String, String> headers) throws IOException {
URL url = new URL(videoUrl);
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader;
Expand All @@ -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<String, String> item : headers.entrySet()) {
connection.setRequestProperty(item.getKey(), item.getValue());
}
}
if (config.shouldIgnoreCertErrors() && connection instanceof
HttpsURLConnection) {
HttpUtils.trustAllCert((HttpsURLConnection) connection);
Expand Down Expand Up @@ -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) {
Expand Down