获取网络地址m3u8文件里所有ts文件

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

public class FileM3U8Util {
    private static final String encoding = "utf-8";


    public static List<String> getM3U8Ts4HttlUrl(String httpUrl) throws IOException{
        URL url = new URL(httpUrl);
        URLConnection urlConn = url.openConnection();
        InputStream in = urlConn.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(in, encoding));
        String strTxt = null;
        List<String> ls = new ArrayList<String>();
        while (null != (strTxt = br.readLine())) {
            if ("ts".equals(FileUtil.getSuffix(strTxt))) {
                ls.add(strTxt);
            }
        }
        if (null != br) {
            br.close();
        }
        if (null != in) {
            in.close();
        }
        url = null;
        return ls;
    }
    

    public static List<String> pushM3U8Files(String httpUrl) throws IOException{
        String prefixHttpUrl = httpUrl.substring(0, httpUrl.lastIndexOf("/") + 1);
        List<String> listFileNames = getM3U8Ts4HttlUrl(httpUrl);
        List<String> ls = new ArrayList<String>();
        ls.add(httpUrl);
        for (String string : listFileNames) {
            String httpMUrl = prefixHttpUrl + string;
            ls.add(httpMUrl);
        }
        return ls;
    }
    
}

 

posted @ 2020-09-03 17:05  凉城  阅读(1485)  评论(0编辑  收藏  举报