Search in sources :

Example 1 with VideoInfo

use of com.yausername.youtubedl_android.mapper.VideoInfo in project androidtv-news by anenasa.

the class Channel method parse.

void parse() throws JSONException, IOException, YoutubeDLException, InterruptedException {
    String url = getUrl();
    YoutubeDLRequest request;
    if (url.startsWith("https://hamivideo.hinet.net/channel/") && url.endsWith(".do")) {
        String id = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
        OkHttpClient okHttpClient = new OkHttpClient();
        Request okHttpRequest = new Request.Builder().url("https://hamivideo.hinet.net/api/play.do?freeProduct=1&id=" + id).build();
        Response response = okHttpClient.newCall(okHttpRequest).execute();
        JSONObject object = new JSONObject(response.body().string());
        request = new YoutubeDLRequest(object.getString("url"));
    } else {
        request = new YoutubeDLRequest(url);
    }
    request.addOption("-f", getFormat());
    if (!getHeader().isEmpty()) {
        String[] headers = getHeader().split("\\\\r\\\\n");
        for (String header : headers) {
            request.addOption("--add-header", header);
        }
    }
    VideoInfo streamInfo = YoutubeDL.getInstance().getInfo(request);
    setVideo(streamInfo.getUrl());
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) JSONObject(org.json.JSONObject) Request(okhttp3.Request) YoutubeDLRequest(com.yausername.youtubedl_android.YoutubeDLRequest) VideoInfo(com.yausername.youtubedl_android.mapper.VideoInfo) YoutubeDLRequest(com.yausername.youtubedl_android.YoutubeDLRequest)

Aggregations

YoutubeDLRequest (com.yausername.youtubedl_android.YoutubeDLRequest)1 VideoInfo (com.yausername.youtubedl_android.mapper.VideoInfo)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 JSONObject (org.json.JSONObject)1