Giter Club home page Giter Club logo

m3u8downloader's People

Contributors

jinjiegu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

m3u8downloader's Issues

下载问题

首先这个项目非棒,非常感谢! 下载超过4M 时会出错,不支持多个任务同时下载?

How to use header?

How to download a video with request headers? Is there a way to headers for download request?

哥哥。

可以指定下载多少个ts吗?
可以指定从多少秒开始,到多少秒结束。进行下载吗?

加密后的视频如何下载

看到readme里面有关于加密的处理方式
但是我走普通的下载流程,下载加密的m3u8可以下载,但是无法播放!
是下载加密的m3u8需要走其他流程吗 ?

解析M3U8文件时,发现个BUG

parseIndex方法,以及Ts:

if (line.endsWith("m3u8")) {
    if(line.startsWith("/")) { // 取根路径
         return parseIndex(contactUrl(domainPath,line));
     } else { // 继承上一路径
        return parseIndex(contactUrl(basePath,line));
     }
 }

M3u8 的解析有问题

目前代码只能下载 Media playlist 不能支持 Master playlist 下载,是否打算支持?

How to add a request header?

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

部分M3U8网址路径301 Moved Permanently问题

修改MUtils文件parseIndex()方法

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;
}
  • M3U8DownloadTask文件的startDownload()方法

    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);
                 }
             }
         });
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.