jay-goo / m3u8downloader Goto Github PK
View Code? Open in Web Editor NEWM3U8下载器,支持多线程下载、断点续传、后台下载、本地播放解决方案、m3u8加密解决方案
M3U8下载器,支持多线程下载、断点续传、后台下载、本地播放解决方案、m3u8加密解决方案
EncryptM3U8Server的加解密只是对ts文件名的加解密吗
不知道是不是那个地址的问题。。
比如一个视频长1小时,那我只需要下载某部分的 几分钟。
10个视频基本全部都失败,再重新尝试,会有几个成功的。
首先这个项目非棒,非常感谢! 下载超过4M 时会出错,不支持多个任务同时下载?
How to download a video with request headers? Is there a way to headers for download request?
反复暂停和重新能复现问题,查看下载目录能看到几个几B到几K大小的分片,建议参考fileDownloader的处理方式,未下载完成的文件进行重命名以便进行续传。
可以指定下载多少个ts吗?
可以指定从多少秒开始,到多少秒结束。进行下载吗?
Using Network Security Config from resource network_security_config debugBuild
看到readme里面有关于加密的处理方式
但是我走普通的下载流程,下载加密的m3u8可以下载,但是无法播放!
是下载加密的m3u8需要走其他流程吗 ?
parseIndex方法,以及Ts:
if (line.endsWith("m3u8")) {
if(line.startsWith("/")) { // 取根路径
return parseIndex(contactUrl(domainPath,line));
} else { // 继承上一路径
return parseIndex(contactUrl(basePath,line));
}
}
目前代码只能下载 Media playlist 不能支持 Master playlist 下载,是否打算支持?
How to add a request header for a download request?
I tried adding addRequestProperty("name", "www.com")
to HttpURLConnection conn
to M3U8Downloader.java but that didn't work
conn.addRequestProperty("name", "www.com");
Any help is really appreciated
下载这个直接报403,请问啥原因
什么时候能转一下Androidx吗
public static M3U8 parseIndex(String url) throws IOException {
String urlName = url;
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
String newUrl = urlName;
Map<String, List<String>> map = conn.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
System.out.println(key + "--->" + map.get(key).get(0));
if ("Location".equals(key)) {
//获取新地址
newUrl = map.get(key).get(0);
System.out.println("newUrl--->" +newUrl);
break;
}
}
// 重新实例化url对象
realUrl = new URL(newUrl);
// 重新打开和URL之间的连接
conn = realUrl.openConnection();
// 建立实际的连接
conn.connect();
InputStream in = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in,encoding));
String basepath = url;
if (url.contains("?")) {
basepath = url.substring(0, url.lastIndexOf("?"));
}
basepath = basepath.substring(0, basepath.lastIndexOf("/") + 1);
M3U8 ret = new M3U8();
ret.setBasePath(basepath);
String line;
float seconds = 0;
while ((line = reader.readLine()) != null) {
if (line.startsWith("#")) {
if (line.startsWith("#EXTINF:")) {
line = line.substring(8);
if (line.endsWith(",")) {
line = line.substring(0, line.length() - 1);
}
seconds = Float.parseFloat(line);
}
continue;
}
if (line.endsWith("m3u8")) {
return parseIndex(basepath + line);
}
ret.addTs(new M3U8Ts(line, seconds));
seconds = 0;
}
reader.close();
return ret;
}
executor.execute(new Runnable() {
@Override
public void run() {
File file;
try {
String fileName = M3U8EncryptHelper.encryptFileName(encryptKey, m3U8Ts.obtainEncodeTsFileName());
file = new File(dir + File.separator + fileName);
} catch (Exception e) {
file = new File(dir + File.separator + m3U8Ts.getUrl());
}
if (!file.exists()) {//下载过的就不管了
String urlName = m3U8Ts.obtainFullUrl(basePath);
FileOutputStream fos = null;
InputStream inputStream = null;
try {
URL url = new URL(m3U8Ts.obtainFullUrl(basePath));
String newUrl = urlName;
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(connTimeout);
conn.setReadTimeout(readTimeout);
Map<String, List<String>> map = conn.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
System.out.println(key + "--->" + map.get(key).get(0));
if ("Location".equals(key)) {
//获取新地址
newUrl = map.get(key).get(0);
System.out.println("newUrl--->" +newUrl);
break;
}
}
// 重新实例化url对象
url = new URL(newUrl);
// 重新打开和URL之间的连接
conn = (HttpURLConnection) url.openConnection();
// 建立实际的连接
conn.connect();
if (conn.getResponseCode() == 200) {
if (isStartDownload){
isStartDownload = false;
mHandler.sendEmptyMessage(WHAT_ON_START_DOWNLOAD);
}
inputStream = conn.getInputStream();
fos = new FileOutputStream(file);//会自动创建文件
int len = 0;
byte[] buf = new byte[8 * 1024 * 1024];
while ((len = inputStream.read(buf)) != -1) {
curLength += len;
fos.write(buf, 0, len);//写入流中
}
} else {
handlerError(new Throwable(String.valueOf(conn.getResponseCode())));
}
} catch (MalformedURLException e) {
handlerError(e);
} catch (IOException e) {
handlerError(e);
} catch (Exception e) {
handlerError(e);
}
finally
{//关流
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
}
itemFileSize = file.length();
m3U8Ts.setFileSize(itemFileSize);
mHandler.sendEmptyMessage(WHAT_ON_PROGRESS);
curTs++;
}else {
curTs ++;
itemFileSize = file.length();
m3U8Ts.setFileSize(itemFileSize);
}
}
});
希望增加mp4下载
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.